Файлы .mp3 и .wav работают на симуляторе, но не на устройстве - PullRequest
0 голосов
/ 04 октября 2011

У меня очень распространенный вопрос, поскольку я искал его, но не могу получить правильный ответ для меня.

Вот фрагмент кода, который я стараюсь воспроизвести в аудиофайлах.

в методе 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;

в IBA Действие нажатия кнопки m с вызовом «play» таким образом.

                [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];

Мои методы play и stop:

-(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играет в симулятор а не девайс почему ?!(iPhone-SDK)

mp3-звуки Воспроизведение на симуляторе, но не на устройстве (Audio BeatBox)

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

...........

Я проверил все имена и нет опечаток.

Не знаю, где я ошибаюсь, пожалуйста, помогите !!!

1 Ответ

0 голосов
/ 04 октября 2011

У меня раньше были подобные проблемы, но это решение - случайное предположение, которое работало для меня в то время.

На реальном iPhone пути к файлам чувствительны к регистру. На симуляторе их нет. Поэтому я хотел бы убедиться, что ваши пути к файлам точно указаны, включая регистр.

...