function media () {
var div = document.createElement("div");
div.setAttribute("class", "container");
foo.appendChild(div);
var audio = document.createElement("audio");
audio.setAttribute("controls", "controls");
var source = document.createElement("source");
source.setAttribute("src", "media/dimples.ogg");
source.setAttribute("type", "audio/ogg");
source.setAttribute("src", "media/dirty_feeling.ogg");
source.setAttribute("type", "audio/ogg");
source.setAttribute("src", "media/suzieq.ogg");
source.setAttribute("type", "audio/ogg");
source.setAttribute("src", "media/wear_my_ring.ogg");
source.setAttribute("type", "audio/ogg");
audio.appendChild(source);
div.appendChild(audio);
var ul = document.createElement("ul");
ul.setAttribute("id", "playlist");
var li = document.createElement("li");
var a = document.createElement("a");
a.setAttribute("href", "#song1");
var text = document.createTextNode("Dimples");
a.appendChild(text);
li.appendChild(a);
ul.appendChild(li);
li = document.createElement("li");
a = document.createElement("a");
a.setAttribute("href", "#song2");
text = document.createTextNode("Dirty Feeling");
a.appendChild(text);
li.appendChild(a);
ul.appendChild(li);
li = document.createElement("li");
a = document.createElement("a");
a.setAttribute("href", "#song3");
text = document.createTextNode("Suzie Q");
a.appendChild(text);
li.appendChild(a);
ul.appendChild(li);
li = document.createElement("li");
a = document.createElement("a");
a.setAttribute("href", "#song4");
text = document.createTextNode("Wear My Ring");
a.appendChild(text);
li.appendChild(a);
ul.appendChild(li);
div.appendChild(ul);
foo.lastChild.scrollIntoView();
musicColors();
}
This is my fist attempt to create a media player. It has to be in Javascript and I refuse to use jquery(no jquery suggestions please).
I got 2 questions, please:
1) All the song links blend together in one line. Why is this since each li is a child of ul?
2) I was going to create a addEventListner for the song links, but I am not sure what function to reference that actually plays the song?
I had a global ul = display: inline I didn’t see.
audio src need to be re-assigned for each new song. I did with using the javascript Audio object and reused the object for each song.