2022-04-20 04:11:08 +00:00
< link rel = "stylesheet" href = "./assets/css/main.css" / >
< script src = "./assets/js/prism.js" defer > < / script >
< script src = "./assets/js/audioshowkit.js" > < / script >
2022-04-18 16:46:23 +00:00
2022-04-20 04:11:08 +00:00
< div class = "part" >
2022-04-23 13:57:34 +00:00
< h2 > Creating a Music Playlist< / h2 >
2022-04-20 04:11:08 +00:00
< p >
A music playlist is a list of {@link Music} which maintains metadata about the playlist, such as the length, and the name of the playlist. It also keeps track of an index for a position in the playlist.
< / p >
< / div >
< div class = "part" >
2022-04-23 13:57:34 +00:00
< h3 > Instantiation< / h3 >
2022-04-20 04:11:08 +00:00
< p > Instantiation is simple. We grab a reference to the audioshowkit library from global, and then under the "player" path, we find the music playlist constructor.< / p >
< pre > < code class = "language-js" >
// Get the entry point to all of AudioShowKit's glory.
const ask = window.audioshowkit;
2022-04-18 16:46:23 +00:00
2022-04-20 04:11:08 +00:00
// The only parameter is the name of the playlist.
const playlist = new ask.player.MusicPlaylist("Awesome Music");
< / code > < / pre >
< / div >
< div class = "part" >
2022-04-23 13:57:34 +00:00
< h3 > Adding Music< / h3 >
2022-04-20 04:11:08 +00:00
< p > A music playlist is no good if it doesn't have music. Lets add some.< / p >
< pre > < code class = "language-js" >
// Still using the same context from the instantiation example...
2022-04-18 16:46:23 +00:00
2022-04-20 04:11:08 +00:00
playlist.add("/assets/audio/moments.mp3", "Moments", "Lost Identities x Robbie Rosen"); // It's that easy.
playlist.add("/assets/audio/XXI.mp3", "XXI", "QR"); // Let's add another one.
< / code > < / pre >
2022-04-18 16:46:23 +00:00
2022-04-20 04:11:08 +00:00
< p > If for whatever reason, you decided to instantiate your own {@link Music}, that's okay too!< / p >
< pre > < code class = "language-js" >
// Still using the same context from the instantiation example...
2022-04-18 16:46:23 +00:00
2022-04-20 04:11:08 +00:00
// Either instantiate, or otherwise have this Music object.
const pathetiqueMusic = new ask.player.Music("/assets/audio/pathetique.mp3", "Sonata No. 8", "Beethoven");
playlist.addExisting(pathetiqueMusic); // Wow, a special function!
< / code > < / pre >
< / div >
< div class = "part" >
2022-04-23 13:57:34 +00:00
< h3 > Display< / h3 >
2022-04-20 04:11:08 +00:00
< p > In the case you want to show the playlist without coding your own display, we provide a simple generator for you!< / p >
< pre > < code class = "language-js" >
// Still using the same context from the instantiation example...
2022-04-18 16:46:23 +00:00
2022-04-20 04:11:08 +00:00
const playlistElem = playlist.generatePlaylistElement(); // Returns an HTMLElement!
2022-04-18 16:46:23 +00:00
2022-04-20 04:11:08 +00:00
// Assuming we do have an acceptable element that can take a child element.
document.getElementById("musicplaylist-demo").appendChild(playlistElem);
< / code > < / pre >
< div class = "result" >
< div id = "musicplaylist-demo" >
2022-04-18 16:46:23 +00:00
< / div >
2022-04-20 04:11:08 +00:00
< / div >
< / div >
2022-04-18 16:46:23 +00:00
2022-04-20 04:11:08 +00:00
< script >
const ask = window.audioshowkit;
const playlist = new ask.player.MusicPlaylist("Awesome Music");
2022-04-18 16:46:23 +00:00
2022-04-20 04:11:08 +00:00
playlist.add("./assets/audio/moments.mp3", "Moments", "Lost Identities x Robbie Rosen"); // It's that easy.
playlist.add("./assets/audio/XXI.mp3", "XXI", "QR"); // Let's add another one.
2022-04-18 16:46:23 +00:00
2022-04-20 04:11:08 +00:00
const pathetiqueMusic = new ask.player.Music("/assets/audio/pathetique.mp3", "Sonata No. 8", "Beethoven");
playlist.addExisting(pathetiqueMusic);
2022-04-18 16:46:23 +00:00
2022-04-20 04:11:08 +00:00
const playlistElem = playlist.generatePlaylistElement();
document.getElementById("musicplaylist-demo").appendChild(playlistElem);
< / script >