使用AVPlayer进行流式传输速度很慢

编程入门 行业动态 更新时间:2024-10-28 22:23:53
本文介绍了使用AVPlayer进行流式传输速度很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用AVPlayer从互联网上流式传输mp3文件,它的运行速度确实很慢.使用分析器发现,它首先下载整个文件,然后开始播放.有什么解决方法吗?

I use AVPlayer for streaming mp3 file from the internet and it works really slow. Using profiler I found out, that it downloads entire file at first, and then starts playing. Is there any workaround for this?

现在,我正在使用此代码

Right now, I'm using this code

if let player = player { NotificationCenter.default.removeObserver(self, name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem) let item = AVPlayerItem(url: url) player.replaceCurrentItem(with: item) } else { player = AVPlayer(url: url) } player?.play()

我尝试过的事情:

  • 将播放器?.play()移动到观察者,该观察者附加到该项目的 status 属性
  • 使用属性 preferredForwardBufferDuration 和 preferredPeakBitRate
  • move player?.play() to an observer, attached to status property of the item
  • play around with properties preferredForwardBufferDuration and preferredPeakBitRate

一直以来,结果都是下载整个音频文件,然后才开始播放.

All the time the result is downloading a whole audio file and only then start of playing.

请注意,问题是-播放器仅在下载整个文件后才开始播放,而我希望它流mp3.

Please note, the issue is - player starts to play ONLY after the whole file was downloaded, while I want it to stream mp3.

推荐答案

要立即播放,您可以尝试设置

To play immediately you can try to set

player.automaticallyWaitsToMinimizeStalling = false

更多推荐

使用AVPlayer进行流式传输速度很慢

本文发布于:2023-10-23 00:32:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519211.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:流式   速度很慢   AVPlayer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!