我正在使用MPMoviePlayerController
,我如何检测电影实际开始播放的时间 - 而不是用户摆弄搜索控件的时间?
从我所做的测试中,我总是得到一个“加载状态更改”事件,并且(moviePlayer.loadState == MPMovieLoadStatePlayable)
每当TRUE
电影开始和用户拖动搜索控件之后(即使他将它从末端拖到中间 - 不一定到电影的开头) . 如何区分电影开始和搜索?
我正在使用MPMoviePlayerController
,我如何检测电影实际开始播放的时间 - 而不是用户摆弄搜索控件的时间?
从我所做的测试中,我总是得到一个“加载状态更改”事件,并且(moviePlayer.loadState == MPMovieLoadStatePlayable)
每当TRUE
电影开始和用户拖动搜索控件之后(即使他将它从末端拖到中间 - 不一定到电影的开头) . 如何区分电影开始和搜索?
MPMoviePlaybackState
Constants describing the current playback state of the movie player.
enum {
MPMoviePlaybackStateStopped,
MPMoviePlaybackStatePlaying,
MPMoviePlaybackStatePaused,
MPMoviePlaybackStateInterrupted,
MPMoviePlaybackStateSeekingForward,
MPMoviePlaybackStateSeekingBackward
};
typedef NSInteger MPMoviePlaybackState;
注册 MPMoviePlayerPlaybackStateDidChangeNotification
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(MPMoviePlayerPlaybackStateDidChange:)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:nil];
签入此函数 MPMoviePlaybackState
- (void)MPMoviePlayerPlaybackStateDidChange:(NSNotification *)notification
{
if (player.playbackState == MPMoviePlaybackStatePlaying)
{ //playing
}
if (player.playbackState == MPMoviePlaybackStateStopped)
{ //stopped
}if (player.playbackState == MPMoviePlaybackStatePaused)
{ //paused
}if (player.playbackState == MPMoviePlaybackStateInterrupted)
{ //interrupted
}if (player.playbackState == MPMoviePlaybackStateSeekingForward)
{ //seeking forward
}if (player.playbackState == MPMoviePlaybackStateSeekingBackward)
{ //seeking backward
}
}
删除通知
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
为了迅速
添加观察者
let defaultCenter: NSNotificationCenter = NSNotificationCenter.defaultCenter()
defaultCenter.addObserver(self, selector: "moviePlayerPlaybackStateDidChange:", name: MPMoviePlayerPlaybackStateDidChangeNotification, object: nil)
功能
func moviePlayerPlaybackStateDidChange(notification: NSNotification) {
let moviePlayerController = notification.object as! MPMoviePlayerController
var playbackState: String = "Unknown"
switch moviePlayerController.playbackState {
case .Stopped:
playbackState = "Stopped"
case .Playing:
playbackState = "Playing"
case .Paused:
playbackState = "Paused"
case .Interrupted:
playbackState = "Interrupted"
case .SeekingForward:
playbackState = "Seeking Forward"
case .SeekingBackward:
playbackState = "Seeking Backward"
}
print("Playback State: %@", playbackState)
}