Hi there!
Is there a way for 2 (or more) events to happen on one onClick event?
Basically, I want my user to click on a button ONCE, and then two things to happen:
Event 1) some data gets called from my dataset and it gets sent to a Wix Audio Player
Event 2) it then automatically plays from the audioplayer.
Here's my code so far:
$w.onReady(function() {
$w("#dataset1").onReady(() =>
{const audioLink = $w("#dataset1").getCurrentItem().stream;
$w("#iconButton1").onClick( (event, $w) => {$w('#audioPlayer5').src = (audioLink);} );} );
} );
With this code, the button calls the correct item from the database and sends it to the audio player just fine. The user then has to press PLAY on the player... and I don't want this. I want it to play automatically.
Any suggestions?
Why use code when you can just use the AudioPlayer itself with the track.
https://support.wix.com/en/article/about-the-wix-audio-player
You can set autoplay within the app itself too.
https://support.wix.com/en/article/changing-the-settings-of-your-wix-music-player
If you must do it through code, then simply set it up with a onViewportEnter for example, then you can use that event handler function to play the audio track when the page loads and the element is viewed.
Or simply take out the iconButton with the onClick event handler and put in the src and then play from audioplayer API.
https://www.wix.com/corvid/reference/$w.AudioPlayer.html#src
https://www.wix.com/corvid/reference/$w.AudioPlayer.html#play
Make sure that it is all wrapped up with the page and the dataset onReady functions so that it loads up after the page and dataset has loaded.