Audio tag not working with variables

Hi,

I am developing an app for iPad.

The Audio tag works when I hard code it

<audio controls>
<source src="audio/file.wav" type="audio/wav">
</audio>

But when I use a variable it doesn’t work

<audio controls>
<source src="{{data.audio.url}}" type="audio/wav">
</audio>

I’ve same issue.
If you find a solution, please post it.
Thanks.

Hi @Romaelz I haven’t found the solution. However, I have used an alternate temporary solution until I find the solution.

Solutions:
in html file

<div id="audio"></div>

In app.js

var str = "<audio controls><source src=' "+$scope.data.audio.url+" ' type='audio/wav'></audio>";
document.findElementById('audio').innerHTML = str;

What about using ngSrc? https://docs.angularjs.org/api/ng/directive/ngSrc

Wouldn’t the following work:

<audio controls>
    <source ng-src="{{data.audio.url}}" type="audio/wav">
</audio>

~ Brad

Hi @ArcReaction,

Using ng-src works for me. Thanks.

@Romaelz Try what ArcReaction said.

Good stuff… glad it’s working for you. :smile:

~ Brad

1 Like