Boo*_*yah 4 mpmovieplayercontroller ios avplayerviewcontroller
在iOS9中,不推荐使用MPMoviePlayer类,而推荐使用AVPlayer。我有一个使用MPMoviePlayerPlaybackDidFinishReasonUserInfoKey的现有应用程序来确定如何记录有关视频播放器如何结束的事件。我如何对AVPlayer进行相同操作?
以下是结束原因键:
AVKit中没有与MPMoviePlayerPlaybackDidFinishReasonUserInfoKey和MPMoviePlayerPlaybackDidFinishNotification等效的功能。要在AVKit中完成相同的功能,您必须分别收听三个通知,而不是侦听具有不同可能原因的一个通知。
如果您想知道视频是否正在播放,可以执行KVO:
[self.player addObserver:self forKeyPath:@"rate" options:0 context:nil];
Run Code Online (Sandbox Code Playgroud)
然后添加此方法:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:@"rate"]) {
if ([self.player rate]) {
[self changeToPause]; // This changes the button to Pause
}
else {
[self changeToPlay]; // This changes the button to Play
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1410 次 |
| 最近记录: |