トップ 一覧 置換 検索 ヘルプ RSS ログイン

iPhone開発 音楽が再生中か確認するの変更点

  • 追加された行はこのように表示されます。
  • 削除された行はこのように表示されます。
http://www.idevgames.com/forum/showthread.php?p=141850

 BOOL			gOtherAudioIsPlaying = YES;
 
 void CheckIfOtherAudioIsPlaying(void)
 {
	UInt32		propertySize, audioIsAlreadyPlaying;
	AudioSessionInitialize(NULL, NULL, NULL, NULL);
	// do not open the track if the audio hardware is already in use (could be the iPod app playing music)
	propertySize = sizeof(UInt32);
	AudioSessionGetProperty(kAudioSessionProperty_OtherAudioIsPlaying, &propertySize, &audioIsAlreadyPlaying);
	if (audioIsAlreadyPlaying != 0)
	{
		gOtherAudioIsPlaying = YES;
		//NSLog(@"other audio is playing");
		
		UInt32	sessionCategory = kAudioSessionCategory_AmbientSound;
		AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
		AudioSessionSetActive(YES);
	}
	else
	{
		//NSLog(@"no other audio is playing ...");
		
		gOtherAudioIsPlaying = NO;
		
		// since no other audio is *supposedly* playing, then we will make darn sure by changing the audio session category temporarily
		// to kick any system remnants out of hardware (iTunes (or the iPod App, or whatever you wanna call it) sticks around)
		UInt32	sessionCategory = kAudioSessionCategory_MediaPlayback;
		AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
		AudioSessionSetActive(YES);
		
		// now change back to ambient session category so our app honors the "silent switch"
		sessionCategory = kAudioSessionCategory_AmbientSound;
		AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
	}
 }

{{category2 プログラミング言語,Objective-C}}