找出MPMoviePlayerController是否正在播放

我有关于MPMoviePlayerController的一个小问题,我有一个链接,播放电影,当我点击该电影button,但是当我点击另一个button应用程序崩溃,我需要find如何确定电影播放或获得任何forms的回应

要扩大@ Saurabh的答案,你可以检查video是否正在播放

if(player.playbackState == MPMoviePlaybackStatePlaying) { // is Playing } 

MPMoviePlaybackState被定义为

 enum { MPMoviePlaybackStateStopped, MPMoviePlaybackStatePlaying, MPMoviePlaybackStatePaused, MPMoviePlaybackStateInterrupted, MPMoviePlaybackStateSeekingForward, MPMoviePlaybackStateSeekingBackward }; typedef NSInteger MPMoviePlaybackState; 

有两个部分,通常组合使用;

像这样注册MPMoviePlayerPlaybackStateDidChangeNotification

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MPMoviePlayerPlaybackStateDidChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil]; 

在通知处理程序中,您可以详细检查实际状态 – 例如:

 - (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 } } 

您当然也可以使用playbackState属性,而不处理发出信号更改的通知。 尽pipe如此,在大多数情况下,这是正确的。

当删除/杀死你的电影播放时,不要忘记删除通知处理程序,例如像这样:

 [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; 

您可以检查MPMoviePlayerController的playbackState属性。 参考这个链接 –

http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPMoviePlayerController_Class/Reference/Reference.html

迅速实现@ ZKV7的答案是:

 if(player.playbackState == MPMoviePlaybackState.Playing) { // is Playing } 

其中MPMoviePlaybackState枚举是:

 enum MPMoviePlaybackState : Int { case Stopped case Playing case Paused case Interrupted case SeekingForward case SeekingBackward } 

有关MPMoviePlayerController的更多信息,请参阅apple文档 。

检查video播放器是否处于播放状态或不在SWIFT中

 @IBAction func btnPressPlay(sender: AnyObject) { if videoPlayerViewController.moviePlayer.playbackState == MPMoviePlaybackState.Playing { self.videoPlayerViewController.moviePlayer.stop() } else { self.videoPlayerViewController.moviePlayer.play() } } 
 typedef NS_ENUM(NSInteger, AVPlayerTimeControlStatus) { AVPlayerTimeControlStatusPaused, AVPlayerTimeControlStatusWaitingToPlayAtSpecifiedRate, AVPlayerTimeControlStatusPlaying } NS_ENUM_AVAILABLE(10_12, 10_0); if(self.player.timeControlStatus == AVPlayerTimeControlStatusPlaying) { // is Playing }