Ios MPMoviePlayerController-检测按下下一个/上一个按钮
我正在使用MPMoviePlayerController,我需要检测按下下一个/上一个按钮。我试过几种方法,但似乎都不管用 以下是我尝试过的:Ios MPMoviePlayerController-检测按下下一个/上一个按钮,ios,ios8,mpmovieplayercontroller,mpmovieplayer,Ios,Ios8,Mpmovieplayercontroller,Mpmovieplayer,我正在使用MPMoviePlayerController,我需要检测按下下一个/上一个按钮。我试过几种方法,但似乎都不管用 以下是我尝试过的: 远程控制事件 问题是永远不会调用remoteControlReceivedWithEvent方法。我已经读到这在高于6的iOS版本中不起作用-我正在使用iOS 7 通知 我尝试使用MPMoviePlayerPlaybackStateDidChangeNotification并检查MPMoviePlaybackStateSeekingForward
- 远程控制事件
remoteControlReceivedWithEvent
方法。我已经读到这在高于6的iOS版本中不起作用-我正在使用iOS 7
- 通知
MPMoviePlayerPlaybackStateDidChangeNotification
并检查MPMoviePlaybackStateSeekingForward
或MPMoviePlaybackStateSekingBackward
——不幸的是,这些播放状态是在拖动播放栏时设置的,而不是在按下Next/Prev按钮时设置的
有什么想法吗?对不起,我不太了解您的问题,但是如果您想在控制中心的应用程序中使用控件,您可以使用:
// You need cath the singleton
MPRemoteCommandCenter *myRemote = [MPRemoteCommandCenter sharedCommandCenter];
//And add the selector you can fire depends on the button, a couple of examples:
[myRemote.playCommand addTarget:self action:@selector(myPlayMethods)];
[myRemote.nextTrackCommand addTarget:self action:@selector(myNextTrackMethods)];
尝试在以下位置注册事件:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// Turn on remote control event delivery
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
// Set itself as the first responder
[self becomeFirstResponder];
}
也不要设置
kAudioSessionProperty\u覆盖与其他人的类别混合
属性您是否尝试过MPMoviePlayerNowPlayingMoviedChangeNotification?
如果这不起作用,那么我建议使用较低级别的API,即AVPlayer。它提供了对视频播放和其他操作的细粒度控制 您需要注册以处理moviePlayerLoadStateChanged的通知。按下下一个/上一个按钮时,将调用moviePlayerLoadStateChanged,加载状态将为MPMovieLoadStateUnknown
-(void)registerMyStuff {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerLoadStateChanged:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:self.mpc];
}
- (void)moviePlayerLoadStateChanged:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayer = notification.object;
MPMovieLoadState loadState = moviePlayer.loadState;
if(loadState == MPMovieLoadStateUnknown)
{
// this is where the next/prev buttons notify
// there is no video in this state so load one
// just reload the default movie
NSLog(@"MPMovieLoadStateUnknown");
self.mpc.contentURL = self.fileURL;
[self.mpc prepareToPlay];
return;
}
else if(loadState & MPMovieLoadStatePlayable)
{
NSLog(@"MPMovieLoadStatePlayable");
}
else if(loadState & MPMovieLoadStatePlaythroughOK)
{
NSLog(@"MPMovieLoadStatePlaythroughOK");
} else if(loadState & MPMovieLoadStateStalled)
{
NSLog(@"MPMovieLoadStateStalled");
}
}
您可以更改
MPMoviePlayerController
overlayView,就像更改UIImagePickerController
overlayView一样,以实现所需的功能
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:someUrl];
moviePlayer.movieControlMode = MPMovieControlModeHidden;
[moviePlayer play];
NSArray *windows = [[UIApplication sharedApplication] windows];
if ([windows count] > 1) {
UIWindow *moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
[moviePlayerWindow addSubview:yourCustomOverlayView];
}
正如你在我的帖子中看到的,这是我尝试的第一件事,但它不起作用。是不是当MPMoviePlayerController显示时,调用ViewWillEnglish,从而结束接收遥控?请尝试注释掉视图将消失,然后再试一次。@John谢谢你的建议,我也这么认为,没有这样的运气!:(您看过MPMoviePlayerNowPlayingMoviedChangeNotification吗?它告诉您当前播放的电影何时更改,如果您有电影的字典或数组,您可以确定正在播放的电影是下一部电影还是上一部电影。还有一个解决方案是将Uiapplication和Impression子类化-(void)remoteControlReceivedWithEvent:(UIEvent*)receivedEvent在那里你试过了吗?
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:someUrl];
moviePlayer.movieControlMode = MPMovieControlModeHidden;
[moviePlayer play];
NSArray *windows = [[UIApplication sharedApplication] windows];
if ([windows count] > 1) {
UIWindow *moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
[moviePlayerWindow addSubview:yourCustomOverlayView];
}