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

1

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!

python-3.x
libvlc
python-vlc
asked on Stack Overflow May 9, 2020 by SevRyb

1 Answer

1

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
answered on Stack Overflow Jul 26, 2020 by Martin.G

User contributions licensed under CC BY-SA 3.0