I am building a radio mobile application using the IONIC Framework, and having a few issues.
For the audio streaming, I am using the HTML5 Audio Plugin from here http://ift.tt/1CHQ802, and it works great. However, there are two things that I would love to accomplish.
Case 1. If I start the application with my headphone plugged in, and I unplug my headphone out, the music stops ( this is okay ) - however, my 'stop' button does not turn into a 'play' button.
Case 2. While i'm listening to the radio, and when I lose connection or turn off my wifi, the music stops which is normal, but my 'stop' button still does change into a 'play' button.
For the headphone detection, I added this snippet to my AppDelegate.m
- (void)audioRouteChangeListenerCallback:(NSNotification*)notification
{
NSDictionary *interuptionDict = notification.userInfo;
NSInteger routeChangeReason = [[interuptionDict
valueForKey:AVAudioSessionRouteChangeReasonKey] integerValue];
switch (routeChangeReason) {
case AVAudioSessionRouteChangeReasonNewDeviceAvailable:
NSLog(@"AVAudioSessionRouteChangeReasonNewDeviceAvailable");
NSLog(@"Headphone/Line plugged in");
//Force current audio out through speaker
break;
case AVAudioSessionRouteChangeReasonOldDeviceUnavailable:
NSLog(@"AVAudioSessionRouteChangeReasonOldDeviceUnavailable");
NSLog(@"Headphone/Line was pulled. Stopping player....");
break;
case AVAudioSessionRouteChangeReasonCategoryChange:
// called at start - also when other audio wants to play
NSLog(@"AVAudioSessionRouteChangeReasonCategoryChange");
break;
}
}
I receive a log perfectly when I unplug my headphone, or plug-in my headphone, but I do not know what to do with this. I do not know how to call my 'stop' function my javascript - OR, maybe the audio can continue playing in the speaker when the headphone is plugged out, but not sure how to do this either.
If anyone can help, that would be wonderful.
Aucun commentaire:
Enregistrer un commentaire