-1

I create a game. and now I need to check itunes is playing or not. I will mute game background music when itunes is playing in background

In cocos2d, itunes will fade out when SimpleAudioEngine play. And If turn on itunes backgroud, cocos2d's game will fade out bgm.

So need some code to check system status.

zszen
  • 1,428
  • 1
  • 14
  • 18
  • You mean iPod, not iTunes, right? –  Aug 30 '12 at 14:20
  • 1
    Answered here: [Detecting if music is playing](http://stackoverflow.com/questions/2274475/detecting-if-music-is-playing) – lcs Aug 30 '12 at 14:23
  • 2
    **what have you tried?** because when you would have started to set up the `AVAudioSession` you should have got the answer to this question... It seems you haven't done anything yet. – holex Aug 30 '12 at 14:28
  • yes, yes this code: if ([[MPMusicPlayerController iPodMusicPlayer] playbackState] == MPMusicPlaybackStatePlaying) . thx your help. – zszen Aug 30 '12 at 14:37
  • all code here:#import if ([[MPMusicPlayerController iPodMusicPlayer] playbackState] == MPMusicPlaybackStatePlaying){ NSLog(@"backgroud music is playing"); return; } – zszen Aug 30 '12 at 15:34
  • You can answer your question and accept that. – neilvillareal Sep 07 '12 at 12:26

1 Answers1

0

solved:

add mediaplayer.frameworks and import:

#import <MediaPlayer/MediaPlayer.h> 

then copy those code to needed place.

if ([[MPMusicPlayerController iPodMusicPlayer] playbackState] == MPMusicPlaybackStatePlaying){
    NSLog(@"backgroud music is playing"); 
    return;
} 
zszen
  • 1,428
  • 1
  • 14
  • 18