Advertisement
jargon

LabDemo2Js :: "midi.js"

Aug 25th, 2024 (edited)
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // LabDemo2Js :: "midi.js"
  2.  
  3. // Initialize the MIDI.js player
  4. MIDI.loadPlugin({
  5.     soundfontUrl: "./soundfont/",
  6.     instruments: ["acoustic_grand_piano"], // You can specify the instruments you need
  7.     onsuccess: function() {
  8.         // Load the MIDI file
  9.         MIDI.Player.loadFile(`{{ release root }}{{ project root }}/assets/Midi/DOOM95.MID`, function() {
  10.             // Start playing and loop the MIDI file
  11.             MIDI.Player.addListener(function(data) {
  12.                 // Check if the song is over and restart if necessary
  13.                 if (MIDI.Player.currentTime === MIDI.Player.endTime) {
  14.                     MIDI.Player.currentTime = 0; // Reset to the start
  15.                     MIDI.Player.resume(); // Resume playback
  16.                 }
  17.             });
  18.            
  19.             // Start the playback
  20.             MIDI.Player.start();
  21.         });
  22.     }
  23. });
  24.  
  25. // Set volume (0 to 127)
  26. MIDI.setVolume(0, 100);
  27.  
  28. // Pause the MIDI
  29. MIDI.Player.pause();
  30.  
  31. // Resume playback
  32. MIDI.Player.resume();
  33.  
  34. // Stop playback
  35. MIDI.Player.stop();
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement