简体   繁体   中英

Deactivating avaudiosession after going back from videoviewcontroller

I am trying to play video in background everything works just fine and the video play and get pause normally in background.But the only problem is whenever I go back from the from my videoviewcontroller(the view on which is played to menu), the video still remains in the background and you can see it as Musicplayer position. How can this be removed once I get out of videoviewcontroller

I have tried

    NSError *error;
    [[AVAudioSession sharedInstance] setActive:NO error:&error];

    NSLog(@"ERROR: %@", error); 

output ERROR: (null) this code removes the video from the background

 [[AVAudioSession sharedInstance] setCategory:nil error:nil];

but if now if want to play the video again it will not play in background mode

From Apple's: AVAudioSession class documentation

It says

Deactivating your session will fail if any associated audio objects (such as queues, converters, players or recorders) are currently running.

So you need to stop any/all of this audio objects before calling the setActive:No

I had had similar issues while trying to perform this before stopping my audio queue. In mi case I was using an external audio library (Dirac) and I just needed to call an AudioQueueStop method from this library before.

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