mardi 4 août 2015

iOS how to stop audio playing in background?

In my app i'm playing live audio stream, audio also continue playing in background, for this i'm using

// Set AVAudioSession
    NSError *sessionError = nil;
    // [[AVAudioSession sharedInstance] setDelegate:self];
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:&sessionError];

    // Change the default output audio route
    UInt32 doChangeDefaultRoute = 1;
 AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof(doChangeDefaultRoute), &doChangeDefaultRoute);
    self.player = [[AVQueuePlayer alloc] initWithURL:[NSURL URLWithString:streamingUrl]];
    self.player.actionAtItemEnd = AVPlayerActionAtItemEndNone;

I'm able to play audio in background/foreground. The streaming url sends audio continuously and my app play audio continuously in background, but at a certain time i want to stop audio player. So my question is how to stop audio player if my app is running in background (playing in background)?

Aucun commentaire:

Enregistrer un commentaire