Search code examples
pythonvlc

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")

When i execute -pause it pauses but when I execute -resume it does not have any effect. Please help I can't figure out why it is doing that. This above is my whole code every other thing works fine.


Solution

  • Because you execute 'self.player.pause()' for both pause and resume

    change this

    elif command == "-pause" or command == "-resume":
    

    to

    if command == "-pause":
                    self.player.pause()
    elif command == "-resume":
                    self.player.play()