我有一个音频播放器应用程序,它是使用 Cordova 和本机 AudioStreamer 插件调用创建的。一切正常,但是,现在我想在应用程序在后台时使用 remoteControlReceivedWithEvent 事件来使用本机遥控器。
当我调用我的 Cordova 插件来启动本机播放器时,我也调用了 ..
- (void)startStream:(CDVInvokedUrlCommand*)command
streamer = [[[AudioStreamer alloc] initWithURL:url] retain];
[streamer start];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self canBecomeFirstResponder];
当我停止流时:
- (void)stopStream:(CDVInvokedUrlCommand*)command
[streamer stop];
[streamer release];
streamer = nil;
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
这一切都很完美,但我不知道将远程事件放在哪里......
- (void)remoteControlReceivedWithEvent:(UIEvent *)event {
switch (event.subtype) {
case UIEventSubtypeRemoteControlTogglePlayPause:
NSLog(@"PAUSE!!!");
break;
case UIEventSubtypeRemoteControlPlay:
NSLog(@"PAUSE!!!");
break;
case UIEventSubtypeRemoteControlPause:
NSLog(@"PAUSE!!!");
break;
case UIEventSubtypeRemoteControlStop:
NSLog(@"PAUSE!!!");
break;
default:
break;
}
}