This commit is contained in:
yumoqing 2022-08-17 10:40:51 +08:00
parent cf6bfc6369
commit 49cc58fca7

View File

@ -23,10 +23,10 @@ class AudioPlayer:
self.load() self.load()
def player_callback(self, selector, value): def player_callback(self, selector, value):
if self.player is None:
print('self.player is None')
return
print(f'player_callback(): {selector}, {value}') print(f'player_callback(): {selector}, {value}')
if self.player is None:
print(f'player_callback():self.player is None, {selector}, {value}')
return
if selector == 'quit': if selector == 'quit':
def close(*args): def close(*args):
self.quitted = True self.quitted = True
@ -47,14 +47,15 @@ class AudioPlayer:
loglevel='info', loglevel='info',
ff_opts=ff_opts) ff_opts=ff_opts)
player = self.player player = self.player
player.set_volume(self.volume)
player.toggle_pause()
self.state = 'pause' self.state = 'pause'
s = time.perf_counter() s = time.perf_counter()
while (player.get_metadata()['duration'] is None and while (player.get_metadata()['duration'] is None and
not self.quitted and not self.quitted and
time.perf_counter() - s < 10.): time.perf_counter() - s < 10.):
time.sleep(0.005) time.sleep(0.005)
player.toggle_pause()
time.sleep(0.04)
player.set_volume(self.volume)
if self.autoplay: if self.autoplay:
self.play() self.play()
@ -70,7 +71,7 @@ class AudioPlayer:
if self.player is None: if self.player is None:
self.load() self.load()
if self.player is None: if self.player is None:
print('self.player is None') print('play():self.player is None')
return return
if self.state == 'play': if self.state == 'play':
return return
@ -81,7 +82,7 @@ class AudioPlayer:
if self.player is None: if self.player is None:
self.load() self.load()
if self.player is None: if self.player is None:
print('self.player is None') print('pause():self.player is None')
return return
if self.state == 'pause': if self.state == 'pause':
return return
@ -105,7 +106,7 @@ class AudioPlayer:
def seek(self, pos): def seek(self, pos):
if self.player is None: if self.player is None:
print('self.player is None') print('seek():self.player is None')
return return
self.player.seek(pos, relative=False) self.player.seek(pos, relative=False)