最新更新后,播放Xamarin for iOS的视频已损坏

Sup*_*eet 6 mpmovieplayercontroller ios xamarin xamarin.forms

Xamarin for iOS的以下代码在Xamarin for iOS更新到v2.0.50727之前工作正常

这是Xamarin Forms应用程序中自定义渲染器中的代码

 class WatchVideoRenderer : PageRenderer
{
    MPMoviePlayerController moviePlayer;

    protected override void OnElementChanged(VisualElementChangedEventArgs e)
    {
        base.OnElementChanged(e);

        var url =  new NSUrl("http://192.168.12.4:8085/MediaUploads/1/211/520140731170618/DPM202.mp4");
        moviePlayer = new MPMoviePlayerController();
        moviePlayer.ContentUrl = url;
        moviePlayer.View.Frame = new CGRect((float)((NativeView.Bounds.Width - 600) / 2), (float)((NativeView.Bounds.Height - 450) / 2), 600, 400);

        MPMoviePlayerController.Notifications.ObserveLoadStateDidChange(OnLoadStateChanged);
        MPMoviePlayerController.Notifications.ObservePlaybackDidFinish(OnPlaybackComplete);

        View.AddSubview(moviePlayer.View);

        moviePlayer.PrepareToPlay();
        moviePlayer.ShouldAutoplay = true;
        moviePlayer.Play();
    }

    private void OnLoadStateChanged(object sender, NSNotificationEventArgs e)
    {
        if (moviePlayer.LoadState == MPMovieLoadState.Playable)
        {

        }
    }

    private void OnPlaybackComplete(object sender, MPMoviePlayerFinishedEventArgs e)
    {

    }
}
Run Code Online (Sandbox Code Playgroud)

正如我所说,这是在前天工作,之后我在Xamarin上安装了2个更新.iOS和现在失败了.我只看到一个黑色的画布,视频永远不会加载.MPMoviePlayerController不会发出任何通知.有一个这个应用程序的发布计划在下周,这最后一分钟的错误导致我头痛.任何帮助都非常感谢.

Dan*_*nyC 0

我通过推送新的图像上下文解决了类似的问题,这成功了。我修改了代码以包含 BeginImageContext() 和 EndImageContext()。

UIGraphics.BeginImageContext(new CGSize(1,1));
var url =  new NSUrl("http://192.168.12.4:8085/MediaUploads/1/211/520140731170618/DPM202.mp4");
moviePlayer = new MPMoviePlayerController();
moviePlayer.ContentUrl = url;
moviePlayer.View.Frame = new CGRect((float)((NativeView.Bounds.Width - 600) / 2), (float)((NativeView.Bounds.Height - 450) / 2), 600, 400);
UIGraphics.EndImageContext();
Run Code Online (Sandbox Code Playgroud)