Advertisement
lule34567

melonland jukebox modified

Sep 2nd, 2024 (edited)
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. <div>
  2. <!-- Melon's Mini Jukebox - Plays MIDIs, MP3s, and most audio files -->
  3. <div id="mk-juke" style="display: flex; justify-content: center; text-align: center; flex-wrap: wrap;">
  4. <marquee id="jukebox_title" style="color: blue; background-color: black; vertical-align: middle; font-size: 25px; height: 30px;"></marquee>
  5. <button id="mk-juke-prev" onclick="playPreviousSong()">Previous</button>
  6. <button id="mk-juke-play" onclick="mkPlay()">Play!</button>
  7. <button id="mk-juke-next" onclick="playNextSong()">Next</button>
  8. </div>
  9. <script src="https://www.midijs.net/lib/midi.js"></script>
  10. <script>
  11. var mkJuke = {};
  12. mkJuke.play = document.getElementById("mk-juke-play");
  13. mkJuke.isPlaying = false;
  14. mkJuke.audio = new Audio();
  15. mkJuke.currentSongIndex = 0;
  16.  
  17. // Define your songs here
  18. mkJuke.songs = [
  19. { title: "title", src: "./audio/file/path/here"},
  20. ];
  21.  
  22. mkJuke.audio.addEventListener('ended', playNextSong);
  23.  
  24. function mkPlay() {
  25. if (mkJuke.isPlaying) {
  26. stopCurrentSong();
  27. return;
  28. }
  29. playCurrentSong();
  30. }
  31.  
  32. function stopCurrentSong() {
  33. if (mkJuke.audio) {
  34. mkJuke.audio.pause();
  35. mkJuke.audio.currentTime = 0; // Reset audio to start
  36. }
  37. MIDIjs.stop();
  38. mkJuke.play.innerHTML = "Play!";
  39. mkJuke.isPlaying = false;
  40. }
  41.  
  42. function playCurrentSong() {
  43. let song = mkJuke.songs[mkJuke.currentSongIndex].src;
  44. if (song.includes(".mid")) {
  45. MIDIjs.play(song);
  46. } else {
  47. mkJuke.audio.src = song;
  48. mkJuke.audio.play();
  49. }
  50.  
  51. mkJuke.isPlaying = true;
  52. mkJuke.play.innerHTML = "Stop!";
  53.  
  54. document.getElementById('jukebox_title').textContent = "♪♫ - Now Playing " + mkJuke.songs[mkJuke.currentSongIndex].title + " ♪♫";
  55. }
  56.  
  57. function playNextSong() {
  58. mkJuke.currentSongIndex = (mkJuke.currentSongIndex + 1) % mkJuke.songs.length;
  59. playCurrentSong();
  60. }
  61.  
  62. function playPreviousSong() {
  63. mkJuke.currentSongIndex = (mkJuke.currentSongIndex - 1 + mkJuke.songs.length) % mkJuke.songs.length;
  64. playCurrentSong();
  65. }
  66.  
  67. // Autoplay on load
  68. window.onload = mkPlay;
  69. </script>
  70. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement