SevRyb
SevRyb

Reputation: 103

python-vlc doesn't play audio/video from .py file

I want to make mediaplayer, I choosed python-vlc library, but I don't know why I can't play audio/video from .py file. If I tried make it with cmd and Python Shell all working:

>>> import vlc
>>> my_player = vlc.MediaPlayer("d:/Music/song.flac")
>>> my_player.play()
0

I write same in .py file:

import vlc

my_player = vlc.MediaPlayer("d:/Music/song.flac")
my_player.play()

When I start it in cmd and PyCharm nothing happens and I don't receive any errors, but when I start debuging I receive this:

[04521730] mmdevice audio output error: cannot initialize COM (error 0x80010106)
[04545aa0] mmdevice audio output error: cannot initialize COM (error 0x80010106)

P.S. I use Python 3.8.0 (32 bit) and I have installed VLC player (32 bit) on Windows 10.

Thanks in advance!

Upvotes: 2

Views: 2530

Answers (1)

Balobiana
Balobiana

Reputation: 38

After some research, you need to add a infinite loop or the delay while you want your song on.

For example if you want 10s of music :

import vlc
import time

p = vlc.MediaPlayer(r"C:\Users\username\Downloads\test.mp3")
p.play()

time.sleep(10)

or

import vlc

p = vlc.MediaPlayer(r"C:\Users\username\Downloads\test.mp3")
p.play()

while True:
     pass

Upvotes: 1

Related Questions