Added switching between items in playlist display.

This commit is contained in:
Harrison Deng 2022-04-19 17:47:14 -05:00
parent 9a940ea55d
commit d0d6f87f34
2 changed files with 18 additions and 3 deletions

View File

@ -212,14 +212,20 @@ export default class MusicPlaylist {
authorHeader.innerText = "Author";
headers.appendChild(authorHeader);
const insertMusic = (music, musicPos = undefined) => {
if (musicPos) musicPos++;
const insertMusic = (music, musicPos) => {
if (isNaN(musicPos)) throw new Error("Music position in playlist required.");
musicPos++;
const row = element.insertRow(musicPos);
row.insertCell().innerText = music.displayName;
row.insertCell().innerText = music.author;
row.addEventListener("click", () => {
this.currentPosition = musicPos - 1;
});
};
let musicInd = 0;
for (const music of this) {
insertMusic(music);
insertMusic(music, musicInd);
musicInd++;
}
this.addLengthChangeListener((changed, added, music) => {

View File

@ -20,6 +20,12 @@
const playlist = previousPlaylist; // We are assuming you have a playlist ready.
const player = new ask.player.MusicPlayer(playlist) // Creates a new music player with the playlist.
</code></pre>
<p>We'll also show the playlist display so you can see how it updates corresponding to the music currently selected.</p>
<div class="result">
<div id="playlist-display">
</div>
</div>
</div>
<div>
<h2>Display a Play Button</h2>
@ -66,6 +72,9 @@
playlist.add("./assets/audio/moments.mp3", "Moments", "Lost Identities x Robbie Rosen");
playlist.add("./assets/audio/XXI.mp3", "XXI", "QR");
const playlistDispElement = playlist.generatePlaylistElement();
document.getElementById("playlist-display").append(playlistDispElement);
const player = new ask.player.MusicPlayer(playlist);
const playElem = player.generatePlayElement();
document.getElementById("musicplayer-playbtn-demo").appendChild(playElem);