AudioStreamer not starting in background

130 Views Asked by At

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

}
1

There are 1 best solutions below

0
On

You need to set the proper background mode in your target Capabilites page. See picture below.

enter image description here