Page 2 of 2

Re: OnMusicEnd

Posted: Sat May 15, 2021 2:55 pm
by Flinx
That means, I should not call CloseMusic() from the EventHandler for OnMusicEnd?
Nevertheless, with a try by IsMusicPlaying() the program works.

My next step is to find out what avcodec makes better in Windows than in Linux.

Re: OnMusicEnd

Posted: Sun May 16, 2021 9:05 pm
by airsoftsoftwair
Flinx wrote: Sat May 15, 2021 2:55 pm That means, I should not call CloseMusic() from the EventHandler for OnMusicEnd?
You must not call CloseMusic() before "OnMusicEnd" has triggered. So you must make sure that CloseMusic() is never called before "OnMusicEnd" has triggered for that music. In your example, that's not the case because you do something like:

Code: Select all

Repeat
	OpenMusic(1, "test.mp3")
	PlayMusic(1)
	SongDuration = GetAttribute(#MUSIC, 1, #ATTRDURATION)
	SeekMusic(1, SongDuration-1500)

	WaitEvent
	Wait(20) 
	CloseMusic(1)  ; !!! this might be called before Hollywood calls your "OnMusicEnd" handler !!!
Forever

Re: OnMusicEnd

Posted: Tue Jun 01, 2021 1:44 pm
by Flinx
I see that my second example was nonsense because I simply added SetInterval, the real program structure is different.
In my script I have a user interface where a click should start the same action like the OnMusicEnd event: Close the current music and skip to the next. This is in the function p_ToNextMusic (hence the name in the example), there I call a second function (StopMusic) with CloseMusic() and then open the next. This function is called in both cases (from the mouse click event and from the handler for OnMusicEnd), so one time after the EventHandler was triggered and one time without.
Do I understand correctly that this should not be done?

Re: OnMusicEnd

Posted: Tue Jun 01, 2021 7:39 pm
by airsoftsoftwair
Flinx wrote: Tue Jun 01, 2021 1:44 pm I see that my second example was nonsense because I simply added SetInterval, the real program structure is different.
In my script I have a user interface where a click should start the same action like the OnMusicEnd event: Close the current music and skip to the next. This is in the function p_ToNextMusic (hence the name in the example), there I call a second function (StopMusic) with CloseMusic() and then open the next. This function is called in both cases (from the mouse click event and from the handler for OnMusicEnd), so one time after the EventHandler was triggered and one time without.
Do I understand correctly that this should not be done?
Hmm, actually, if your p_ToNextMusic() is called *after* OnMusicEnd has triggered it shouldn't cause any problems. The crash should only occur if p_ToNextMusic() is called *before* Hollywood has called your OnMusicEnd callback...