我广告使用下面的代码从网络下载一个AMR文件,并由AVAudioPlayer播放,但我总是得到unrecongnize selector sent to instance错误。
这是开始下载和播放的方法:
- (IBAction)DisplayAudioPlayView:(id)sender
{
[self InitializePlayer];
}
-(void) InitializePlayer
{
// Get the file path to the doa audio to play.
NSString *filePath = [[ServerInteraction instance] getAudio:audioData.ID];
// Convert the file path to a URL.
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: filePath];
//Initialize the AVAudioPlayer.
audioPlayer= [AVPlayer playerWithURL:fileURL] ;
audioPlayer.delegate= self; //THIS LINE CAUSE ERROR//
// Preloads the buffer and prepares the audio for playing.
[audioPlayer prepareToPlay];
audioPlayer.currentTime = 0;
[audioPlayer play]
}编辑
基于@Michael建议我更改代码,帖子将代码更改为:
NSURL *fileURL = [[NSURL alloc] initWithString: @"http://www.domain1.com/mysound.mp3"];
//Initialize the AVAudioPlayer.
audioPlayer= [AVPlayer playerWithURL:fileURL];
[audioPlayer play];现在它播放声音,但是当我使用http://maindomain.com/mysound.amr时,它不是在播放声音。
发布于 2014-06-08 07:31:54
检查以下几点:
AVPlayer (音频和视频)还是只想要音频?仅用于音频AVAudioPlayer。下面的代码片段演示如何处理它。AVAudioPlayer,那么您自己的实例是否实现了AVAudioPlayerDelegate协议?#import <AVFoundation/AVFoundation.h>)?https://stackoverflow.com/questions/24103790
复制相似问题