gpt4 book ai didi

iOS Novocaine 在扬声器上播放

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:03:53 25 4
gpt4 key购买 nike

我正在尝试使用 Novocaine 播放一些高性能音频,但我发现的示例代码仅在耳机中播放音频,但我希望它在扬声器上播放...这可能吗?

谢谢

最佳答案

我已经实现了这样的路由更改,它似乎有效。只需将 sessionPropertyListener 替换为下面的代码并添加 updateAudioRoute

void sessionPropertyListener(void *                  inClientData,
AudioSessionPropertyID inID,
UInt32 inDataSize,
const void * inData){


if (inID == kAudioSessionProperty_AudioRouteChange)
{
Novocaine *sm = (Novocaine *)inClientData;
[sm checkSessionProperties];
[sm updateAudioRoute];
}
}

//Quick and dirty way to override the audioRoute whenever the audioRoute is changed.
- (void)updateAudioRoute {
CFStringRef newRoute;
UInt32 size = sizeof(CFStringRef);
CheckError(AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &size, &newRoute),
"couldn't get new audio route");
if (newRoute)
{
CFShow(newRoute);
if (CFStringCompare(newRoute, CFSTR("ReceiverAndMicrophone"), (UInt32)NULL)== kCFCompareEqualTo)
{
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
}
else if (CFStringCompare(newRoute, CFSTR("HeadsetInOut"), (UInt32)NULL) == kCFCompareEqualTo)
{
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_None;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
}
}
}

关于iOS Novocaine 在扬声器上播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13785215/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com