mjbrusso / AudioPlayer

audioplayer is a cross platform Python 3 package for playing sounds (mp3, wav, ...). It provides the key features of an audio player, such as opening a media file, playing (loop/block), pausing, resuming, stopping, and setting the playback volume.
MIT License
37 stars 11 forks source link

AudioPlayer with wxPython #3

Open reticulatus opened 4 years ago

reticulatus commented 4 years ago

I noticed that in branch v0.7 a callback function has been added. This would be very useful for me in my wxPython application which needs to be able to produce single and looped async sounds.

I downloaded the zip file of the branch yesterday and did some experiments with a simple wxPython test app. Both the single and looped async sounds are working fine. However, when I exit the program I am seeing a number of different error messages on the command line and, occasionally, the application crashes. e.g.

richardt@Pavilion ~/.../wxpython4/sound/audio_player_0.7 $ python3 audioplayer_0.7_exp1.py 
Xlib: sequence lost (0x10e82 > 0xe83) in reply type 0x1c!

also:

richardt@Pavilion ~/.../wxpython4/sound/audio_player_0.7 $ python3 audioplayer_0.7_exp1.py 
double free or corruption (fasttop)
Aborted (core dumped)

Is there a fundamental problem in using audioplayer with wxPython, or is it just a case that the development of v0.7 is not yet complete?

I am using wxPython 4.0.1 and Python 3.6.9 on Linux Mint 19.3

audio_player_0.7.zip

Edit: I have just run the test program on a different PC which uses wxPython 4.0.7 and Python 3.8.2 on Linux Mint 20 and it works fine and I don't get any errors when the program exits.

It looks like the problem could due to the older wxPython/Python software on the first PC.

Edit 2: I spoke too soon. With more testing, I did get it to crash on the second PC, it just happens a lot less frequently than on the first PC.

reticulatus commented 4 years ago

After reading the following comment in audioplayer_linux.py

"If you don't plan on using GTK with the program, you will have to run a gobject.Mainloop() in order to get messages from the bus."

I reasoned that, as wxPython uses GTK on linux, I shouldn't run a gobject.Mainloop().

As a quick hack, I added the following 2 lines to the top of my demo program:

from audioplayer.audioplayer_linux import AudioPlayerLinux
AudioPlayerLinux._gloop_thread = 1

Since then I haven't seen any error messages, and the program hasn't crashed.

mjbrusso commented 4 years ago

Thank you for your feedback!

Getting this feature up and running in a cross-platform project has been an hard problem. Each OS and window manager has its own event system. I thought GObject.MainLoop().is_running() would detect the case that there is already a loop!

Let's try to find another way to automatically detect an existing event loop. In another case, we will have to create a class property or a new parameter in the constructor to configure it by hand.

Edit: I didn't do any test with wxPython.