简体   繁体   中英

AudioStreamer not starting in background

I am using AudioStreamer library. 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. See picture below.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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