Is using a singleton the answer?

94 Views Asked by At

I'm trying to create a snips app to play songs using Python 3 and the python-vlc library. I am able to play my songs, but unable to stop them. The action will not run again while the song is playing, but other actions will, so I'm looking to put the stop function in a seperate file. The problem with this, is it creates a second instance of vlc and does not stop the current song.

I'm wondering if creating a singleton of the vlc object would allow me to accomplish this.

Does anyone have any recommendations?

1

There are 1 best solutions below

0
On

In my opinion I think you can use Singleton for playing and pausing/stopping music.

It would make you able to control the only instance of the class that is initiated.

Especially if you only want to play small snippets of each song (kinda like SongPop I guess?), you'll be sure that no more than one instance of the class is initiated, and can be quite sure where and when it is used.