我有问题用我的avplayer控制iPhone控件.
如果我把功能
- (void)remoteControlReceivedWithEvent:(UIEvent *)event
Run Code Online (Sandbox Code Playgroud)
在负责播放被调用函数的视图控制器中但仅当我要在当前视图控制器中进行后台操作时.
如果我要去其他视图控制器的背景,那么函数永远不会调用.
这就是为什么我想把它放在app委托中.
我尝试了Becomefirstresponse并将该函数放在每个视图控制器中但它确实有帮助.
我打电话
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
Run Code Online (Sandbox Code Playgroud)
在里面
-(void)applicationWillResignActive:(UIApplication *)application
Run Code Online (Sandbox Code Playgroud)
谢谢
San*_*ndy 23
我在iPhone控件中使用了以下代码 -
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
Run Code Online (Sandbox Code Playgroud)
用于注册监听遥控器.完成后删除它 -
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];
Run Code Online (Sandbox Code Playgroud)
让app canBecomeFirstResponder -
- (BOOL)canBecomeFirstResponder {
return YES;
}
Run Code Online (Sandbox Code Playgroud)
使用委托方法处理iPhone控件,如播放和暂停,同时点击主页按钮
- (void)remoteControlReceivedWithEvent:(UIEvent *)event {
//if it is a remote control event handle it correctly
if (event.type == UIEventTypeRemoteControl) {
if (event.subtype == UIEventSubtypeRemoteControlPlay) {
[audioPlayer play];
NSLog(@"play");
} else if (event.subtype == UIEventSubtypeRemoteControlPause) {
[audioPlayer stop];
NSLog(@"pause");
} else if (event.subtype == UIEventSubtypeRemoteControlTogglePlayPause) {
NSLog(@"toggle");
}
}
}
Run Code Online (Sandbox Code Playgroud)
在我的情况下,我能够处理播放和暂停.请让我知道是否有任何错误.
| 归档时间: |
|
| 查看次数: |
8724 次 |
| 最近记录: |