0
votes

I have single iframe embedded on the web page playing initial song. Below this player I have list of other songs with play button. Now, if any of the play icon is clicked I change the src url of iframe and want to play this new song.

To achive the same I am using js at top of the page.

<script type="text/javascript" src="https://w.soundcloud.com/player/api.js" ></script>

then in my own javascript I have following. On document ready i have following code. Just to check what's going on.

$(document).ready(function () {
var iframeElement = document.querySelector('iframe');
var widget = SC.Widget(iframeElement);
widget.bind(SC.Widget.Events.READY, function () {
    console.log('Ready');
    widget.bind(SC.Widget.Events.PLAY, function () {
        // get information about currently playing sound
        widget.getCurrentSound(function (sound) {
            console.log(sound.title);
        });
    });
    widget.bind(SC.Widget.Events.FINISH, function () {
        console.log('Finished');
    });
    widget.bind(SC.Widget.Events.PAUSE, function () {
        console.log('Paused');
    });
});
widget.seekTo(30000);
widget.toggle();
}());

Now, on play icon click I am calling following function.

function playcurrentpad(curplayurl) {

var iframeElement = document.querySelector('iframe');

var widget = SC.Widget(iframeElement);

widget.pause();

iframeElement.setAttribute('src', curplayurl);

widget.play();

}

Now, from above code, I am able to change the src url of embedded ifram. But, play() is not triggered. And in console I get the line 'SoundCloud Embed Player (api-web)'. So, what is wrong in following code?

1

1 Answers

0
votes

I have solved the issue my self by simply appending auto_play=true in my audio url. It was simple solution but didn't strike.