user3264844
user3264844

Reputation:

JavaScript variable not working in HTML Audio control?

Audio player not serving its purpose, audio source URL received in JSON and saved in a audio path, variable passed as SRC attribute, still doesn't seem to work

var audio_path = json_defects.audio_path;

$('#audio_edit').html('<audio controls><source src="audio_path" type="audio/mpeg"></audio>');

Upvotes: 0

Views: 187

Answers (1)

David
David

Reputation: 218960

You're setting the src to the literal string "audio_path". Variables don't automatically expand in strings.

Instead, concatenate the variable into the resulting string:

'<audio controls><source src="' + audio_path + '" type="audio/mpeg"></audio>'

Upvotes: 1

Related Questions