Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions ios/ReactNativeAudioStreaming.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ - (void)dealloc
#pragma mark - Pubic API

RCT_EXPORT_METHOD(play:(NSString *) streamUrl options:(NSDictionary *)options) {

if(![self activate]) return;

@try {
Expand Down Expand Up @@ -237,6 +237,16 @@ - (void)unregisterAudioInterruptionNotifications
object:nil];
}

- (void) manageInterruption: (Boolean) isStop {
if(isStop) {
if (self.audioPlayer) {
[self.audioPlayer pause];
}
} else {
[self.audioPlayer play];
}
}

- (void)onAudioInterruption:(NSNotification *)notification {

// Get the AVAudioSessionInterruptionTypeKey enum
Expand All @@ -247,12 +257,12 @@ - (void)onAudioInterruption:(NSNotification *)notification {
{
case AVAudioSessionInterruptionTypeBegan:
NSLog(@"Audio Session Interruption case started.");
[self stop];
[self manageInterruption:true];
break;

case AVAudioSessionInterruptionTypeEnded:
NSLog(@"Audio Session Interruption case ended.");
[self play:self.lastUrlString options:self.lastOptions];
[self manageInterruption:false];
break;

default:
Expand Down