我正在使用MPMoviePlayerController
,我需要检测按下下一个/上一个按钮。我尝试了几件事,但似乎都没有。
以下是我的尝试:
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
-(void) viewWillDisappear:(BOOL)animated
{
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];
[super viewWillDisappear:animated];
}
-(BOOL)canBecomeFirstResponder
{
return YES;
}
-(void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent
{
// stuff
}
问题是永远不会调用remoteControlReceivedWithEvent
方法。我已经读过,这在iOS版本高于6时无效 - 我正在使用iOS 7
我尝试使用MPMoviePlayerPlaybackStateDidChangeNotification
并检查MPMoviePlaybackStateSeekingForward
或MPMoviePlaybackStateSeekingBackward
- 不幸的是,这些播放状态是在拖动播放栏时设置的,而不是在按下下一个/上一个按钮时设置的。
有什么想法吗?
答案 0 :(得分:0)
抱歉,我不太了解你的问题,但是如果你想在控制中心使用你的应用程序中的控件,你可以使用:
// 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)];
答案 1 :(得分:0)
尝试注册以下事件:
- (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_OverrideCategoryMixWithOthers
属性
答案 2 :(得分:0)
您是否尝试过MPMoviePlayerNowPlayingMovieDidChangeNotification? 如果这不起作用,那么我建议转移到较低级别的API,即AVPlayer。它可以在视频播放时以及其他方式对所有操作进行细粒度控制。
答案 3 :(得分:0)
您需要注册才能处理moviePlayerLoadStateChanged的通知。当您按下next / prev按钮时,将调用moviePlayerLoadStateChanged并且loadState将为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");
}
}
答案 4 :(得分:0)
您更改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];
}