2016-12-19 7 views
0

をプレイしない:AVplayerはAVPlayerの非常に単純な実装使って特定のリンク

AVURLAsset *asset = [AVURLAsset assetWithURL:self.currentCollateral.url]; 
AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:asset]; 
AVPlayer *player = [AVPlayer playerWithPlayerItem:item]; 
AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init]; 
playerViewController.player = player; 
[player play]; 
[self presentViewController:playerViewController animated:YES completion:nil]; 

をしかし、このリンクは再生されません。

https://www.screencast.com/users/DoorAndHardware/folders/2016%20Orlando%20Conference/media/08848a5a-d414-4bdd-861f-95cf9890d1a1/embed

Player not playing

何をわからない

\ I紛失しています。コードは他のリンクでも機能します。ドキュメントに関連するものが見つからないようです。助けてくれてありがとう!

ベン

答えて

0

あなたのURLは、メディアファイル(例えば.mp4)に埋め込まなく、プレイヤーにリンクしません。

リンクされたプレーヤーサイトのソースコードをご覧になると、used URLが表示されます。このURLはコードで動作するはずです。

+0

ありがとうございました! – Mountainbrussell

0

avplayerで動画を再生する前に、指定したURLが再生可能かどうかを確認する必要があります。 avplayerの下にobserverを追加してください。

[avplayerObject addObserver:self forKeyPath:@"status" options:0 context:nil]; 

#pragma Observer for Player status. 
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { 
    if (object == _audioPlayer && [keyPath isEqualToString:@"status"]) { 
     if (_audioPlayer.status == AVPlayerStatusFailed) { 
      NSLog(@"AVPlayer Failed"); 

     } else if (_audioPlayer.status == AVPlayerStatusReadyToPlay) { 
      NSLog(@"AVPlayerStatusReadyToPlay"); 
       [_audioPlayer play]; 

     } else if (_audioPlayer.status == AVPlayerItemStatusUnknown) { 
      NSLog(@"AVPlayer Unknown"); 

     } 
     [_audioPlayer removeObserver:self forKeyPath:@"status" context:nil]; 
    } 

} 
関連する問題