For this purpose I wrote this plugin and added it to my appDelegate.m (renamed to .mm and compiled as a C++ file):
extern "C" {
bool _IsMusicPlaying () {
BOOL isPlaying = NO;
MPMusicPlayerController* iPodMusicPlayer = [MPMusicPlayerController iPodMusicPlayer];
if (iPodMusicPlayer.playbackState == MPMusicPlaybackStatePlaying) {
isPlaying = YES;
}
NSLog(@"Music is %@.", isPlaying ? @"on" : @"off");
return isPlaying;
}
}
Unity can then call this method through a plugin class and get the state of the iPod music. I hope that's useful.
EDIT (added unity code too): In the Assets/Plugin folder of your unity project, create a OBJCPlugin.cs file and add:
using UnityEngine;
using System.Runtime.InteropServices;
public class OBJCPlugin
{
[DllImport ("__Internal")]
private static extern bool _IsMusicPlaying ();
public static bool IsMusicPlaying ()
{
if ( Application.platform == RuntimePlatform.IPhonePlayer )
{
return _IsMusicPlaying();
}
else {
return false;
}
}
}
Then you can call that static method of that class from any other class.