·H
SystemSoundID sound1;
.m
NSURL *soundURL1 = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"Woosh" ofType:@"mp3"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)soundURL1, & sound1);
AudioServicesPlaySystemSound(sound1);
这是我用来播放Woosh.mp3声音的唯一代码。我在iPad上运行应用程序,当我更改设备上的音量时,声音的音量没有变化。我想知道是否可能有另一种方法将声音应用到应用程序中,或者添加以这种方式更改音量的功能。
答案 0 :(得分:0)
NSURL *soundurl = [[NSBundle mainBundle] URLForResource: @"mysound" withExtension: @"caf"];
AVAudioPlayer *mySoundPlayer =[[AVAudioPlayer alloc] initWithContentsOfURL:soundurl error:&error];
mySoundPlayer .volume=1.0f; //between 0 and 1
[mySoundPlayer prepareToPlay];
mySoundPlayer.numberOfLoops=0; //or more if needed
[mySoundPlayer play];