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?
#audioplayer #wixaudioplayer #onclick #events
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.
Hey @sailorcihan thank you so much for replying. Means a great deal for a novice like me.
The reason why it needs to be done in code is that I need to have just the 1 Wix Audio Player on the page. There are several different iconButtons, and each one sends different dynamic data to the audio player. So, a user chooses which button to press, and that sends a different audio stream out of the player. That all works fine… however, I’m missing the part of the code which makes this data play immediately. Currently, users are having to click which button they want and THEN click play on the player.
(NOTE: I actually want several other things to happen on the page when a user clicks on ‘iconButton1’. But i’m taking it one step at a time, as I’m still learning! Hence why I’d like to know how to code several actions to occur from just 1 onClick event, if you can help with that?).
I’m a little confused with your suggestion, though I am so new to this! Does my reply put things into better context?