Detach event after destroying player class
This commit is contained in:
parent
a4b73a963e
commit
b2539ba697
@ -3,7 +3,7 @@ import random
|
|||||||
import vlc
|
import vlc
|
||||||
import logging
|
import logging
|
||||||
from pubsub import pub
|
from pubsub import pub
|
||||||
from utils import RepeatingTimer
|
from utils import call_threaded
|
||||||
|
|
||||||
player = None
|
player = None
|
||||||
log = logging.getLogger("player")
|
log = logging.getLogger("player")
|
||||||
@ -25,10 +25,11 @@ class audioPlayer(object):
|
|||||||
self.shuffle = False
|
self.shuffle = False
|
||||||
self.instance = vlc.Instance()
|
self.instance = vlc.Instance()
|
||||||
self.player = self.instance.media_player_new()
|
self.player = self.instance.media_player_new()
|
||||||
|
self.event_manager = self.player.event_manager()
|
||||||
|
self.event_manager.event_attach(vlc.EventType.MediaPlayerEndReached, self.end_callback)
|
||||||
|
|
||||||
def play(self, item):
|
def play(self, item):
|
||||||
self.stopped = True
|
self.stopped = True
|
||||||
# Make sure there are no other sounds trying to be played.
|
|
||||||
if self.is_working == False:
|
if self.is_working == False:
|
||||||
self.is_working = True
|
self.is_working = True
|
||||||
if item.download_url == "":
|
if item.download_url == "":
|
||||||
@ -96,12 +97,10 @@ class audioPlayer(object):
|
|||||||
self.shuffle = shuffle
|
self.shuffle = shuffle
|
||||||
self.queue_pos = playing
|
self.queue_pos = playing
|
||||||
self.play(self.queue[self.queue_pos])
|
self.play(self.queue[self.queue_pos])
|
||||||
if not hasattr(self, "worker"):
|
|
||||||
self.worker = RepeatingTimer(5, self.player_function)
|
|
||||||
self.worker.start()
|
|
||||||
|
|
||||||
def player_function(self):
|
def end_callback(self, event, *args, **kwargs):
|
||||||
if self.player.is_playing() == 0 and self.stopped == False:
|
#https://github.com/ZeBobo5/Vlc.DotNet/issues/4
|
||||||
if len(self.queue) == 0:
|
call_threaded(self.next)
|
||||||
return
|
|
||||||
self.next()
|
def __del__(self):
|
||||||
|
self.event_manager.event_detach(vlc.EventType.MediaPlayerEndReached)
|
Loading…
x
Reference in New Issue
Block a user