简体   繁体   English

AudioStreamer没有在后台启动

[英]AudioStreamer not starting in background

I am using AudioStreamer library. 我正在使用AudioStreamer库。 My problem is when one song finishes, next song must start streaming. 我的问题是,当一首歌结束时,下一首歌必须开始播放。 It works fine when app is in foreground but it stops after current song when app is in background. 当应用程序在前景中时,它可以正常工作;但是当应用程序在背景中时,它将在当前歌曲之后停止。 Here is my code: 这是我的代码:

-(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 {
        }
    }

}

You need to set the proper background mode in your target Capabilites page. 您需要在目标Capabilites页面中设置适当的背景模式。 See picture below. 见下图。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM