【问题标题】:Adjusting the size the volume, using the same uislider but for multiple sounds调整音量大小,使用相同的uislider,但用于多种声音
【发布时间】:2011-08-04 20:57:17
【问题描述】:

我的视图中有 10 个声音。还有一个uislider

这是其中一种声音的代码。

- (IBAction)oneSound:(id)sender; {
    SystemSoundID soundID;
    NSString *path = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"mp3"];
    AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path],&soundID);
    AudioServicesPlaySystemSound (soundID);
    if (oneAudio) [oneAudio release];
    NSError *error = nil;
    oneAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error];
    if (error)
        NSLog(@"%@",[error localizedDescription]);
    oneAudio.delegate = self;
    [oneAudio play];    


}

- (void)viewDidLoad {
    [volumeSlider addTarget:self action:@selector(updateVolume) forControlEvents:UIControlEventValueChanged];
    [super viewDidLoad];
}



-(void)updateVolume {
    [oneAudio, twoAudio, threeAudio, fourAudio, fiveAudio, sixAudio, sevenAudio, eightAudio, nineAudio, tenAudio, elevenAudio, twelveAudio, thirteenAudio, fourteenAudio, fifthteenAudio, sixteenAudio setVolume:volumeSlider.value];
}

这是我尝试过的当前方法,但它不起作用。感谢您的帮助

【问题讨论】:

  • 有什么不好的?它崩溃了吗?它根本不播放任何声音?你只能影响一个声音的音量?

标签: iphone xcode cocoa-touch avfoundation


【解决方案1】:

在 updateVolume 中,您不能通过这样列出多个实例来调用它们。您应该做的是将所有这些音频播放器放入一个数组中,并在数组中的每个对象上循环遍历每个和 setVolume

【讨论】:

  • 我该怎么做?非常感谢
  • 你听说过 NSArray 吗?好吧,还有一个 NSMutableArray,它允许您在创建它之后向它添加对象。所以,把你的音频播放器添加到这个数组中。然后,使用 for 循环将它们的音量更改为相同的水平。
猜你喜欢
  • 1970-01-01
  • 2011-01-11
  • 1970-01-01
  • 1970-01-01
  • 2011-04-18
  • 2012-11-06
  • 1970-01-01
  • 1970-01-01
  • 2012-09-18
相关资源
最近更新 更多