admin管理员组

文章数量:1417108

In my javascript code I create a url from my audio blob

var blobUrl = URL.createObjectURL(blob);

I then have an audio controller. How do I put the blobUrl variable into the src = ?

<audio controls="controls">
<source src= blobUrl type="audio/mp3">
</audio>

In my javascript code I create a url from my audio blob

var blobUrl = URL.createObjectURL(blob);

I then have an audio controller. How do I put the blobUrl variable into the src = ?

<audio controls="controls">
<source src= blobUrl type="audio/mp3">
</audio>
Share Improve this question asked May 23, 2014 at 0:01 SolidCloudincSolidCloudinc 32111 silver badges27 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

You need to get the source element and set its src property.

Lets get the element using the basic js DOM API.

var srcElement = document.getElementsByTagName("source")[0]; // Assuming there's only one

Now lets set the src property using

srcElement.src = blobUrl; or srcElement.setAttribute("src", blobUrl); or jquery's element.attr() method if you get the element using a jquery selector.

本文标签: Put javascript blob variable in src of audioStack Overflow