7

またはを使用して Mac のヘッドフォン ジャックに何かが接続されているかどうかを検出する方法はありますcobjective-c?

ありがとう

4

3 に答える 3

8

あなたがまだこの深い魔法に飛び込みたいと思っているなら、私はここで見つけたコードから何かを一緒に構築することができました:

http://www.iphonedevsdk.com/forum/iphone-sdk-development/54013-hardware-volume-change-listener-callback.html

AudioProperties のリッスンを登録し、「kAudioSessionProperty_AudioRouteChange」に関するメッセージをキャッチします。「理由」と「名前」を使用して、何が起こったかをまとめて解析できます。詳細については、こちらをご覧ください:

http://developer.apple.com/library/ios/#DOCUMENTATION/AudioToolbox/Reference/AudioSessionServicesReference/Reference/reference.html

// Registers this class as the delegate of the audio session.
[[AVAudioSession sharedInstance] setDelegate: self];

// Use this code instead to allow the app sound to continue to play when the screen is locked.
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];

// Registers the audio route change listener callback function
AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, audioRouteChangeListenerCallback, self);

折り返し電話:

void audioRouteChangeListenerCallback (void *inUserData, AudioSessionPropertyID inPropertyID, UInt32 inPropertyValueSize, const void *inPropertyValue ) {
    // ensure that this callback was invoked for a route change
    if (inPropertyID != kAudioSessionProperty_AudioRouteChange) return;


    {
        // Determines the reason for the route change, to ensure that it is not
        //      because of a category change.
        CFDictionaryRef routeChangeDictionary = (CFDictionaryRef)inPropertyValue;

        CFNumberRef routeChangeReasonRef = (CFNumberRef)CFDictionaryGetValue (routeChangeDictionary, CFSTR (kAudioSession_AudioRouteChangeKey_Reason) );
        SInt32 routeChangeReason;
        CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);

        if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable) {

            //Handle Headset Unplugged
        } else if (routeChangeReason == kAudioSessionRouteChangeReason_NewDeviceAvailable) {
                    //Handle Headset plugged in
        }

    }
}
于 2011-05-09T23:03:20.053 に答える
4

これは「それらのこと」の 1 つです。つまり、絶対にすべきではないこと、絶対に行う必要があること、または知っておく必要があることです。一般的な考え方は、サウンドを再生するために提供されている API を使用し、残りはサウンド サブシステムが処理するというものです。

特定の設定が必要な場合は、ダイアログ ボックスを介してユーザーに特定の方法でシステムを親切に設定するよう依頼できますが、それだけです。

編集:この理由は、一般的なドライバー プログラミング、特にサウンド プログラミングは深い魔法を構成するためであり、何らかの理由でマシンのハードウェアを取り込もうとするアプリケーションは通常、見事に失敗しますが、多くの場合、非常に微妙です。

既知の限定された一連のマシン向けのエンタープライズ アプリケーションを開発している場合を除き、マシンのハードウェアについて決して仮定しないでください。気が付くと、iMac の次のモデルには、アナログ ジャックがまったくないなどの仕様になっています。

また、アナログ ジャックが存在し、空の場合でも、オンボード、PCI、または USB のいずれかのセカンダリ サウンド カードを介してサウンドを送信できます。メモリが機能する場合は、FireWire サウンド カードさえも出回っています。

于 2011-05-05T06:14:18.083 に答える
-4

これは、組み込みチップに存在する (または存在しない) 隠し機能です。製造元が API をリリースした場合は、それを制御できますが、そうでない場合は制御できません。

于 2011-05-05T07:51:28.170 に答える