iphone, how to play sound even in silent or mute mode?

后端 未结 3 1747
执笔经年
执笔经年 2020-12-30 17:08

as topic... is it possible ?

Thanks

again, I have attached the code as follows, please check which step is wrong .thanks.

    //@step
AudioS         


        
3条回答
  •  天涯浪人
    2020-12-30 18:00

    If you look in the docs under Audio Session Categories, you'll find a number of modes that you can set to tell the system how your app plans to use audio. The default is AVAudioSessionCategorySoloAmbient which tracks the ring/silent switch and the screen lock.

    To have your app ignore the ring/silent switch settings, you could try changing the category:

    #import 
    
    AudioSessionInitialize (NULL, NULL, NULL, NULL);
    AudioSessionSetActive(true);
    
    UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
    AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, 
                             sizeof(sessionCategory),&sessionCategory);
    

    If you want to allow iPod audio to continue playing in the background, you'll also want to check kAudioSessionProperty_OverrideCategoryMixWithOthers.

提交回复
热议问题