第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何以編程方式感知iPhone靜音開關?

如何以編程方式感知iPhone靜音開關?

慕工程0101907 2019-08-12 10:28:52
如何以編程方式感知iPhone靜音開關?我似乎無法在SDK中找到如何以編程方式感知iPhone上的靜音按鈕/開關。當我的應用程序播放背景音樂時,它會正確響應音量按鈕,而我沒有任何代碼可以遵循,但是,當我使用靜音開關時,它只是繼續(xù)播放。如何測試靜音的位置?(注意:我的程序有自己的靜音開關,但我希望物理開關覆蓋它。)
查看完整描述

3 回答

?
桃花長相依

TA貢獻1860條經(jīng)驗 獲得超8個贊

JPM。實際上,你提供的鏈接會得到正確的答案(最終。;)為了完整性(因為SO應該是QUICK答案的來源?。?.....

// "Ambient" makes it respect the mute switch// Must call this once to init sessionif (!gAudioSessionInited){
    AudioSessionInterruptionListener    inInterruptionListener = NULL;
    OSStatus    error;
    if ((error = AudioSessionInitialize (NULL, NULL, inInterruptionListener, NULL)))
    {
        NSLog(@"*** Error *** error in AudioSessionInitialize: %d.", error);
    }
    else
    {
        gAudioSessionInited = YES;
    }}SInt32  ambient = kAudioSessionCategory_AmbientSound;if (AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (ambient), &ambient)){
    NSLog(@"*** Error *** could not set Session property to ambient.");}


查看完整回答
反對 回復 2019-08-12
?
GCT1015

TA貢獻1827條經(jīng)驗 獲得超4個贊

-(BOOL)silenced {
     #if TARGET_IPHONE_SIMULATOR
         // return NO in simulator. Code causes crashes for some reason.
         return NO;
     #endif

    CFStringRef state;
    UInt32 propertySize = sizeof(CFStringRef);
    AudioSessionInitialize(NULL, NULL, NULL, NULL);
    AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state);
    if(CFStringGetLength(state) > 0)
            return NO;
    else
            return YES;

    }


查看完整回答
反對 回復 2019-08-12
?
嚕嚕噠

TA貢獻1784條經(jīng)驗 獲得超7個贊

如果您不在靜音模式下,其他答案中的某些代碼(包括接受的答案)可能不起作用,其中靜音開關受到尊重。


我編寫了下面的例程切換到環(huán)境,讀取開關,然后返回到我的應用程序中需要的設置。


-(BOOL)muteSwitchEnabled {


#if TARGET_IPHONE_SIMULATOR

    // set to NO in simulator. Code causes crashes for some reason.

    return NO;

#endif


// go back to Ambient to detect the switch

AVAudioSession* sharedSession = [AVAudioSession sharedInstance];

[sharedSession setCategory:AVAudioSessionCategoryAmbient error:nil];


CFStringRef state;

UInt32 propertySize = sizeof(CFStringRef);

AudioSessionInitialize(NULL, NULL, NULL, NULL);

AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state);


BOOL muteSwitch = (CFStringGetLength(state) <= 0);

NSLog(@"Mute switch: %d",muteSwitch);


// code below here is just restoring my own audio state, YMMV

_hasMicrophone = [sharedSession inputIsAvailable];

NSError* setCategoryError = nil;


if (_hasMicrophone) {


    [sharedSession setCategory: AVAudioSessionCategoryPlayAndRecord error: &setCategoryError];


    // By default PlayAndRecord plays out over the internal speaker.  We want the external speakers, thanks.

    UInt32 ASRoute = kAudioSessionOverrideAudioRoute_Speaker;

    AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,

                             sizeof (ASRoute),

                             &ASRoute

                             );

}

else

    // Devices with no mike don't support PlayAndRecord - we don't get playback, so use just playback as we don't have a microphone anyway

    [sharedSession setCategory: AVAudioSessionCategoryPlayback error: &setCategoryError];


if (setCategoryError)

    NSLog(@"Error setting audio category! %@", setCategoryError);


return muteSwitch;

}


查看完整回答
反對 回復 2019-08-12
  • 3 回答
  • 0 關注
  • 647 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號