OnMusicEnd

Discuss any general programming issues here
Flinx
Posts: 17
Joined: Sun Feb 14, 2021 9:54 am

OnMusicEnd

Post by Flinx »

While searching for other problems, I added an EventHandler to my player and it crashes since then. I have tried to isolate the problem as much as possible. The following example crashes after a few loops, apparently independent of the MP3 file used (of course there must be one). Tested with Windows 7 32 bit and Windows 10 64 Bit.

Code: Select all

Function p_ToNextMusic()
	DebugPrint("p_ToNextMusic")
EndFunction

;---------
		
InstallEventHandler({OnMusicEnd = p_ToNextMusic})												 

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

	WaitEvent
	CloseMusic(1)
Forever
Ralf

amyren
Posts: 217
Joined: Thu May 02, 2019 11:53 am

Re: OnMusicEnd

Post by amyren »

I just tested your program and this happens here to.
But by adding just a short wait in there it does not crash.

Just an unqualified guess..Could it be that the OS filesystem havent had time to close the file properly before hollywood opens it again and then unpredicted things happen.

Anyway, with this small modification it runs in loops here

Code: Select all

Function p_ToNextMusic()
	DebugPrint("p_ToNextMusic "..counter)
	Wait(2)
EndFunction

;---------
		
InstallEventHandler({OnMusicEnd = p_ToNextMusic})												 

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

Flinx
Posts: 17
Joined: Sun Feb 14, 2021 9:54 am

Re: OnMusicEnd

Post by Flinx »

Hi amyren,

OS functions should not cause timing problems. Already the Amiga had a message system for such things, and if an asynchronous function was not finished, the subsequent call had to wait.
Another hint for a problem with the EventHandler is that if you replace it by "If Not IsMusicPlaying(1)" then the script does not crash too.

Ralf

User avatar
airsoftsoftwair
Posts: 4657
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: OnMusicEnd

Post by airsoftsoftwair »

Clearly a bug, fixed now. Thanks for reporting! As a workaround, just insert a short delay before CloseMusic().

Code: Select all

- Fix: Hollywood could crash when using an "OnMusicEnd" event handler and calling CloseMusic() immediately
  after a music had finished playing

Flinx
Posts: 17
Joined: Sun Feb 14, 2021 9:54 am

Re: OnMusicEnd

Post by Flinx »

Thank you!

Ralf

Flinx
Posts: 17
Joined: Sun Feb 14, 2021 9:54 am

Re: OnMusicEnd

Post by Flinx »

Now that I have tried a bit more, I have to ask again.
The example does not crash anymore with the delay, but still my program. I increased the wait time to some seconds, but that doesn't help either.
But maybe I should explain what I am doing: My program is meant for a Raspberry with a small touch display, it is supposed to become a music player with display of LRC texts. A short test showed that this works in principle, and so I built the program under Windows, where it runs reasonably well.
But under Linux many music files do not work. Some do not start and some do not finish. Since all these files work with other players, I suspect bugs in the avcodec, and wanted to find out what these files have in common.
To do this, I built the test loop that plays everything only short, and in this process I stumbled across the problem with the EventHandler.
Now I have another EventHandler in my program for the mouse operations and timers for scrolling, so it is difficult to locate such errors.
The crah disappears when I remove the EventHandler for OnMusicEnd and check only with IsMusicPlaying.

How should I continue to search? If this can still be the bug you have already fixed, then I could ignore it for now.

User avatar
airsoftsoftwair
Posts: 4657
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: OnMusicEnd

Post by airsoftsoftwair »

Can you try if it works with Hollywood 8? The bug you reported here was introduced with Hollywood 9 so if it crashes with Hollywood 8 too then it's a different thing...

Flinx
Posts: 17
Joined: Sun Feb 14, 2021 9:54 am

Re: OnMusicEnd

Post by Flinx »

No crash with Hollywood 8.
I have condensed the program again, the crash occurs if the interval function is present.

Code: Select all

Function p_ToNextMusic()
	DebugPrint("p_ToNextMusic")
EndFunction

Function p_Scroll()
	Wait(1)
EndFunction

;---------
SetInterval(1, p_Scroll, 50) 	
InstallEventHandler({OnMusicEnd = p_ToNextMusic})												 

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

	WaitEvent
	Wait(20) ; workaround?
	CloseMusic(1)
Forever

User avatar
airsoftsoftwair
Posts: 4657
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: OnMusicEnd

Post by airsoftsoftwair »

Doesn't crash here anymore with the fix mentioned here so I consider this fixed. Since the Wait() workaround doesn't seem to be stable, you should just avoid using "OnMusicEnd" to work around the issue. You could use IsMusicPlaying() instead.

User avatar
airsoftsoftwair
Posts: 4657
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: OnMusicEnd

Post by airsoftsoftwair »

Alternatively, if you want to use "OnMusicEnd" you must make sure that the music is not closed before "OnMusicEnd" has been handled because that's what's causing the crash.

Post Reply