Python VLC 运行 暂停两次不恢复播放?
Python VLC Running pause() twice does not resume playing?
import vlc,os,time,multiprocessing
from threading import Thread
def play_single(filePath):
item = Player(filePath)
Thread(target=item.startProcessing).start()
Thread(target=item.asyncInput).start()
class Player:
def __init__(self, file):
self.instance = vlc.Instance()
self.player = self.instance.media_player_new()
self.media = vlc.Media(file)
self.skip = False
def asyncInput(self):
while True:
command = input(">> ")
if command == "-skip" or command == "-quit":
self.skip = True
break
elif command == "-pause" or command == "-resume":
self.player.pause()
else:
print("else")
def startProcessing(self):
self.player.set_media(self.media)
self.player.play()
time.sleep(2)
while True:
if (self.player.is_playing() == 0):
self.player.stop()
break
if self.skip:
self.player.stop()
break
if __name__ == '__main__':
play_single("C:/Users/Satvik/Music/Dua Lipa - Levitating.mp3")
当我执行-pause
时它会暂停但是当我执行-resume
时它没有任何效果。请帮忙,我不明白为什么要这样做。以上是我的全部代码,其他一切正常。
因为暂停和恢复都执行'self.player.pause()'
改变这个
elif command == "-pause" or command == "-resume":
至
if command == "-pause":
self.player.pause()
elif command == "-resume":
self.player.play()
没有 'toggle play pause' 命令不同于静音,audio_toggle_mute
。
不过,您可以通过检查媒体播放器的状态自行实施。
def toggle_(self):
if self.player.is_playing():
self.player.pause()
else:
self.player.play()
import vlc,os,time,multiprocessing
from threading import Thread
def play_single(filePath):
item = Player(filePath)
Thread(target=item.startProcessing).start()
Thread(target=item.asyncInput).start()
class Player:
def __init__(self, file):
self.instance = vlc.Instance()
self.player = self.instance.media_player_new()
self.media = vlc.Media(file)
self.skip = False
def asyncInput(self):
while True:
command = input(">> ")
if command == "-skip" or command == "-quit":
self.skip = True
break
elif command == "-pause" or command == "-resume":
self.player.pause()
else:
print("else")
def startProcessing(self):
self.player.set_media(self.media)
self.player.play()
time.sleep(2)
while True:
if (self.player.is_playing() == 0):
self.player.stop()
break
if self.skip:
self.player.stop()
break
if __name__ == '__main__':
play_single("C:/Users/Satvik/Music/Dua Lipa - Levitating.mp3")
当我执行-pause
时它会暂停但是当我执行-resume
时它没有任何效果。请帮忙,我不明白为什么要这样做。以上是我的全部代码,其他一切正常。
因为暂停和恢复都执行'self.player.pause()'
改变这个
elif command == "-pause" or command == "-resume":
至
if command == "-pause":
self.player.pause()
elif command == "-resume":
self.player.play()
没有 'toggle play pause' 命令不同于静音,audio_toggle_mute
。
不过,您可以通过检查媒体播放器的状态自行实施。
def toggle_(self):
if self.player.is_playing():
self.player.pause()
else:
self.player.play()