Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div>
- <!-- Melon's Mini Jukebox - Plays MIDIs, MP3s, and most audio files -->
- <div id="mk-juke" style="display: flex; justify-content: center; text-align: center; flex-wrap: wrap;">
- <marquee id="jukebox_title" style="color: blue; background-color: black; vertical-align: middle; font-size: 25px; height: 30px;"></marquee>
- <button id="mk-juke-prev" onclick="playPreviousSong()">Previous</button>
- <button id="mk-juke-play" onclick="mkPlay()">Play!</button>
- <button id="mk-juke-next" onclick="playNextSong()">Next</button>
- </div>
- <script src="https://www.midijs.net/lib/midi.js"></script>
- <script>
- var mkJuke = {};
- mkJuke.play = document.getElementById("mk-juke-play");
- mkJuke.isPlaying = false;
- mkJuke.audio = new Audio();
- mkJuke.currentSongIndex = 0;
- // Define your songs here
- mkJuke.songs = [
- { title: "title", src: "./audio/file/path/here"},
- ];
- mkJuke.audio.addEventListener('ended', playNextSong);
- function mkPlay() {
- if (mkJuke.isPlaying) {
- stopCurrentSong();
- return;
- }
- playCurrentSong();
- }
- function stopCurrentSong() {
- if (mkJuke.audio) {
- mkJuke.audio.pause();
- mkJuke.audio.currentTime = 0; // Reset audio to start
- }
- MIDIjs.stop();
- mkJuke.play.innerHTML = "Play!";
- mkJuke.isPlaying = false;
- }
- function playCurrentSong() {
- let song = mkJuke.songs[mkJuke.currentSongIndex].src;
- if (song.includes(".mid")) {
- MIDIjs.play(song);
- } else {
- mkJuke.audio.src = song;
- mkJuke.audio.play();
- }
- mkJuke.isPlaying = true;
- mkJuke.play.innerHTML = "Stop!";
- document.getElementById('jukebox_title').textContent = "♪♫ - Now Playing " + mkJuke.songs[mkJuke.currentSongIndex].title + " ♪♫";
- }
- function playNextSong() {
- mkJuke.currentSongIndex = (mkJuke.currentSongIndex + 1) % mkJuke.songs.length;
- playCurrentSong();
- }
- function playPreviousSong() {
- mkJuke.currentSongIndex = (mkJuke.currentSongIndex - 1 + mkJuke.songs.length) % mkJuke.songs.length;
- playCurrentSong();
- }
- // Autoplay on load
- window.onload = mkPlay;
- </script>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement