Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 当应用程序处于后台时,freestreamer无法在呼叫结束后继续播放音乐(;实际上没有声音);_Ios_Avaudioplayer_Background Music_Audio - Fatal编程技术网

Ios 当应用程序处于后台时,freestreamer无法在呼叫结束后继续播放音乐(;实际上没有声音);

Ios 当应用程序处于后台时,freestreamer无法在呼叫结束后继续播放音乐(;实际上没有声音);,ios,avaudioplayer,background-music,audio,Ios,Avaudioplayer,Background Music,Audio,我尝试使用freestreamer播放音乐,当应用程序在后台调用时,音乐可以停止,但如果调用结束(CTCallStateDisconnected),音乐无法再次恢复,它可以捕捉到FSAudioStream函数中调用结束(AVAudioSessionInterruptionTypeEnded)时的状态,该函数名为 } else if ([interruptionType intValue] == AVAudioSessionInterruptionTypeEnded) { if (

我尝试使用freestreamer播放音乐,当应用程序在后台调用时,音乐可以停止,但如果调用结束(CTCallStateDisconnected),音乐无法再次恢复,它可以捕捉到FSAudioStream函数中调用结束(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];
        }
    }
}
应用程序还可以在后台捕捉播放状态,这意味着重新开始播放音乐,但我根本听不到音乐!!!!有人知道如何解决这个问题吗? 顺便说一下,我还设置了

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
支持背景播放

2015年5月27日更新:


我读过一些关于:,在这种情况下,我们可以在代码中捕获此中断通知,也可以检测呼叫结束状态并重新启动音乐,但根本没有声音,所以很高兴,解决了这个问题:在后台,我们应该添加一些代码来支持后台播放

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

这将解决这个问题

我想我也有同样的问题,你能多告诉我一些解决方案吗?你把这个
@synchronized
代码放在哪里了?@tommepe在Common/FSAudioStream.mm文件中,是的,我试过了,但没有看到任何变化。。。当我在后台时,我可以停止我的音频流,但我不能播放它。您是否做了任何其他更改?当我第一次在代码中使用
[AVAudioSession sharedInstance]
时,我还添加了
[[AVAudioSession sharedInstance]setCategory:AVAudioSessionCategoryPlayback错误:nil],而不仅仅是在
@synchronized