grimmdude / MidiPlayerJS

♬ MIDI parser & player engine for browser or Node. As a parser converts MIDI events into JSON. Works well with single or multitrack MIDI files.
https://grimmdude.com/MidiPlayerJS/
MIT License
357 stars 52 forks source link

How to skip to a certain time in a midi track? #6

Closed polyclick closed 6 years ago

polyclick commented 6 years ago

I want to start playing at 00:10 seconds in. Is there a method to skip to a certain time? I see in the docs there's a startTime but can't seem to figure out how it works.

grimmdude commented 6 years ago

Hi @polyclick,

Thanks for your message. I don't believe this functionality is implemented yet, but I think all of the logic is in place. I will take a look at this this evening and see if I can get that going for you.

-Garrett

grimmdude commented 6 years ago

Hi @polyclick,

Whew that was a brain twister. Had to rework a few things, which should hopefully optimize playback a bit. I've added a few skipTo methods to the Player class which should be what you're looking for. Let me know if you have any issues.

http://grimmdude.com/MidiPlayerJS/docs/Player.html#skipToSeconds

-Garrett

polyclick commented 6 years ago

Great thanks! I'm gonna try it out and let you know.

grimmdude commented 6 years ago

Cool, just a heads up you'll have to call play() after you skip. So something like:

Player.skipToSeconds(24).play();