Howto check whether Ipod is playing music

Posts: 95
Joined: 2009.09
Post: #1
Hello again,

well I already use AudioServicesSystemSounds for many clicks/clacks and similar things.
I like that because the player may start his ipod to have his music running while playing the game. (doubletapping the mainbutton even opens a small ipodmenu on top of the game).

Now to create a better athmosphere I want to play an intro, but only if the ipod is not playing any music currently. I think that actually makes sense, because when the user starts the game without having music running he really wants to play and I should give him the big thing.

So where can I get the "BOOL" that is YES when the ipod is currently playing music?
Quote this message in a reply
Posts: 446
Joined: 2002.09
Post: #2
Here's a function that'll do what you want...
bool OtherAudioIsPlaying(void)
  UInt32 audioPlaying = 0;
  UInt32 audioPlayingSize = sizeof(audioPlaying);

  AudioSessionGetProperty(kAudioSessionProperty_OtherAudioIsPlaying, &audioPlayingSize, &audioPlaying);

  return (bool)audioPlaying;

On OS 3.x you need to initialize your audio session first (using kAudioSessionCategory_AmbientSound) before checking for other audio. You can then set the session category to SoloAmbientSound or MediaPlayback if you want to stop the other audio, or just leave it as AmbientSound to keep the other audio playing.

On OS 2.x yer pretty much SOL, 'cause AFAICT kAudioSessionProperty_OtherAudioIsPlaying always returns true on OS 2.2.1. In that case I just use SoloAmbientSound when I have my own music and AmbientSound if not.
Quote this message in a reply
Posts: 95
Joined: 2009.09
Post: #3
Works a treat, thank you Smile
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  HowTo initialize an EAGLView.m as a Subview Bersaelor 4 9,658 Oct 23, 2009 09:06 AM
Last Post: Bersaelor
  Turning off mixing iPod music dsk00 0 3,525 Jun 4, 2009 10:25 PM
Last Post: dsk00
  Sanity check, Aisle 9 KittyMac 6 6,177 Sep 14, 2006 07:51 PM
Last Post: KittyMac
  Howto compile a Maya Plug-in on OS X? webwarrior 4 6,930 Dec 16, 2004 01:19 PM
Last Post: KenD
  Texture loading code check. CarbonX 0 3,257 Jul 31, 2004 10:47 PM
Last Post: CarbonX