iOS高级音频的设置项

最近做音频合成,看了百度很多的音频后台,但不是自己想要的效果.于是google加官方文档,实现了自己想要的东西.

特此记录一下.与有同需求的朋友分享一下.

目的功能主要是音频能后台 程序启动不中断ipod能与ipod混音

转载请保留出处:http://blog.csdn.net/fightper/article/details/7516876

关键代码:

 

AudioSessionInitialize (NULL,NULL,NULL,NULL);//初始化音频

UInt32 sessionCategory =kAudioSessionCategory_MediaPlayback;//设置后台播放

AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,sizeof (sessionCategory), &sessionCategory);

UInt32 allowMixWithOthers =true;//设置是否与ipod混合(ipod声音一样大)

AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers,sizeof(allowMixWithOthers), &allowMixWithOthers);

UInt32 allowAudioShouldDuck =true;//设置是否与ipod混合(ipod声音变小,应用程序声音变大)

AudioSessionSetProperty(kAudioSessionProperty_OtherMixableAudioShouldDuck,sizeof(allowAudioShouldDuck), &allowAudioShouldDuck);

AudioSessionSetActive(true);//激活audiosession

 

/*调用高级类设置方法

 [[AVAudioSession sharedInstance] setActive:YES error: nil];

 [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:nil];

 //调用远程播放控件

 [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

 */

 

 

//系统提示音调用 

staticvoid completionCallback (SystemSoundID  soundID,void* aa) {}

musicID = 0;

SystemSoundID soundID;

NSString *path = [[NSBundlemainBundle]pathForResource:@"tishi"ofType:@"aif"];    

CFURLRef soundURL = (CFURLRef)[NSURLfileURLWithPath:path];

AudioServicesCreateSystemSoundID(soundURL,&soundID);

AudioServicesPlaySystemSound (kSystemSoundID_Vibrate);

AudioServicesAddSystemSoundCompletion(soundID,NULL,NULL,completionCallback,(void *)musicID);

AudioServicesPlayAlertSound(soundID);

原文连接:http://blog.csdn.net/fightper/article/details/7516876

posted @ 2014-05-04 23:10  WFApple  阅读(384)  评论(0编辑  收藏  举报