需要使用AVAudioPlayer iOS从URL流式传输音频的帮助吗
我正在使用twilio创建一个手机应用程序。我有一个指向语音邮件的链接,我正在尝试从tableview中的控件播放语音邮件。因为我从来没有流式音频之前,我决定简化一切,只是尝试流式音频从任何网址。我试图从中流式传输音频的URL为“” 我尝试过使用苹果开发者页面上的例子,但我想我只是不理解文档 这是我目前正在尝试的,我得到了一个错误需要使用AVAudioPlayer iOS从URL流式传输音频的帮助吗,ios,xcode,audio,stream,avaudioplayer,Ios,Xcode,Audio,Stream,Avaudioplayer,我正在使用twilio创建一个手机应用程序。我有一个指向语音邮件的链接,我正在尝试从tableview中的控件播放语音邮件。因为我从来没有流式音频之前,我决定简化一切,只是尝试流式音频从任何网址。我试图从中流式传输音频的URL为“” 我尝试过使用苹果开发者页面上的例子,但我想我只是不理解文档 这是我目前正在尝试的,我得到了一个错误 NSURL *url = [NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbo
NSURL *url = [NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
NSError *error;
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
我得到了这个错误
Error Domain=NSOSStatusErrorDomain Code=2003334207 "The operation couldn’t be completed. (OSStatus error 2003334207.)"
我是朝着正确的方向走,还是应该做些不同的事情。我发现了许多不同的线索,但我看到的都不能让我播放音频。如果能朝着正确的方向努力,我们将不胜感激
我也尝试过使用AVPlayer
NSURL *url = [NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
self.player = [[AVPlayer alloc] initWithURL:url];
[self.player play];
什么也没发生试试这个
@property (nonatomic,strong) AVPlayer *audioStremarPlayer;
NSURL *url = [NSURL URLWithString:@"your url"];
// stremar player
AVPlayer *player = [[AVPlayer alloc]initWithURL:url];
self.audioStremarPlayer= player;
[self.audioStremarPlayer addObserver:self forKeyPath:@"status" options:0 context:nil];
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (object == self.audioStremarPlayer && [keyPath isEqualToString:@"status"]) {
if (self.audioStremarPlayer.status == AVPlayerStatusFailed)
{
// //NSLog(@"AVPlayer Failed");
}
else if (self.audioStremarPlayer.status == AVPlayerStatusReadyToPlay)
{
[self.audioStremarPlayer play];
}
else if (self.audioStremarPlayer.status == AVPlayerItemStatusUnknown)
{
// //NSLog(@"AVPlayer Unknown");
}
}
}
可能的副本: