2016-12-03 4 views
1

스트리밍 재생 오디오를 시도했습니다. 일부 URL에서는 정상적으로 작동하지만 URL이 일부인 경우 (http://listen.radionomy.com/almightyradiohindi) 플레이어 상태도 = AVPlayerStatusReadyToPlay가되면 실패합니다. 브라우저에서 작동하지 않는 동일한 URL을 입력하면 작동하지 않습니다. 하지만 플레이어가 = AVPlayerStatusReadyToPlay와 같은 상태를 나타내지 않아야한다고 생각합니다. 나는 그것을 관리하기 위해 문제에 직면하고있다. 예를 들어 스트리밍 URL AVPlayer가 작동하는지 여부를 어떻게 알 수 있습니까?iOS - 일부 URL에 대해 오디오를 스트리밍하지 않는 AVPlayer

내 코드 : 나는 브라우저에서 오디오 URL (http://listen.radionomy.com/almightyradiohindi)를 열 때이 문제가 해결 될 것입니다 정확한 URL 및 URL 인코딩을 얻을 수 있다면

-(void)viewDidLoad { 
    NSURL *url = [[NSURL alloc] initWithString:urlString]; 
    AVAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil]; 
    AVPlayerItem *anItem = [AVPlayerItem playerItemWithAsset:asset]; 
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; 
    avPlayer = [AVPlayer playerWithPlayerItem:anItem]; 
    [avPlayer addObserver:self forKeyPath:@"status" options:0 context:nil]; 

} 

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { 
    if (object == avPlayer && [keyPath isEqualToString:@"status"]) { 

     if (avPlayer.status == AVPlayerStatusFailed) { 
      NSLog(@"\n\n **** AVPlayer Failed ***\n\n"); 
     } 

     else if (avPlayer.status == AVPlayerStatusReadyToPlay) { 
      NSLog(@"\n\n **** AVPlayer Ready to Play ****\n\n"); 
      [avPlayer play]; 

     } 
     else if (avPlayer.status == AVPlayerItemStatusUnknown) { 
      NSLog(@"\n\n **** AVPlayer Unknown \n\n ****"); 
     } 
    } 
} 
+0

NSURL streamingURL * = [NSURL URLWithString : URL_STRING]; NSLog (@ "% @", streamingURL); player = [AV 플레이어 playerWithURL : streamingURL]; [선수 플레이]; –

+0

문제를 파악 했습니까? – Artur

답변

0

그것 (http://streaming.radionomy.com/AlmightyRadioHindi?lang=en-US%2cen%3bq%3d0.8%2cfa%3bq%3d0.6) 로 변경됩니다 신속한 3.0

URL 인코딩 :

var originalString = "test/test" 
var escapedString = originalString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) 
print(escapedString!) 
+0

@ Hamid, 변경된 URL도 브라우저에서 재생되지 않습니다. 따라서 여기서는 인코딩/디코딩 할 필요가 없습니다. –