Ios 视频关闭时,将不会触发AnimationCoordinator的WillendFullScreen演示
您好,我有一个基于Xamarin MvvmCross框架的应用程序,它使用iOS中NSProject库的AVPlayerItem。每当视频播放关闭时,由于观察者在动画协调器的全屏演示结束时发出通知,应弹出测验。最常见的情况是,函数WillEndFullScreenPresentation被激发。但有时当我在暂停时滑动过快或关闭时,此函数会在调用视频播放之前启动。如何防止这种情况发生Ios 视频关闭时,将不会触发AnimationCoordinator的WillendFullScreen演示,ios,xamarin,video-streaming,mvvmcross,nsobject,Ios,Xamarin,Video Streaming,Mvvmcross,Nsobject,您好,我有一个基于Xamarin MvvmCross框架的应用程序,它使用iOS中NSProject库的AVPlayerItem。每当视频播放关闭时,由于观察者在动画协调器的全屏演示结束时发出通知,应弹出测验。最常见的情况是,函数WillEndFullScreenPresentation被激发。但有时当我在暂停时滑动过快或关闭时,此函数会在调用视频播放之前启动。如何防止这种情况发生 private void SetVideoPlayer(VideoAsset video) {
private void SetVideoPlayer(VideoAsset video)
{
var player = new AVPlayer(new NSUrl(video.VideoUrl));
ViewModel.WatchedVideoAssetCommand.Execute(video);
aVPlayerViewController = new AVPlayerViewController();
aVPlayerViewController.Player = player;
aVPlayerViewController.Delegate = this;
this.PresentViewController(aVPlayerViewController, true, () =>
{
aVPlayerViewController.Player?.Play();
});
//NotificationCenter.default.addObserver(self, selector: Selector(("playerDidFinishPlaying:")),
//name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: fourVideoPlayer.player.currentItem)
NSNotificationCenter.DefaultCenter.AddObserver(AVPlayerItem.DidPlayToEndTimeNotification, (notify) => {
notify.Dispose();
aVPlayerViewController.DismissModalViewController(true);
});
NSNotificationCenter.DefaultCenter.AddObserver(AVPlayerItem.ItemFailedToPlayToEndTimeNotification, (notify) =>
{
notify.Dispose();
aVPlayerViewController.DismissModalViewController(true);
});
}
[Export("playerViewController:willEndFullScreenPresentationWithAnimationCoordinator:")]
public void WillEndFullScreenPresentation(AVPlayerViewController playerViewController, IUIViewControllerTransitionCoordinator coordinator)
{
ViewModel.StartQuizForVideoAssetCommand.Execute(ViewModel.PlayingAsset);
}
AVPlayer有一个属性:
但有时当我在暂停时滑动过快或关闭时,此函数会在调用视频播放之前启动
您可以在WillEndFullScreenPresentation
方法中检查此状态,以确定是否需要退出全屏
示例代码如下:
[Export("playerViewController:willEndFullScreenPresentationWithAnimationCoordinator:")]
public void WillEndFullScreenPresentation(AVPlayerViewController playerViewController, IUIViewControllerTransitionCoordinator coordinator)
{
if (aVPlayerViewController.Player.TimeControlStatus != AVFoundation.AVPlayerTimeControlStatus.Paused || aVPlayerViewController.Player.TimeControlStatus != AVFoundation.AVPlayerTimeControlStatus.WaitingToPlayAtSpecifiedRate)
{
ViewModel.StartQuizForVideoAssetCommand.Execute(ViewModel.PlayingAsset);
}
}
应用此修复后,没有注意到太多差异,但很少产生错误。事实上,很难重现这个错误。@t好的,如果回答有帮助,请不要忘记接受它作为答案(单击✔ 在这个答案的左上角)投票,它将帮助其他有类似问题的人。