I have a audio player app, that is created with Cordova and native AudioStreamer plugin calls.. Everything works perfectly, BUT, now i want to use the remoteControlReceivedWithEvent event to use the native remote controle when the app is in the background..
When I call my Cordova plugin to start the native player I also call ..
- (void)startStream:(CDVInvokedUrlCommand*)command
streamer = [[[AudioStreamer alloc] initWithURL:url] retain];
[streamer start];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self canBecomeFirstResponder];
And when I stop the stream:
- (void)stopStream:(CDVInvokedUrlCommand*)command
[streamer stop];
[streamer release];
streamer = nil;
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
It all work perfect, but i DONT know where to put the remote events...
- (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;
}
}
"[self canBecomeFirstResponder];" can not work because this method is for UIResponder and CDVPlugin extend from NSObject.
For this override pluginInitialize method like bellow:
Noticed, MainViewController is first responder so it will take all remote event. Now add property in MainViewController.h then controller can pass to the desired plugin
And add remote event method like that which call your remote plugin method
Now put remoteControlReceivedWithEvent in your plugin too.