Announcements

Help Wizard

Step 1

NEXT STEP

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

Let's introduce ourselves!

Hey there you,   Yeah, you! 😁   Welcome - we're glad you joined the Spotify Community!   While you here, let's have a fun game and get…

ModeratorStaff / Moderator/ 4 years ago  in Social & Random