2014-01-02 1 views
0

Я пытаюсь воспроизвести звук нажатия кнопки, также, чтобы я мог управлять звуком щелчка вместе с кнопкой громкости.Нет Видимый интерфейс для 'AVAudioPlayer объявляет селектор initWithUrl:'

Что я сделал это Добавлено AVFoundationFramework проекта,

в файле .h

#import <AVFoundation/AVAudioPlayer.h> 
#import <AVFoundation/AVFoundation.h> 

в .m файл под кнопкой мыши методом

NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"mp3"]; 
NSURL *soundUrl = [NSURL fileURLWithPath:soundPath]; 

AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithURL:soundUrl]; 

[player play]; 

, но я получаю выше Ошибка. Любая помощь будет оценена.

ответ

2

Это "initWithContentsOfURL:" не "initWithURL:".

Как и в:

AVAudioPlayer *player = [[AVAudioPlayer alloc] 
          initWithContentsOfURL:soundUrl]; 
+0

Благодаря bro.Error это removed.Problem звук не получает played.Any мысли? –

+0

Да, проверьте, действительно ли у вас есть правильный URL-адрес, используя «' [SoundURL checkResourceIsReachableAndReturnError: & error] '" перед воспроизведением звука. [Есть больше информации о том, что у вас есть правильный URL-адрес в этом вопросе] (http://stackoverflow.com/questions/1927754/testing-file-existence-using-nsurl). –

Смежные вопросы