gpt4 book ai didi

ios - AVPlayer 加载缓慢

转载 作者:可可西里 更新时间:2023-11-01 03:58:47 49 4
gpt4 key购买 nike

我正在使用 AVPlayer 从远程 url 播放 mp3 文件。我在 mp3 的初始加载时间上遇到了一些问题,它非常慢(大约 5-8 秒)。
我将它与其他第三方播放器进行比较,它的速度要慢得多,我还将它与 Android 播放器进行比较,它也慢得多。
所以问题不在于 url 本身,也不在于网络连接。

另一个有趣的地方是AVPlayer开始播放mp3后,seeking非常快(几乎是立即),这是否意味着播放器在开始播放之前下载了整个mp3文件,这就是原因这么慢?
我可以控制这种行为吗?如果不是,任何其他想法可能是什么原因?

最佳答案

AVPlayer 有一些新功能(适用于 iOS 10+),您可以尝试一下。我自己使用它,一切正常。

/*!
@method playImmediatelyAtRate:
@abstract Immediately plays the available media data at the specified rate.
@discussion
When the player's currentItem has a value of NO for playbackBufferEmpty, this method causes the value of rate to change to the specified rate, the value of timeControlStatus to change to AVPlayerTimeControlStatusPlaying, and the receiver to play the available media immediately, whether or not prior buffering of media data is sufficient to ensure smooth playback.
If insufficient media data is buffered for playback to start (e.g. if the current item has a value of YES for playbackBufferEmpty), the receiver will act as if the buffer became empty during playback, except that no AVPlayerItemPlaybackStalledNotification will be posted.
*/
- (void)playImmediatelyAtRate:(float)rate NS_AVAILABLE(10_12, 10_0);

另外你可以检查这个变量(你也可以使用 KVO):

   /*!
@property reasonForWaitingToPlay
@abstract Indicates the reason for waiting when the value of timeControlStatus is AVPlayerTimeControlStatusWaitingToPlayAtSpecifiedRate
@discussion
When the value of timeControlStatus is AVPlayerTimeControlStatusWaitingToPlayAtSpecifiedRate, this property describes why the player is currently waiting. It is nil otherwise.
You can use the value of reasonForWaitingToPlay to show UI indicating the player's waiting state conditionally.
This property is key value observable.
Possible values are AVPlayerWaitingWithNoItemToPlayReason, AVPlayerWaitingWhileEvaluatingBufferingRateReason, and AVPlayerWaitingToMinimizeStallsReason.
*/

@property (nonatomic, readonly, nullable) NSString *reasonForWaitingToPlay NS_AVAILABLE(10_12, 10_0);

关于ios - AVPlayer 加载缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42053476/

49 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com