Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9106629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:23:00+00:00 2026-06-17T02:23:00+00:00

Possible Duplicate: HTML5 audio element with dynamic source I’m trying to get the player

  • 0

Possible Duplicate:
HTML5 audio element with dynamic source

I’m trying to get the player to reload a new track once the current one ends, but I think I might have done something wrong.

This is the player:

<audio id="audio" autoplay controls="controls" onclick="start()">
<source src="song.php" type="audio/mpeg" />
</audio>

Here’s the script:

function start(){
    var audio = document.getElementById('audio');
    audio.play();
    audio.addEventListener('ended',function(){
        $.post("song.php", function(result){
        audio.src = result;
        audio.pause();
        audio.load();
        audio.play();
    });
    });
}

If I change the script to this, it works…but I don’t want to reload the whole page:

function start(){
    var audio = document.getElementById('audio');
    audio.play();
    audio.addEventListener('ended',function(){
        window.location = 'player.html';
    });
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T02:23:01+00:00Added an answer on June 17, 2026 at 2:23 am

    For starters, you are attaching a new event handler every single time the element is clicked. If someone frequently pauses the music, they will run into problems.

    Intead, try this:

    <audio id="audio" autoplay controls src="song.php" type="audio/mpeg"></audio>
    <script type="text/javascript">
        document.getElementById('audio').addEventListener("ended",function() {
            this.src = "song.php?nocache="+new Date().getTime();
            this.play();
        });
    </script>
    

    I’m assuming that song.php is a PHP file that returns the audio data. The nocache query parameter will ensure that the file is actually called every time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Set HTML5 doctype with XSLT I'm new to xslt and I'm trying
Possible Duplicate: JavaScript move delay and multiple keystrokes I'm new and learning HTML5 canvas
Possible Duplicate: Why doesn’t Firefox support mp3 file format in <audio> I am trying
Possible Duplicate: get a >24 fps framerate in HTML5 video? And if it's not
Possible Duplicate: Using jQuery to control HTML5 <audio> volume I have a html audio
Possible Duplicate: Text blinking jQuery I'm trying to create a timer in my HTML5/JavaScript
Possible Duplicate: Storing Objects in HTML5 localStorage I'm trying to store JSON data, name
Possible Duplicate: HTML5 local storage sort I am storing data into a localstorage using
Possible Duplicate: How to parse and process HTML with PHP? I am brand new
Possible Duplicate: HTML5 form required attribute. Set custom validation message? in HTML 5 form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.