0

i try to use freestreamer to play music, a call coming when app in background, the music can stop, but if the call end(CTCallStateDisconnected), the music can not resume again, it can catch the status when the call end(AVAudioSessionInterruptionTypeEnded) in the FSAudioStream function which named

    } else if ([interruptionType intValue] == AVAudioSessionInterruptionTypeEnded) {
    if (self.wasInterrupted) {
        self.wasInterrupted = NO;

        @synchronized (self) {
            [[AVAudioSession sharedInstance] setActive:YES error:nil];
            fsAudioStreamPrivateActiveSessions[[NSNumber numberWithUnsignedLong:(unsigned long)self]] = @"";
        }

        if (self.wasContinuousStream) {
            /*
             * Resume playing.
             */
            [self play];
        } else {
            /*
             * Resume playing.
             */
           [self playFromOffset:_lastSeekByteOffset];
        }
    }
}

and the app can also catch the kFsAudioStreamPlaying status in background, it mean start to play the music again , but i can not listen the music at all !!!! can somebody know how to solve this issue? by the way i also set the

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];

to support the background play.

update 27/5/2015:

i have read something about :Background audio doesn't resume after a call, in this case have catch this interruption notification in code, also can detect the call end status and restart the music , but have no sounds at all

Community
  • 1
  • 1
iCrany
  • 115
  • 10

1 Answers1

0

so happy, solve this problem: in the background , we should add some code to support background play

            @synchronized (self) {
            [[AVAudioSession sharedInstance] setActive:YES error:nil];
            [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
            fsAudioStreamPrivateActiveSessions[[NSNumber numberWithUnsignedLong:(unsigned long)self]] = @"";
        }

and this will solve this issue!!

iCrany
  • 115
  • 10
  • I think I've got the same issue, can you tell me a bit more about the solution ? where did you put this `@synchronized` code ? – Thomas Besnehard Sep 29 '15 at 15:17
  • @Tommecpe in Common/FSAudioStream.mm file, [link](https://github.com/muhku/FreeStreamer/blob/b80a61777cdaffd13cdb6b83657cc48b374ff3d4/Common/FSAudioStream.mm#L751) – iCrany Sep 30 '15 at 01:07
  • Yep I've tried it but I didn't see any change... I can stop my audiostream when I'm in background but I cannot play it. Did you do any other changes ? – Thomas Besnehard Sep 30 '15 at 14:07
  • when i use `[AVAudioSession sharedInstance]` first time in my code, i also add `[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];`, not only in `@synchronized` – iCrany Oct 01 '15 at 02:35