3
我試圖將耳機插入耳機時將音頻路由到耳機,並在沒有連接耳機時通過iPhone揚聲器播放音頻。AVplayer音頻路由到揚聲器和耳機
我曾嘗試以下
AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange, audioRouteChangeListenerCallback, nil);
void audioRouteChangeListenerCallback (
void *inUserData,
AudioSessionPropertyID inPropertyID,
UInt32 inPropertyValueSize,
const void *inPropertyValue
) {
DetailViewController *controller = (__bridge_transfer DetailViewController *) inUserData;
if (inPropertyID != kAudioSessionProperty_AudioRouteChange) return;
CFDictionaryRef routeChangeDictionary = (CFDictionaryRef)inPropertyValue;
CFNumberRef routeChangeReasonRef = (CFNumberRef)CFDictionaryGetValue (routeChangeDictionary, CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
SInt32 routeChangeReason;
CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable) {
NSLog(@"UnPlugged");
[controller headphoneIsPlugged];
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride),&audioRouteOverride);
} else if (routeChangeReason == kAudioSessionRouteChangeReason_NewDeviceAvailable) {
NSLog(@"Plugged in");
}
}
功能耳機不會被調用的。該計劃甚至不會涉及該部分的這一部分。
現在,當我拔出耳機時,音頻剛剛停止,沒有任何音頻沒有通過揚聲器播放。
裏面的audiolister我試圖把以下 [controller.avplayer play]; 但仍然沒有發生。
請幫