Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LabDemo2Js :: "midi.js"
- // Initialize the MIDI.js player
- MIDI.loadPlugin({
- soundfontUrl: "./soundfont/",
- instruments: ["acoustic_grand_piano"], // You can specify the instruments you need
- onsuccess: function() {
- // Load the MIDI file
- MIDI.Player.loadFile(`{{ release root }}{{ project root }}/assets/Midi/DOOM95.MID`, function() {
- // Start playing and loop the MIDI file
- MIDI.Player.addListener(function(data) {
- // Check if the song is over and restart if necessary
- if (MIDI.Player.currentTime === MIDI.Player.endTime) {
- MIDI.Player.currentTime = 0; // Reset to the start
- MIDI.Player.resume(); // Resume playback
- }
- });
- // Start the playback
- MIDI.Player.start();
- });
- }
- });
- // Set volume (0 to 127)
- MIDI.setVolume(0, 100);
- // Pause the MIDI
- MIDI.Player.pause();
- // Resume playback
- MIDI.Player.resume();
- // Stop playback
- MIDI.Player.stop();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement