freestreamer 通话结束后在后台无法继续播放音乐(实际没有声音)
freestreamer can not resume play music after call end when app in background(have no sound actually)
我尝试用freestreamer播放音乐,当app在后台来电时,音乐可以停止,但如果通话结束(CTCallStateDisconnected),音乐就无法再次恢复,它可以捕捉状态时在名为
的 FSAudioStream 函数中调用 end(AVAudioSessionInterruptionTypeEnded)
} 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];
}
}
}
而且应用程序还可以在后台捕获kFsAudioStreamPlaying状态,这意味着重新开始播放音乐,但我根本听不到音乐!!!!有人可以知道如何解决这个问题吗?
顺便说一下,我还设置了
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
支持后台播放
2015 年 5 月 27 日更新:
我看过:Background audio doesn't resume after a call,在这种情况下在代码中捕获了这个中断通知,也可以检测到通话结束状态并重新启动音乐,但是根本没有声音
太开心了,解决这个问题:在后台,我们应该添加一些代码来支持后台播放
@synchronized (self) {
[[AVAudioSession sharedInstance] setActive:YES error:nil];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
fsAudioStreamPrivateActiveSessions[[NSNumber numberWithUnsignedLong:(unsigned long)self]] = @"";
}
这将解决这个问题!!
我尝试用freestreamer播放音乐,当app在后台来电时,音乐可以停止,但如果通话结束(CTCallStateDisconnected),音乐就无法再次恢复,它可以捕捉状态时在名为
的 FSAudioStream 函数中调用 end(AVAudioSessionInterruptionTypeEnded) } 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];
}
}
}
而且应用程序还可以在后台捕获kFsAudioStreamPlaying状态,这意味着重新开始播放音乐,但我根本听不到音乐!!!!有人可以知道如何解决这个问题吗? 顺便说一下,我还设置了
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
支持后台播放
2015 年 5 月 27 日更新:
我看过:Background audio doesn't resume after a call,在这种情况下在代码中捕获了这个中断通知,也可以检测到通话结束状态并重新启动音乐,但是根本没有声音
太开心了,解决这个问题:在后台,我们应该添加一些代码来支持后台播放
@synchronized (self) {
[[AVAudioSession sharedInstance] setActive:YES error:nil];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
fsAudioStreamPrivateActiveSessions[[NSNumber numberWithUnsignedLong:(unsigned long)self]] = @"";
}
这将解决这个问题!!