ios - AVAudioPlayer 音量范围?

标签 ios objective-c cocos2d-iphone avaudioplayer

我们在Cocos2d项目中使用了AVAudioPlayer。音频变化不符合预期。

代码:

    NSURL* tapSound = [NSURL fileURLWithPath:[[NSBundle mainBundle] 
                                              pathForResource:@"tap"
                                              ofType:@"m4a"]];

    mClickSound = [[AVAudioPlayer alloc] initWithContentsOfURL: tapSound error: nil];
    [mClickSound prepareToPlay];
    mClickSound.numberOfLoops = 0;
    [mClickSound setVolume: 1.0f];

    mRandomLoopMusic = NULL;

在上面的代码中,我将音量设置为 1.0,但是音乐音量并没有满。当我设置 10.0f 然后增加。所以我的疑问是音量的范围是多少?在 AVAudioPlayer 的文档中,0 - 1 是范围,但在 cocos2D 样本中它不是真的。我们如何将音频范围限制为 0 - 1?

最佳答案

为了改变设备本身的音量,你应该设置

[mClickSound setVolume:1.0];
[[MPMusicPlayerController iPodMusicPlayer] setVolume:1.0];

您还需要添加 MediaPlayer 框架

关于ios - AVAudioPlayer 音量范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8710266/

相关文章:

ios - 在 iOS 的 cocos2d 中添加颜色

ios - 使用导航 Controller 在滑出面板中显示右键

ios - react native : how to change status bar icon colors

ios - scrollsToTop 和 UIRefreshControl 的错误

ios - Storyboard不会做出按钮 Action

ios - 如何在离线时使用 NSURLCache 返回缓存的 API 响应(iOS App)

python - Cocos2d : AttributeError: 'Director' object has no attribute '_window_virtual_width'

ios - Storyboard已编译但 iOS 找不到它并崩溃

ios - 在 Customize UIView 上添加 subview 效果不如预期

iphone - 在 CCTouchesMoved 中使用 Cocos2D 粒子效果时 FPS 降低问题