2016-06-16 16 views
1

ストリーミングURLがサーバーダウンであり、AVPlayer(Swift 2.2)でエラーが発生しました。Swift 2.2 AVPlayerのエラー処理

私はステータスとレートのオブザーバーを追加しましたが、その応答は期待通りでした。プレーヤーのステータスが再生準備が整っていることを示します。

playerItem = AVPlayerItem(URL: NSURL(string: streaminglink)!) 
playerItem.addObserver(self, forKeyPath: "timedMetadata", options: .New, context: nil) 
player = AVPlayer(playerItem:playerItem) 
player.addObserver(self, forKeyPath: "status", options: NSKeyValueObservingOptions(), context: nil) 
player.addObserver(self, forKeyPath: "rate", options: .New, context: nil) 
player.rate = 1.0 
player.play() 

ヒントは参考になります。ありがとう。

答えて

0

実は、私は、レートオブザーバを削除し、代わりにプレイヤーのステータスオブザーバーの、私は今playerItem

playerItem.addObserver(self, forKeyPath: "status", options: NSKeyValueObservingOptions(), context: nil) 

でそれを適用し、Iストリーミングがオンラインになったとき、またはサーバーが現在停止しているときに取得します。

1

あなたはAVPlayerItemFailedToPlayToEndTimeNotificationのためのオブザーバーとのネットワークの変更を処理することができます:AVPlayer : How to handle network interruptions

+0

あなたの提案と迅速な対応に感謝します。私はそれを試してみましょう。 –

関連する問題