mp3 player glitch

kolbe

Active Member
Licensed User
Longtime User
Hello again,

I've written a simple mp3 player but have a small glitch. I'm using a trackbar to show/control the position in the mp3 file. Once the file is playing a timer is set so that once a second I update the trackbar position. I would like however for the user to be able to change the position of the trackbar as well using sub trackbar_valuechanged.

What happens however is that when the timer event is triggered the trackbar_valuechanged is subsequently triggered as well because the trackbar value is changed programatically. The sub trackbar_valuechanged then reassigns fmod.position which causes a small tick in the audio playback.

Has anybody found the same problem?

Thanks
 

kolbe

Active Member
Licensed User
Longtime User
OK!

Now to answer my own question... Using a global variable to keep track of the previous trackbar value I can reduce the effect. If the trackbar has changed significantly, the user moved the trackbar, only then do I change fmod.position. This works good enough.
 

cpc6128

Member
Licensed User
kolbe,

one way of solving your problem would be to declare a global variable that your trackbar ValueChanged sub can use to differentiate a change made within the program from a change made by user input. In this example, the code in bar_ValueChanged only executes if the change DOES NOT come from Timer1_Tick:

Sub Globals
Dim auto_change
End Sub

Sub Timer1_Tick
auto_change=true
' change bar.value here
auto_change=false
End Sub

Sub bar_ValueChanged
If auto_change=false Then
' change fmod.position here
End If
End Sub
 

derez

Expert
Licensed User
Longtime User
track bar

I had the same problem and decided to show the advance of the song by a progress bar, and allow the user to select a new point in the song by moving the track bar - but the track bar is not moving, only by the user:

Sub Timer1_Tick
...
progressBar1.Value = fmod.Position / fmod.Length1 * 100
...
end sub

Sub Bar1_ValueChanged
fmod.Position = bar1.Value * fmod.Length1 /100
End Sub

not ellegant but efficient...
 

Attachments

  • Screen01.jpg
    Screen01.jpg
    12.5 KB · Views: 173
Top