You can use some javascript code to call the STICKY Footer player and its functions. Here are a couple of javascript functions you can use.
Load the sticky player and Play a specific playlist: #
IRON.sonaar.player.setPlayerAndPlay({ id:"1218", trackid:"0"});
id 1218 is the post ID of your playlist post type you want to play. To find out your post ID, see screenshot: https://d.pr/i/KH79f2
trackid 0 would be the first track of the playlist, 1 would be the second track, 2 would be the third track, etc.
Attributes parameters available: “id”, “trackid”, “shuffle”,”soundwave” and “notrackskip”.
Start the Sticky Player from an URL #
Our Sticky Player can be directly started from a URL, allowing you to load and play a specific track at a desired time and share the URL with others. For example:
https://yourdomain.com/?ts_post_id=4669&ts_track_num=1&ts_time=01:03
This URL will load the Sticky Player on your homepage, playing track 1 from playlist ID 4669, starting at 1 minute 3 seconds.
Here’s a breakdown of the parameters:
ts_post_id=4669
This identifies the post ID housing your playlist. Replace 4669 with your desired post ID.ts_track_num=1
This specifies the track number to play from the playlist. Replace 1 with your desired track number.ts_time=01:03
This parameter sets the starting time for the track. Replace 01:03 with your desired start time, formatted as MM:SS.
Simply adjust these parameters in the URL to start the Sticky Player with your desired settings.
Play the track set in the sticky player: #
IRON.sonaar.player.play();
Pause the current track: #
IRON.sonaar.player.pause();
Set the volume at 50% #
sr_setVolume(0.5);
Start a specific playlist or widget player at a specific time: #
sonaar_ts_shortcode({id:"", widget_id:"", trackid:", time:""});
id is the post ID of your playlist post type you want to play. To find out your post ID, see screenshot: https://d.pr/i/KH79f2
widget_id would target the player/widget ID set in your DOM.
trackid:”1″ would be the first track of the playlist, trackid:”2″ the second track, trackid:”3″ the third track.
time:”10:00″ would start the player at 10 minutes.
If you want to trigger click on the NON sticky player (aka free player), you can use this JS code:
jQuery('[data-albums="75"]').find('li:nth-child(2) .audio-track').trigger( "click" );
Trigger function when the track has completed #
You can trigger a function when a track has ended to play. To make the trigger works, you must ensure that:
- Stop when Episode/Track ends option is enabled (see screenshot)
- Sticky Player is enabled
The JavaScript event is:
document.getElementById("sonaar-audio").addEventListener('ended', function() {
var track = IRON.sonaar.player.list.tracks[IRON.sonaar.player.currentTrack];
console.log('track has ended');
console.log( track );
});
Trigger function when the track start #
This can trigger a function when a track start to play. To make the trigger works, you must ensure that:
- Stop when Episode/Track ends option is enabled (see screenshot)
- Sticky Player is enabled
The JavaScript event is:
document.getElementById("sonaar-audio").addEventListener('loadstart', function() {
var track = IRON.sonaar.player.list.tracks[IRON.sonaar.player.currentTrack];
console.log('track has started');
console.log( track );
});
Other Audio Element Event #
You can learn more about native HTML Audio Element events supported by the browser here