Danke für deine Antwort.
Warum brauch ich für jedes Lied einen neuen Player? Bisher hat alles mit diesem einen Player funktioniert. Jedes neue Lied wird immer wieder in der Variable "audio" gespeichert. Das funktioniert ja auch für das manuelle Aufrufen eines Liedes per Doppelklick.
Hier mal der gesamte Player falls es hilft:
$(document).ready(function(){
//prepare
var audio = document.getElementById('audio1');
var playing = false;
$("#1").css({"color": "#FFFFFF"});
//blink();
//button events
$("#playpause").click(playpause);
$("#rewind").click(rewind);
//volume events
$("#volume").click(setVolume);
//progress events
$("#progress").click(setProgress);
//playlist events
$("div#playlist ol li").hover(function(event) {
$(document.getElementById(event.target.id)).css({"background-color": "#444444"});
}, function(event) {
$(document.getElementById(event.target.id)).css({"background-color": "transparent"});
});
$("div#playlist ol li").dblclick(newSong);
function newSong(event) {
//alert("newsong");
var lisId = event.target.id;
newSong1(lisId);
}
function newSong1(lisId) {
pause();
rewind();
audio = document.getElementById('audio' + lisId);
play();
$("#1").css({"color": "#AAAAAA"});
$("#2").css({"color": "#AAAAAA"});
$("#3").css({"color": "#AAAAAA"});
$("#4").css({"color": "#AAAAAA"});
$(document.getElementById(lisId)).css({"color": "#FFFFFF"});
}
//audio.addEventListener('ended', audioEnded);
audio.onended = function() {
alert("ended");
switch(audio.id) {
case "audio1":
alert("sw1");
newSong1('2');
break;
case "audio2":
alert("sw2");
newSong1('3');
break;
case "audio3":
alert("sw3");
newSong1('4');
break;
case "audio4":
alert("sw4");
newSong1('1');
break;
}
};
//basic functions
function playpause() {
if(playing) {
pause();
} else {
play();
}
}
function play() {
playing = true,
$("#playpause").val("||");
audio.play();
updateTime();
updateProgress();
}
function pause() {
playing = false;
$("#playpause").val(">");
audio.pause();
//blink();
}
function rewind() {
audio.currentTime = 0;
}
var minute = 0;
var second = 0;
var sec = "00";
var currTime = 0;
function updateTime() {
setInterval(function() {
if(playing) {
refreshTime()
} else {
clearInterval();
}
}, 100);
}
function refreshTime() {
currTime = Math.floor(audio.currentTime);
minute = Math.floor(currTime / 60);
second = currTime % 60;
if(second < 10) {
sec = "0" + second;
}
else {
sec = second;
}
$("#time span").html(minute + ":" + sec);
}
function setVolume() {
audio.volume = $("#volume").val();
}
function updateProgress() {
setInterval(function() {
if(playing) {
$("#progress").attr("max", audio.duration);
$("#progress").val(audio.currentTime);
} else {
clearInterval();
}
}, 100);
}
function setProgress() {
audio.currentTime = $("#progress").val();
refreshTime();
}
});