-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybackStatusChecker.py
65 lines (57 loc) · 2 KB
/
playbackStatusChecker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# playback status checker
import constants
import globalVars
import logging
import player
from soundPlayer.constants import *
import threading
import time
import wx
interval = 1
deviceErrorMax = 10
deviceErrorCount = 0
STATUS_CONSTANTS = {
PLAYERSTATUS_STATUS_OK: "OK",
PLAYERSTATUS_STATUS_FAILD: "FAILD",
PLAYER_STATUS_PLAYING: "PLAYING",
PLAYER_STATUS_PAUSED: "PAUSED",
PLAYER_STATUS_STOPPED: "STOPPED",
PLAYER_STATUS_END: "END",
PLAYER_STATUS_LOADING: "LOADING",
PLAYER_STATUS_DEVICEERROR: "DEVICEERROR",
PLAYER_STATUS_OVERREWIND: "OVERREWIND",
}
class PlaybackStatusChecker(threading.Thread):
def __init__(self, player, onStop):
super().__init__(daemon=True)
self._player = player
self.onStop = onStop
self.log = logging.getLogger("%s.%s" % (constants.LOG_PREFIX, "playbackStatusChecker"))
self.running = True
def run(self):
time.sleep(1)
self.log.debug("started")
while self.running:
status = self._player.getPlayer().getStatus()
self.log.debug("status: %s" % STATUS_CONSTANTS[status])
if status == PLAYER_STATUS_DEVICEERROR:
global deviceErrorCount
deviceErrorCount += 1
self.log.debug("deviceErrorCount: %s" % deviceErrorCount)
if deviceErrorCount >= deviceErrorMax:
deviceErrorCount = 0
self.log.debug("Device error. Use default device.")
self._player.setDevice()
elif status == PLAYER_STATUS_END:
self.log.debug("restarting playback...")
self._player.reload()
elif status in (PLAYER_STATUS_PLAYING, PLAYER_STATUS_LOADING, PLAYER_STATUS_PAUSED):
pass
else:
self.log.debug("stopping")
wx.CallAfter(self.onStop)
break
time.sleep(interval)
def exit(self):
self.running = False
self.log.debug("exitting...")