AudioStreamer无法在后台启动

时间:2014-07-01 13:34:44

标签: ios background-process audio-streaming audiostreamer

我正在使用AudioStreamer库。我的问题是当一首歌结束时,下一首歌必须开始播放。当应用程序处于前台时它可以正常工作,但当应用程序处于后台时它会在当前歌曲后停止。这是我的代码:

-(void)playNextTrack
{
    [stopSongStreamer stopMark30StreamingFor:playSong];
[self destroyStreamer:YES];

}

-(void) onStopStreamingResultMark30:(BOOL) isSuccess{
    [stopSongStreamer stopMArkStreamingSongFor:playSong];
}

-(void) onStopStreamingStop:(BOOL) isSuccess{
    if (nextPlaySong!=nil) {
        NSLog(@"play next song");
        [songStreamer streamSongForObject:nextPlaySong];
        nextPlaySong = nil;
    }
}

-(void) onStreamingResultWith:(PSStreamingSong *)streamingSongResult{
    if(streamingSongResult == nil)
    {
        [self handleError];
    }else{
        @try {
            streamer=[[AudioStreamer alloc]init];
    streamer.url=url;
    isSongDurationUpdated=NO;
    progressUpdateTimer =
    [NSTimer
     scheduledTimerWithTimeInterval:0.1
     target:self
     selector:@selector(updateProgress:)
     userInfo:nil
     repeats:YES];

    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(playbackStateChanged:)
     name:ASStatusChangedNotification
     object:streamer];

            [streamer start];

        }
        @catch (NSException *exception) {
            NSLog(@"Unable to stream song...");
        }
        @finally {
        }
    }

}

1 个答案:

答案 0 :(得分:0)

您需要在目标功能页面中设置正确的背景模式。 见下图。

enter image description here