Play Audio over Other Active Sounds

1。AVAudioSession:每一个ios应用都有一个audio session

    AVAudioSession *audioSession = [AVAudioSession sharedInstance];

2。设置类别:

    - (BOOL)setCategory:(NSString *)theCategory error:(NSError **)outError

   category:AVAudioSessionCategoryAmbient //静音模式或者锁屏下不再播放音乐,和其他app音频混合播放

           AVAudioSessionCategorySoloAmbient //静音模式或者锁屏下不再播放音乐,会中止其他app音频,单独播放--默认模式

             AVAudioSessionCategoryRecord//不播放,锁屏状态继续录音,prepareToPlay=YES,play=NO

             AVAudioSessionCategoryPlayback//静音模式或者锁屏下仍能播放音乐,并中止其他音频播放,经常在真机运行无声音时,在

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions中加上这一句

             AVAudioSessionCategoryPlayAndRecord//可同时进行播放和录音,静音模式或者锁屏下仍能继续,并中止其他音频播放

             AVAudioSessionCategoryAudioProcessing//只做音频处理,不能播放和录音,prepareToPlay=NO,play=NO,同时中止其他音频播放


e.g.

    NSError *audioSessionError = nil;

    AVAudioSession *audioSession = [AVAudioSession sharedInstance];

    if ([audioSession setCategory:AVAudioSessionCategoryAmbient error:&audioSessionError]){

        NSLog(@"Successfully set the audio session.");

    } else {

        NSLog(@"Could not set the audio session");

    }

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值