I have a Sub, which handled when I create my new window. It loads and plays an mp3 file using Irrklang library. But how to update the playposition. I heard that i can use timer, but how to use it inside a sub?
Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs)
Dim Music = MyiSoundengine.Play2D("Music/001.mp3")
I Want to update this in every sec!
Dim Music_Playposition = Music.Playpostion
End Sub
You cannot use a timer inside of a method/sub. The only way that a timer works is by periodically raising events; in the case of a timer, it's called the "Tick" event, raised each time that the timer "ticks".
You probably already know what events are—your
MainWindow_Loadedmethod is handling one, theLoadedevent of theMainWindowclass.So what you need to do is add a timer to your application, handle its Tick event, and inside that event handler update your textbox with the current position.
For example:
Note the use of the
WithEventskeyword in the class-level declaration of the timer object. That makes it easy to handle its events using onlyHandlesstatements on the event handler. Otherwise, you have to useAddHandlerinside of the constructor to wire up the event handler methods to the desired events.