gpt4 book ai didi

iphone - 播放最大 speakerPhone 音量,然后使用 AVAudioPlayer 重置为之前的音量 --- IOS

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

我已经能够将我的音频路由到免提电话,但它仍然无法以可能的最大音量播放。我试过 [audioAlert setVolume:1.0],它仍然保持在用户当前设置的音量。如果有人知道我做错了什么,我将不胜感激。

这是我的代码:

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:NULL];

UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);

NSURL* soundUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"HsTR_soundEFX_2-1" ofType:@"mp3"]];
audioAlert= [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];
audioAlert.delegate = self;
[audioAlert setVolume:1.0];
[audioAlert prepareToPlay];
[audioAlert play];

感谢 PaulPerry!

现已解决:

我添加了一些额外的内容以使用以下代码将其设置回之前的卷:

 AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:NULL];

UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);

NSURL* soundUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"HsTR_soundEFX_2-1" ofType:@"mp3"]];
audioAlert= [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];
audioAlert.delegate = self;
[audioAlert prepareToPlay];
float maxVolume = 1.0;
float currentVolume=[MPMusicPlayerController applicationMusicPlayer].volume;
[[MPMusicPlayerController applicationMusicPlayer] setVolume:maxVolume];
[audioAlert play];
//set up timer to wait until audioAlert is finished playing,
// and then call the line below to set the volume back to it's original setting
[[MPMusicPlayerController applicationMusicPlayer]setVolume:currentVolume];

最佳答案

这会将整个系统的音量重置为最大。

float 量 = 1.0;[[MPMusicPlayerController applicationMusicPlayer] setVolume:volume];

关于iphone - 播放最大 speakerPhone 音量,然后使用 AVAudioPlayer 重置为之前的音量 --- IOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12397658/

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