我正在使用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];