Problem with Music Player Slider not syncing with Audio

Hi everyone,

I’m building a music player in Kodular and I’m facing two issues with the Slider component:

:one: When a song is playing, the Slider does not move automatically to show the current position of the song.
:two: When I drag the Slider to move forward or backward, the music does not seek to the new position.

Here’s what I have done so far:

I added a Clock with a 500ms interval to update the Slider.

The Slider shows progress when I drag it, but it doesn’t affect the music.

I think I might be missing some blocks or arranging them incorrectly.
Could someone please check my block setup and guide me on how to make the Slider sync properly with the music?

Any help would be greatly appreciated!

Thanks in advance :folded_hands:

Firstly try this, It work or not let me know. If not share block/components details.

Set Slider.MaxValue = Player.Duration when the song starts.

  • In Clock.Timer:

set Slider.Position = Player.CurrentPosition

  • In Slider.PositionChanged:

call Player.SeekTo(Slider.Position)

1 Like

Hi securebugs,

Unfortunately, doing it this way creates a conflict because
set Slider.Position triggers Slider.PositionChanged.

It’s a bit more cumbersome :grinning_face_with_smiling_eyes:.

Screen.Initialize

  • We set a ListView with the names of our tracks.

  • When a track is selected:

    • Stop the player if it’s currently playing.
    • Set the Player’s source.
    • As you said, set the Slider’s MaxValue to the track’s duration (ms).
    • Set the TrackDuration label to the track’s duration in "mm:ss" format.
    • Start the player and a Clock that monitors the track’s state (I set the interval to 25 ms).

Slider.PositionChanged

  • Update the TrackPosition label in the same "mm:ss" format to show the current position based on where the slider is.

Slider.TouchDown

  • As soon as the slider is touched, stop the timer; otherwise, it interferes.

Slider.TouchUp

  • As soon as the slider is released, stop the song and restart it from the slider’s position.

SimpleMusicPlayer.aia (4.2 KB)

I hope I’ve explained it clearly enough.

Happy :kodular:oding!!!

2 Likes

No I solved one problem but one problem is remind

I added a slider to control the music.
The slider moves, but when I drag it, it doesn’t stay in the new place it goes back to the old position.
Also, when I move the slider forward or backward, the music doesn’t change at all.

I used a Clock to update the slider and also added the Slider.PositionChanged block, but it’s still not working.

These questions have been asked many times in all AI2 distro communities and answered more than five years ago. Basically, search the forum first:

1 Like