No Visible interface for 'AVAudioPlayer declares the selector initWithUrl:'

安稳与你 提交于 2020-01-06 15:14:43

问题


I am trying to play a button click sound,also that i should be able to manage click sound along with volume button.

What i have done is Added AVFoundationFramework to project,

in .h file

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

in .m file under button click method

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

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

[player play];

but i get the above error.Any help would be appreciated.


回答1:


It's "initWithContentsOfURL:" not "initWithURL:".

As in:

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


来源:https://stackoverflow.com/questions/20878257/no-visible-interface-for-avaudioplayer-declares-the-selector-initwithurl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!