首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从url加载AVPlayer很慢

从url加载AVPlayer很慢
EN

Stack Overflow用户
提问于 2019-08-14 17:00:04
回答 1查看 375关注 0票数 0

我已经创建了AVQueuePlayer来加载音频。信号源来自音频文件。当执行的时候,我发现播放下一个视频需要6-7秒。你能告诉我如何优化下载时间和最小化下载下一个音频的等待时间吗?

下面是我的代码:

代码语言:javascript
运行
复制
let url = URL(string: (audio?.audio_path)!)
let playerItem:AVPlayerItem = AVPlayerItem(url: url!)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-14 17:37:33

我已经回答了一个关于this线程加载缓慢的问题。

AVPlayer具有(来自iOS 10+的)功能,您可以试用。我自己使用了它,一切都运行正常。

代码语言:javascript
运行
复制
/*!
 @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来查看它):

代码语言:javascript
运行
复制
   /*!
     @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);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57491416

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档