codnor
codnor

Reputation: 131

HTML5 Audio not playing after src URL injected in

I have something like this on page load:

echo "<td class='audio'><audio controls><source src></audio></td>";

I then make an ajax call based on click to pull relative audio URL's from an API I'm working with to be used as the src.

Upon visiting one of those audio URL's in a separate tab, the audio does in fact play. My thinking is that it's not playing where I need it to because it doesn't get a source until it needs it (used ajax to cut down on load time due to rather large API calls).

Any thoughts?

Upvotes: 1

Views: 285

Answers (2)

Felix Fong
Felix Fong

Reputation: 985

This is work me,or may be you can remove the <source src=""> tag and add src="" inside of the <audio> tag

https://shty.ml?j2n7MxkhKm When you enter this link then click the Preview button

Upvotes: 0

Johannes
Johannes

Reputation: 67768

Your source tag is missing the filetype information. Even is src is replaced by src="your_path/your_file.mp3", it also needs for example type="audio/mpeg" for an mp3-file. The full generated HTML code would have to be something like

<audio controls>
  <source src="your_path/your_file.mp3" type="audio/mpeg">
</audio> 

Upvotes: 0

Related Questions