jaysalvat / buzz

Buzz is a small but powerful Javascript library that allows you to easily take advantage of the new HTML5 audio element. It tries to degrade silently on non-modern browsers.
http://buzz.jaysalvat.com
MIT License
1.21k stars 227 forks source link

`setTime()` not working on MP3 files #112

Closed jklegseth closed 7 years ago

jklegseth commented 7 years ago

I had a page that used a slider you can slide or click to change playing location. To do that I used setTime() but couldn't get it to work. So I created a barebones example to make sure it wasn't a problem I was introducing, and it still didn't work. What I found is that setTime() works fine with ogg but the same code with a mp3 doesn't work. I'll paste my code below but I've also created JSBin of each so I'll link to those as well. Most of this code is straight from the Buzz library website.

To see the issue click the "Start play at 15 seconds" button--works for ogg, not for mp3.

ogg code

var sound = new buzz.sound("https://upload.wikimedia.org/wikipedia/en/4/45/ACDC_-_Back_In_Black-sample", {
    formats: [ "ogg", "mp3", "aac" ]
});

var play = $('#play');
var stop = $('#stop');
var pause = $('#pause');
var time = $('#time');

play.on('click', function() {
  sound.play()
    .fadeIn()
    .bind("timeupdate", function() {
      var timer = buzz.toTimer(this.getTime());
      document.getElementById("timer").innerHTML = timer;
    });
});

pause.on('click', function() {
  sound.pause();
});

stop.on('click', function() {
  sound.stop();
});

time.on('click', function() {
  sound.setTime(buzz.fromTimer("00:15")).play()
    .bind("timeupdate", function() {
      var timer = buzz.toTimer(this.getTime());
      document.getElementById("timer").innerHTML = timer;
    });
});

mp3 code Same as above except:

var sound = new buzz.sound("https://allthingsaudio.wikispaces.com/file/view/Shuffle%20for%20K.M.mp3/139190697/Shuffle%20for%20K.M", {
  formats: [ "mp3" ]
});
jaysalvat commented 7 years ago

Hello,

Works fine for me on my MP3. Did you try another file?

For example, if I use the controls below your file, it doesn't change time either. https://allthingsaudio.wikispaces.com/file/view/Shuffle%20for%20K.M.mp3/139190697/Shuffle%20for%20K.M.mp3

jklegseth commented 7 years ago

@jaysalvat thanks for the response. That isn't my website or MP3, just a URL I used for testing. This issue started for me on a local server, using local MP3 files and I tried several. I'll do some more testing.

jklegseth commented 7 years ago

My bad, sorry for wasting your time. I tried a few more MP3s, some worked, some didn't, so the issue must be on the encoding side or maybe how they are being served.