-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added data-duration attribute option #56
base: master
Are you sure you want to change the base?
Conversation
Nice one. |
Yes it works everywhere. |
As far as I know, Mp3s do not include the duration as metadata in a metatag. An accurate way to retrieve audio, and, I believe, also video duration involves opening and reading the file and converting samples to milliseconds. 11918592 samples = 270263 milliseconds = 04.30 duration. The trick is being able to get the number of samples without reading-in the file, e.g.: the last sample in the music track. Adobe Audition, for example, does this. It reads the entire file, when you open it, to calculate the duration from samples. It takes a moment or so. Players take a different route and arrive at a duration which is more approximated, however pretty accurate most of the time. Perhaps – a big perhaps, as I don't claim to know – based on bitrate and file size. Variable bitrate encodings (VBRs) may skew the result, especially on long audios, and very especially on old VBR Mp3s, that are notorious for returning wrong durations. Safari iOS may be unwilling to commit that kind of error. Conversely, in my experience with Mp3s, the players I use and the relatively short tracks I play, are calculated, I would say, down to a few milliseconds, precisely. That's a guess. If at the outset you set 260 = 04.20 duration is the wrong duration for 11918592 samples. The browser (Safari) contradicts 04.20 when it reaches the end of play, assuming the audio plays longer. I thought I should comment here. IMO, Safari is being cautious. (Too cautious?) Why are the players in other browsers able to approximate duration in advance of playing to the end? How? Trade secret? |
Mp3 file duration is indeed calculated using bitrate number of channels etc... Which is skewed with vbr. Which is why most players will mention "estimated" while it parses the file. But this is not important as you shouldn't use mp3 file format on the Web :) It's also why the usage of data-duration is interesting. Otherwise your browser will completely load the mp3 file just to get the duration :) |
Another skewing factor is the metatag size. Almost all audio formats have or support metatag info. Which is why file size alone gives a wrong duration estimate. In short, metatags increase file size. By how much depends on the metatag (and the information it contains, user-added info, etc.). The assumption is that without loading the metadata, Safari can't even approximate duration. An additional reason your |
Hello |
Hello
Safari does not support the preload=metadata option. It loads the whole audio file.
Which is complicated if it's a big file.
I've added support for a data-duration attribute on the tag . That way you can specify manually the sound file duration before metadata gets loaded.
Take care :)