Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

Adding a "play" or "state-changed" event to Embeds iframe API please.

Adding a "play" or "state-changed" event to Embeds iframe API please.

Hi Spotify,
I would like to ask you to add another event listener to your Embeds player iframe API please.
Adding a "play" or "state-changed" event, as same as you got for your Web Playback SDK, and same as other players have as in Soundcloud/Mixcloud/Youtube/Vimeo/Twitch and so.
This event needs to be fire only once there is a change, unlike the current available event "playback_update" which fires every single second.

Reply
1 Reply

For now to achieve the same goal, I'm doing so:

var myEmbedPlayer;

function createPlayer(){
	const widget = document.querySelector('.my-player-element');
	
	const options = {
		uri: 'spotify:episode:7makk4oTQel546B0PZlDM5'
	};

	const callback = function(EmbedController){
		myEmbedPlayer = EmbedController;
		myEmbedPlayer.state = 'paused';

		myEmbedPlayer.addListener('playback_update',function(e){
			if(e.data && e.data.isPaused == false){
				if(myEmbedPlayer.state != 'playing'){
					myEmbedPlayer.state = 'playing';
					console.log('on play state');
				}
			}else{
				if(myEmbedPlayer.state != 'paused'){
					myEmbedPlayer.state = 'paused';
					console.log('on pause state');
				}
			}
		});
	};

	SpotifyIframeApi.createController(widget, options, callback);
}

 

Suggested posts