I know unity has no native support for this, but how can I disable a certain audio source when the player is using their ipod?
I’ve used a native plugin that I call to check the state of the iPod on a scene opening and then play or not play game music like this (it’s based on some examples I Google’d basically) -
Plugins/iOS/iOSPlugin.mm
#import <Foundation/Foundation.h>
#import <MediaPlayer/MediaPlayer.h>
extern "C" {
bool _IsMusicPlaying () {
BOOL isPlaying = NO;
MPMusicPlayerController* iPodMusicPlayer = [MPMusicPlayerController iPodMusicPlayer];
if (iPodMusicPlayer.playbackState == MPMusicPlaybackStatePlaying) {
isPlaying = YES;
}
// NSLog(@"NATIVE: Music is %@.", isPlaying ? @"on" : @"off");
return isPlaying;
}
}
Plugins/iOSBridge.cs
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
public class iOSBridge {
// Native code definitions
[DllImport ("__Internal")]
private static extern bool _IsMusicPlaying ();
// Accessor functions
public static bool CheckIPodPlaying() {
// Call plugin only when running on real device
if (Application.platform == RuntimePlatform.IPhonePlayer) {
return _IsMusicPlaying();
} else {
// Not running on iOS
return false;
}
}
}
Then I can just call it from Javascript when needed -
var iPodPlaying : boolean = iOSBridge.CheckIPodPlaying();
Hope that helps!