Enable Selectively The “Override IPod Music” Player Option From Code (Unity)

Enable Selectively The “Override IPod Music” Player Option From Code  (Unity)

Symptoms

  • We want to allow music from other apps if the user has the music turned off in our game and Unity API does not give access to “Override iPod Music”.

Cause

  • “Override iPod Music” is not accessible from code.

Resolution

Using the native API from iOS, you can change the music source application:

<extern "C" {
    #import <AVFoundation/AVFoundation.h>
    #import <AudioToolbox/AudioToolbox.h>
    bool _IsMusicPlaying (){ 
        if ([[AVAudioSession sharedInstance] isOtherAudioPlaying ]){ 
            return true; 
        } 
        return false; 
    }
}

Was this article helpful?

Related Articles