我试图通过变量来改变音效的音量。我正在使用AVAudioPlayer并调用变量来设置音量,但是当我运行该应用程序时,无论变量设置如何,我都听不到任何声音。 (.1-1.0)但是,如果我从AvAudioPlayer块(player.volume = .5;)中设置数字,则它会按照它的响应进行响应。任何想法我做错了什么?我的代码AVAudioPlayer音量从变量
例子:
@interface
@property (nonatomic) float setVolume;
@implementation
@synthesize setVolume;
float setVolume = .5;
-(void)countdown
{
//play sound
NSString *musicFilePath = [[NSBundle mainBundle] pathForResource:@"Countdown_beep" ofType:@"wav"];
NSURL *musicURL = [[NSURL alloc] initFileURLWithPath:musicFilePath];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:musicURL error:nil];
player.volume = setVolume;
[player play];
感谢。 :)
编辑:
我通过从头文件中的声明和创建实施中的伊娃解决了这一问题。
C全局(外部变量)不是一个ivar。 – matt