Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can audio data from an <iframe>, such as a YouTube video or embedded music player, be accessed with JavaScript?

I am embedding various players on my webpage (YouTube, Spotify, Bandcamp etc.) and would like to change my webpage's state based on the embedded sound. How can this data be accessed?

UPDATE: From evolutionxbox 's comment, I looked into the element of one of the Bandcamp embedded players, and found the below:

    <script type="text/javascript">
        var playerdata = {"tracks":[{"title":"Virga I","encodings_id":1606233426,"file":{"mp3-128":"https://t4.bcbits.com/stream/.....
        var parentpage = "http://localhost:8080/"; // page we are embedded in
        var params = {"tracklist":"false","fgcol":null,"url_referrer":false...

        $(function() {
            HTMLEmbeddedPlayer3.init(playerdata, parentpage, params);
        });
    </script>

This is cool, because I may be able to see this iframe's "playerdata" var programmatically, and access the audio when the user clicks play? I'll be giving it a try.

Bandcamp embeds screenshot

EXTRA:

I also found this helpful thread: Is there anyway to visualize youtube audio from an iframe using the web audio api?

However this solves for only YouTube. Other services (and I'm mainly looking at Bandcamp here) don't have an API to stream the audio, so it would have to be from the iframe itself.

Since the audio is playing on the site it seems there ought to be some way to intercept between the media service and the user, but right now I'm not seeing it.

like image 541
recholsknauber Avatar asked Nov 22 '25 07:11

recholsknauber


1 Answers

No, this is not possible, for security reasons.

Content of different origins will not be accessible.

like image 122
Brad Avatar answered Nov 24 '25 22:11

Brad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!