2012-01-03 53 views
4

我们在Cocos2d项目中使用了AVAudioPlayer。音频变化不像预期的那样。AVAudioPlayer音量范围?

CODE:

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?

回答

0

为了改变设备本身的体积,你应该设置

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

您还需要添加MediaPlayer的框架

+0

对不起,先生......它不是正确的答案...我的问题是如何限制AVAudioPlayer的音量范围....它工作,即使它是1.5 :) – Guru 2013-03-19 14:29:42