2011-10-04 91 views
0

我有很常见的问题,因为我搜索了它,但无法为我获得正确的答案。.mp3和.wav文件适用于模拟器,但不适用于设备

这里是上余米努力地播放音频文件的代码段。

在viewDidLoad方法

NSURL *buttonSound = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/button4.wav", [[NSBundle mainBundle] resourcePath]]]; 

    NSURL *correctSound = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/key_drop1.wav", [[NSBundle mainBundle] resourcePath]]]; 

    NSURL *wrongSound = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/sound8.mp3", [[NSBundle mainBundle] resourcePath]]]; 


    NSError *error; 

    ButtonPressedSound = [[AVAudioPlayer alloc] initWithContentsOfURL:buttonSound error:&error]; 
    ButtonPressedSound.numberOfLoops = 0; 


    correctAnsweredSound = [[AVAudioPlayer alloc] initWithContentsOfURL:correctSound error:&error]; 
    correctAnsweredSound.numberOfLoops = 0; 


    wrongAnsweredSound = [[AVAudioPlayer alloc] initWithContentsOfURL:wrongSound error:&error]; 
    wrongAnsweredSound.numberOfLoops = 0; 
在IBAction为

这样按下一个按钮,打电话是 “玩” 的。

   [ButtonPressedSound play]; 

      [self performSelector:@selector(stop) withObject:nil afterDelay:0.50]; 

       [correctAnsweredSound play]; 

       [self performSelector:@selector(stop) withObject:nil afterDelay:0.50]; 

       [wrongAnsweredSound play]; 

       [self performSelector:@selector(stop) withObject:nil afterDelay:1.0]; 

我的播放和停止的方法是:

-(IBAction)play 
{ 

self.ButtonPressedSound.currentTime = 0; 
[self.ButtonPressedSound play]; 

self.correctAnsweredSound.currentTime = 0; 
[self.correctAnsweredSound play]; 

self.wrongAnsweredSound.currentTime = 0; 
[self.wrongAnsweredSound play]; 


} 

-(IBAction)stop 
{ 
[self.ButtonPressedSound stop]; 
[self.correctAnsweredSound stop]; 
[self.wrongAnsweredSound stop]; 

} 

是我迄今所做的......

...我已经寻找到这些链接,但没有得到答案我的代码。

AVAudioPlayer only plays in simulator but not device why?! (iPhone-SDK)

mp3 Sounds Playing on simulator but not on Device (Audio BeatBox)

http://www.icodeblog.com/2009/05/04/iphone-game-programming-tutorial-part-4-basic-game-audio/

...........

我已经检查了所有的名字ñ没有任何错字错。

不知道其中m越来越错了,请帮助!

回答

0

我以前也有类似的问题,但这种解决方案只是在工作时间对我来说是随机猜测。

在真正的iPhone,文件路径是区分大小写的。在模拟器上,他们不是。所以我会检查以确保您的文件路径完全正确,包括大小写。

相关问题