2

I am trying use JS to playback some sounds. What i want to do is have piece of music playing but after a certain time replace it with another audio file. I thought the most effective way would be to reuse the same audio object, but it seems to not kill the original sound so all gets messy. What is the best way to do this?

My code is below, all im doing is passing in a new source at a certain time

function inGameSndCreate(src) {
    inGameSnd = new Audio(src)
    inGameSnd.loop = true;
    inGameSnd.play();
}

thanks in advance

1
  • 1
    In which browsers did you test this? Commented Sep 24, 2010 at 19:54

1 Answer 1

2

I expect you'll need to change the source in the DOM using JavaScript. The following should work.

document.getElementById('audio_id').src = 'different_file.wav';
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.