MediaElement.js-如何设置播放音频之前的持续时间? [英] MediaElement.js - How do you set duration before playing audio?

查看:178
本文介绍了MediaElement.js-如何设置播放音频之前的持续时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以在音频播放器上第一次按播放之前预加载持续时间.我知道您可以使用{duration:120},如果每个剪辑的长度都为120秒,那就很好了.我没有数据库中可用的信息来动态填充此变量,因此必须有另一种方法来调整MediaElement.JS脚本来实现.

Is there a way to preload the duration before pressing play the first time on an audio player. I know you can use { duration: 120 } which is fine if every clip is 120 seconds long. I do not have the information available in the database to dynamically populate this variable so there must be another way to tweak the MediaElement.JS script to do it.

有人在想什么吗?

推荐答案

我认为mediaelement.js无法获得在下载全部或部分文件之前的持续时间.您可以播放视频,轮询duration属性,直到获得一个值,然后将视频重置为开始.虽然那不是很优雅.

I don't think mediaelement.js has a way of getting the duration before all or part of the file has been downloaded. You could play the video, poll the duration property until you get a value then reset the video to the start. Though that would not be very elegant.

您可以使用类似于此客户端的JavaScript库: https://github.com/aadsm/JavaScript-ID3-Reader

You could used a JavaScript library like this client side: https://github.com/aadsm/JavaScript-ID3-Reader

如果您使用的是PHP,则可以在此服务器端进行操作.有关更多信息,请参见 PHP函数以获取MP3持续时间.

If you are using PHP then you could do this server side. See PHP Function to get MP3 duration for more info.

希望这会有所帮助.

这篇关于MediaElement.js-如何设置播放音频之前的持续时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆