Audio tag not working with variables


#1

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>

#2

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


#3

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;

#4

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


#5

Hi @ArcReaction,

Using ng-src works for me. Thanks.

@Romaelz Try what ArcReaction said.


#6

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

~ Brad