iphone - 播放最大扬声器电话音量,然后使用 AVAudioPlayer 重置为以前的音量 --- IOS
<p><p>我已经能够将我的音频路由到扬声器电话,但它仍然无法以最大音量播放。我已经尝试过 并且它仍然保持在用户当前设置的音量。如果有人知道我做错了什么,我会非常感激。</p>
<p>这是我的代码:</p>
<pre><code>AVAudioSession *audioSession = ;
;
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
NSURL* soundUrl = pathForResource:@"HsTR_soundEFX_2-1" ofType:@"mp3"]];
audioAlert= [ initWithContentsOfURL:soundUrl error:nil];
audioAlert.delegate = self;
;
;
;
</code></pre>
<p>感谢保罗佩里!</p>
<p>现已解决:</p>
<p>我添加了一些额外内容,以便使用以下代码将其设置回上一卷:</p>
<pre><code> AVAudioSession *audioSession = ;
;
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
NSURL* soundUrl = pathForResource:@"HsTR_soundEFX_2-1" ofType:@"mp3"]];
audioAlert= [ initWithContentsOfURL:soundUrl error:nil];
audioAlert.delegate = self;
;
float maxVolume = 1.0;
float currentVolume=.volume;
[ setVolume:maxVolume];
;
//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
[setVolume:currentVolume];
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>这会将整个系统的音量重置为最大。</p>
<p> float 体积 = 1.0;
[ setVolume:volume];</p></p>
<p style="font-size: 20px;">关于iphone - 播放最大扬声器电话音量,然后使用 AVAudioPlayer 重置为以前的音量 --- IOS,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/12397658/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/12397658/
</a>
</p>
页:
[1]