Hi, I’m trying to create a gallery where when you click on an item it causes the audio player to play a song that corresponds to the item in the database.
I’ve managed to get half-way there but I have to click twice the same image for the track to change. In addition to this the first track that plays is always the first index in the database regardless of which item is clicked on.
I tried to use the item’s index to set the databases current item.
If anyone can see what I’m doing wrong, I’d be grateful - probably something simple I’ve missed but I’ve been trying for way to many hours. Thanks!
export function gallery1_itemClicked(event) {
let itemIndex01 = event.itemIndex;
console.log(itemIndex01); // 3
$w( ‘#dataset1’ ).setCurrentItemIndex( 3 );
let currentItem = $w( ‘#dataset1’ ).getCurrentItem()
console.log(currentItem);
let player = $w( ‘#audioPlayer1’ )
player.src = currentItem.file;
player.artistName = currentItem.trackId
setTimeout( **function** () {
player.seek( 0 );
player.play();
}, 500 );
}