10

Ok here go .Im trying to play a video located online.I got the url ,which is the following: http://fsi.stanford.edu/sites/default/files/video_4.mp4 Its not something i will use in my application but Its just a sample file . Reading the examples for the python-vlc module i wrote the following code:

import vlc

Instance = vlc.Instance('--fullscreen')
player = Instance.media_player_new()
Media = Instance.media_new('http://fsi.stanford.edu/sites/default/files/video_4.mp4')
Media.get_mrl()
player.set_media(Media)
player.play()

In general I use anaconda and jupyter to write code .In the jupyter enviroment the code above executes corectly except the fullscreen parameter(which is still not what i need).So i tried running my code on a command window expecting the vlc player to start to fullscreen mode.Instead the code returned 0 as expected but the player never started.Im using windows 10 and vlc 2.2.4 . Can you please explain or at least help me understand why is this happening ?

2 Answers2

16

I prefer:

from time import sleep

sleep(5) # Or however long you expect it to take to open vlc
while player.is_playing():
     sleep(1)

This way, we can return once video is done playing.

PC Planet
  • 161
  • 1
  • 2
9

Ok I solved it on my own.I just had to put an infinite loop in the end,so the player has enough time to run:

while True:
     pass
  • why is this even accepted as the correct answer when there is an answer that breaks an infinite loop exists. https://stackoverflow.com/a/57583062/5153955 – Tendai May 13 '20 at 16:12
  • That is a legitimate question. Although little bit late... Because in the application I used this I wanted the player to be constantly open. – Θοδωρής Φλώκος May 15 '20 at 08:50
  • It works, maybe it is not the best solution but now I got an idea where the problem came from! Thank you! – Alex M.M. Jun 12 '20 at 07:33