IOS AVAudioSession is slow and synchronous

In iOS, I try to calm down music in music while playing some sound effects. If you don’t know, “dodging” simply means that the volume of the music is a little discharged before playing my sound, then the sound is played, and then the music volume returns to its original volume.

For ducking, I set the AVAudioSessioncategory AVAudioSessionCategoryAmbientwith the option AVAudioSessionCategoryOptionDuckOthers, and then activate / deactivate the session (and, obviously, reproducing the sound between them). It works well, but volume changes seem to be performed in the same thread as the call, and the application freezes when the volume changes.

If you want to reproduce the behavior, I think the fastest route is to launch a new SpriteKit project, which will give you a sample of a rotating project on the road. Then enter the following code into the method touchesBegan:withEvent:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient withOptions: AVAudioSessionCategoryOptionDuckOthers error: nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
[[AVAudioSession sharedInstance] setActive:NO error:nil];

Then launch the app on your iOS device, put the music in the Music app and tap the screen to create ships and miss the music. You will hear dodging, but also see the ships freeze on the screen.

This is normal? What would be the easiest way to avoid freezing an application while dodging?

By the way, I am using iPhone 5S on iOS 8.1. In addition, I use this in the Unity3D plugin. How can I bite the Music app from Unity itself?

+4
source share
1 answer

AVAudioSession . (UI) . setActive, .

        dispatch_queue_t myQueue = dispatch_queue_create("com.myname.myapp", nil);
        dispatch_async(myQueue, ^{
            [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient withOptions: AVAudioSessionCategoryOptionDuckOthers error: nil];
            [[AVAudioSession sharedInstance] setActive:YES error:nil];
        });

: iOS AudioSessionSetActive() ?

0

All Articles