Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python-vlc won't start the player

Tags:

python-2.7

vlc

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 ?

like image 763
Θοδωρής Φλώκος Avatar asked Apr 07 '17 07:04

Θοδωρής Φλώκος


People also ask

Why is my VLC video not playing?

Check the File Format VLC media player is compatible with a lot of video formats, but not all of them. If you try to play an unsupported video format on VLC, it will throw a black screen or an error message. You can visit VLC's official features webpage to learn about the different file formats it supports.

How do I install a Python module in VLC?

In order to install the VLC module in Python, we will use the pip installer following the command shown below: Syntax: $ pip install python-vlc.

Why does VLC stop working?

The VLC Player could have been corrupted as well. Your system might not have enough free space to run an HD video. The drivers installed on your computer might be corrupt or outdated. There could be an issue with VLC's coding, output scheme, or any other playback setting.

Why is my VLC only playing the video but not the audio?

Click on "Tools-Preferences" in VLC. On the "Simple Preferences" interface, navigate to "Audio Settings". Make sure the "Enable audio" box is checked and then choose "DirectX audio output" at Output dropdown list. Actually, if this does not work, you can try all the choices one by one in "Output module" and "Device".


2 Answers

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.

like image 68
PC Planet Avatar answered Oct 07 '22 12:10

PC Planet


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
like image 41
Θοδωρής Φλώκος Avatar answered Oct 07 '22 11:10

Θοδωρής Φλώκος