2015-02-10 75 views
-1

我使用twilio創建一個手機應用程序從URL流式音頻。我有一個語音信箱的鏈接,我正嘗試在桌面視圖中使用控件播放語音郵件。由於在決定簡化所有內容之前,我從來沒有對音頻進行流式處理,只是嘗試從任何URL流式傳輸音頻。我嘗試從中串流音頻的網址是「http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8」。需要幫助使用AVAudioPlayer的iOS

我一直在使用從蘋果開發者頁面的例子試過,但我想我只是不理解的文檔。

這是我目前正在和我得到一個錯誤。

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

,並沒有任何反應

+0

的可能重複:HTTP://stackoverflow.com/questions/23908870/avplayer而不是扮演,流媒體,無線與動態-URL/23909395#23909395 – karthikeyan 2015-02-10 10:14:20

回答

2

試試這個

@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"); 

     } 
    } 
}