Ios 音频拖缆未在后台启动
我正在使用AudioStreamer库。我的问题是当一首歌结束时,下一首歌必须开始播放。当应用程序位于前台时,它可以正常工作,但当应用程序位于后台时,它会在当前歌曲之后停止。这是我的密码:Ios 音频拖缆未在后台启动,ios,background-process,audio-streaming,audiostreamer,Ios,Background Process,Audio Streaming,Audiostreamer,我正在使用AudioStreamer库。我的问题是当一首歌结束时,下一首歌必须开始播放。当应用程序位于前台时,它可以正常工作,但当应用程序位于后台时,它会在当前歌曲之后停止。这是我的密码: -(void)playNextTrack { [stopSongStreamer stopMark30StreamingFor:playSong]; [self destroyStreamer:YES]; } -(void) onStopStreamingResultMark30:(BOOL) i
-(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 {
}
}
}
您需要在目标能力页面中设置适当的背景模式。 见下图
-(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 {
}
}
}
-(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 {
}
}
}