【问题标题】:AVAudioPlayer volume range?AVAudioPlayer 音量范围?
【发布时间】:2012-01-03 09:40:46
【问题描述】:

我们在 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?

【问题讨论】:

    标签: ios objective-c cocos2d-iphone avaudioplayer


    【解决方案1】:

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

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

    您还需要添加 MediaPlayer 框架

    【讨论】:

    • 对不起先生...它不是正确的答案...我的问题是如何限制 AVAudioPlayer 的音量范围....即使它是 1.5 也可以工作 :)
    猜你喜欢
    • 1970-01-01
    • 2012-09-22
    • 2010-11-16
    • 1970-01-01
    • 1970-01-01
    • 2017-11-07
    • 2013-09-03
    • 1970-01-01
    • 2022-08-11
    相关资源
    最近更新 更多