Run Videos with parameters

Asked

Viewed 95 times

1

Staff I’m having difficulties in creating a relatively simple script.

I have some files . mp4 and wanted to try to run them in order (with loop) and on Full Screen

I have that code:

class Video(object):
    def __init__(self,path):
        self.path = path

    def play(self):
        from os import startfile
        startfile(self.path)

class Movie_MP4(Video):
    type = "MP4"

movie = Movie_MP4(r"C:\\Users\\Empathy.co\\Desktop\\Bot\\Olhos_Animado.mp4")

movie = Movie_MP4(r"C:\\Users\\Empathy.co\\Desktop\\Bot\\Olhos_Animado_Parte01.mp4")



movie.play()

He runs only the last video and I have no idea how to leave it in full screen and loop (I tried to use While True but apparently he does not recognize that the process has already been opened and keeps opening)

  • See documentation: "startfile() Returns as soon as the Associated application is launched. There is no option to Wait for the application to close, and no way to Retrieve the application’s Exit status."

1 answer

1

Will call her os.startfile has exactly the same effect as you clicking the file through the graphical interface. That is: the operating system will open the associated program first with that type of file - and, depedne the program whether it will play the video or not.

But os.startfile does not let you choose any option, nor even lets you choose which program you will use.

What you will need in this case is to know which program you want to call to play the movies, (for example: "vlc player"), and to study in the documentation of this program which parameters you can pass on the command line to activate the desired options (full screen, etc...) - and then call the program, with the options and the path to the file using the module options subprocess.

For example:

 subprocess.run(["mplayer", "-fs", movie])

If the video player is mplayer. This will pass the "-Fs" option to him and the video path. When the video is completed, mplayer ends and your program continues on the next line.

Which brings us to another part of your question: only one video plays because you are using twice the same variable - when you create the second variable movie containing an object of its class Movie_MP4, the first is "forgotten", and ceases to exist.

And finally, you’re making a mess of the paths to the files. or you use the prefix r" for the strings, or duplicate the " ", typing each one as " ". Do both, it even works, but it’s really ugly.

The same ideal would be to create file paths as instances of pathlib.Path - and use the "/" that is universally used outside of Windows to separate files and directories. At the point where you pass the file path to the subprocess.run you use str(nome_do_arquivo) to convert Path to string.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.