日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

升级iOS10后,AVPlayer有时候播放延时和播放不了的问题

發布時間:2023/12/31 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 升级iOS10后,AVPlayer有时候播放延时和播放不了的问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

如果你的視頻使用的是HLS(m3u8)協議的,是不會由于升級ios10出現這個播放問題的。

如果不是基于HLS協議的,解決方法如下

self.player = [AVPlayer playerWithPlayerItem:self.playerItem]; // [self.player replaceCurrentItemWithPlayerItem:self.playerItem]; if([[UIDevice currentDevice] systemVersion].intValue>=10){ // 增加下面這行可以解決iOS10兼容性問題了self.player.automaticallyWaitsToMinimizeStalling = NO; }

ios10種AVPlayer增加了多個屬性,其中有幾個需要注意一下

  • timeControlStatus
  • automaticallyWaitsToMinimizeStalling
    正是第二個屬性的默認值導致了不使用HLS的方式(比如使用localhttpserver間接實現在線播放、或者下載到本地再播放的方式)就會播放不了的問題。
  • 重點就在上述第二條的官網文檔的這段描述

    ImportantFor clients linked against iOS 10.0 and later or macOS 10.12 and later (and running on those versions), the default value of this property is true. This property did not exist in previous OS versions and the observed behavior was dependent on the type of media played:* HTTP Live Streaming (HLS): When playing HLS media, the player behaved as if automaticallyWaitsToMinimizeStalling is true.* File-based Media: When playing file-based media, including progressively downloaded content, the player behaved as if automaticallyWaitsToMinimizeStalling is false.You should verify that your playback applications perform as expected using this new default automatic waiting behavior.

    在之前的版本中,我們通過rate來判斷avplayer是否處于播放中

    - (Boolean)isPlaying {return self.player.rate==1; }

    在iOS10中,AVPlayer多了一個timeControlStatus,我們就應該這么實現

    - (Boolean)isPlaying {if([[UIDevice currentDevice] systemVersion].intValue>=10){return self.player.timeControlStatus == AVPlayerTimeControlStatusPlaying;}else{return self.player.rate==1;} }

    當時的具體問題是這樣的,我們的場景是有聲繪本,在翻頁時使用了seek來設定起始時間。在調用了[self.player play]方法之后播放器并沒有播放(此時loadedTimeRanges已經足以播放了) self.player.timeControlStatus 是wait狀態。
    這時候其實可以通過另外一個iOS10新增加的屬性reasonForWaitingToPlay來查看wait的原因。

    總的來說,如果在不使用HLS的情況下,AVPlayer新增加的屬性可以比較好的反應實際播放中的一些狀態,而無需我們自己去維護狀態了。

    我們問題解決了。如果你的問題還沒有解決可以再看下這篇WWDC的文章,Advances in AVFoundation Playback。

    總結

    以上是生活随笔為你收集整理的升级iOS10后,AVPlayer有时候播放延时和播放不了的问题的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。