10 iphone objective-c mpmovieplayercontroller ios
我有一个关于MPMoviePlayerController的小问题,当我点击那个电影按钮时我有一个播放电影的链接,但是当我点击另一个按钮应用程序崩溃时,我需要找到如何识别该电影正在播放或获得任何类型回应
vis*_*kh7 21
要扩展@ Saurabh的答案,您可以检查视频是否正在播放
if(player.playbackState == MPMoviePlaybackStatePlaying)
{
// is Playing
}
Run Code Online (Sandbox Code Playgroud)
在哪里MPMoviePlaybackState定义为
enum {
MPMoviePlaybackStateStopped,
MPMoviePlaybackStatePlaying,
MPMoviePlaybackStatePaused,
MPMoviePlaybackStateInterrupted,
MPMoviePlaybackStateSeekingForward,
MPMoviePlaybackStateSeekingBackward
};
typedef NSInteger MPMoviePlaybackState;
Run Code Online (Sandbox Code Playgroud)
有两部分,通常组合使用;
注册MPMoviePlayerPlaybackStateDidChangeNotification例如:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(MPMoviePlayerPlaybackStateDidChange:)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:nil];
Run Code Online (Sandbox Code Playgroud)
在通知处理程序中,您可以详细检查实际状态 - 例如:
- (void)MPMoviePlayerPlaybackStateDidChange:(NSNotification *)notification
{
//are we currently playing?
if (movieController_.playbackState == MPMoviePlaybackStatePlaying)
{ //yes->do something as we are playing...
}
else
{ //nope->do something else since we are not playing
}
}
Run Code Online (Sandbox Code Playgroud)
您当然也可以使用playbackState属性,而无需处理发出更改信号的通知.不过,在大多数情况下,这是正确的地方.
删除/删除电影播放时,不要忘记删除通知处理程序,例如:
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
Run Code Online (Sandbox Code Playgroud)