0

I've got this JavaScript/jquery code:

$(document).ready(function() {
var audioElement = document.createElement('audio');
var secondtrack = 'hangover.ogg';
audioElement.setAttribute('src', 'hangover.ogg');
audioElement.load()
audioElement.addEventListener("load", function() { 
    audioElement.play(); 
}, true);

$('#play').click(function() {
    audioElement.play();
});
$('#pause').click(function() {
    audioElement.pause();
});
});

How could I get another song started after the first ended?

1
  • 2
    I don't think this deserves this many downvotes. The question is, are there events for the audio element that allow this Commented Sep 7, 2011 at 12:54

1 Answer 1

2

The AUDIO element should fire a "ended" event though I am not sure how well this is supported at the moment.

So you could try something like that:

audioElement.addEventListener('ended', function () {
    // Play another song
});

See also: http://dev.w3.org/html5/spec/Overview.html#event-media-ended

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.