[英]Is there a way to stop the AVPlayer's rate property being reset?
我正在使用AVPlayer對象進行視頻播放,並具有控件來調整播放器的速率。
除了每次按停止/暫停按鈕將AVplayer對象的速率值似乎重置為1.0之外,所有其他方法都工作正常。 有辦法防止這種情況發生嗎?
非常感謝。
[AVPlayer play]
等效於[AVPlayer setRate:1.0]
[AVPlayer pause]
等於[AVPlayer setRate:0.0]
MPMediaItem為您提供一個屬性來讀取媒體項目的每分鍾節拍數。
像這樣-
MPMediaItem *item = [[MPMediaItem alloc]init] ;
.
.
.
int BPM = [item valueForProperty:MPMediaItemPropertyBeatsPerMinute];
現在,計算您要設置媒體項目的費率的費率-
float rate = newBPM/(float)BPM; // lets say BPM = 100, You want to double the rate of the media then newBPM = 200
現在將此速率設置為AVPlayer對象-
[AVPLayer setRate:rate];
通過AVPlayer的“播放”方法重置速率很奇怪,但確實如此。 我習慣使用以下代碼作為解決方法,以加載新的播放器項目,調整播放速率並讓其播放:
[self.player replaceCurrentItemWithPlayerItem: [AVPlayerItem playerItemWithURL: movieURL]];
self.player.rate = PLAYER_RATE;
[self.player seekToTime: kCMTimeZero];
為Google的利益而跟進...
每次播放器開始播放時,rate屬性都會重置為1.0,因此您需要保持rate值,否則將在每次播放時重新應用它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.