5

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.

Any thoughts anyone?

2 Answers2

5

Let the browser load the metadata by setting preload attribute.

Syntax:

<audio preload="auto|metadata|none">

http://www.w3schools.com/tags/att_audio_preload.asp

pixelDino
  • 105
  • 2
  • 9
0

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.

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

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

Hope this helps.

Community
  • 1
  • 1
r8n5n
  • 2,059
  • 17
  • 23