Page 1 of 1
How to play an Audio CD / DVD with VLC Python Bindings
Posted: 15 Dec 2016 02:21
by Undefinedmaniac
Hello, I am currently working on a media player program using python 3.5, pyqt4, and the VLC python bindings. Although I have figured out how to play mp3s and other media files, I would like to be able to play from audio CDs and DVDs as well. The only example code I have seen is in C++ and I am having trouble converting to python. Any help would be much appreciated (example code for audio CD and DVD playback would be amazing).
Code for playing audio files:
Code: Select all
import vlc
instance = vlc.Instance()
player = instance.media_player_new()
media = instance.media_new('path/to/mp3')
player.set_media(media)
player.play()
Re: How to play an Audio CD / DVD with VLC Python Bindings
Posted: 21 Dec 2016 12:25
by kodela
Try it with this code:
Code: Select all
import vlc
def setup_player(name):
vlc_instance = vlc.Instance()
player = vlc_instance.media_player_new()
media = vlc_instance.media_new(name)
player.set_media(media)
player.play()
setup_player('dvd:///O:/') # for no disc menu: 'dvdsimple:///O:/' for audio cd: 'cdda:///O:/' - "O:/" is the optical drive
while True:
pass
Re: How to play an Audio CD / DVD with VLC Python Bindings
Posted: 24 Dec 2016 00:34
by Undefinedmaniac
Thanks for the reply, the code for the DVD works flawlessly. However, when I try to play a CD with "cdda:///H:/" as my source (H is my CD reader on windows) I get the error "[00000240056f01f0] core stream error: cannot pre fill buffer".
Re: How to play an Audio CD / DVD with VLC Python Bindings
Posted: 26 Dec 2016 09:16
by kodela
How does your code look and is the DVD played?
Re: How to play an Audio CD / DVD with VLC Python Bindings
Posted: 26 Dec 2016 19:11
by Undefinedmaniac
I used your code from above, but replaced the optical drive "O:/" with my drive "H:/".
Code: Select all
import vlc
def setup_player(name):
vlc_instance = vlc.Instance()
player = vlc_instance.media_player_new()
media = vlc_instance.media_new(name)
player.set_media(media)
player.play()
setup_player('dvd:///H:/') # for no disc menu: 'dvdsimple:///O:/' for audio cd: 'cdda:///O:/' - "O:/" is the optical drive
while True:
pass
This plays a DVD properly and both audio and video output is given, and you can even navigate the DVD menus in the video output.
Using this same code and changing the media source for a CD gives the error "[00000240056f01f0] core stream error: cannot pre fill buffer" and the CD does not play.
Code: Select all
import vlc
def setup_player(name):
vlc_instance = vlc.Instance()
player = vlc_instance.media_player_new()
media = vlc_instance.media_new(name)
player.set_media(media)
player.play()
setup_player('cdda:///H:/') # for no disc menu: 'dvdsimple:///O:/' for audio cd: 'cdda:///O:/' - "O:/" is the optical drive
while True:
pass
Re: How to play an Audio CD / DVD with VLC Python Bindings
Posted: 27 Dec 2016 13:26
by kodela
Hi and sorry!
for audio cd: 'cdda:///O:/'
that is not right!
Correct would be "
for audio cd: 'cddb:///O:/' "
But that is not yet the solution to the problem. You probably still have to integrate another module (CDDB.py).
See here:
https://sourceforge.net/projects/cddb-py/
and here:
http://cddb-py.sourceforge.net/
Re: How to play an Audio CD / DVD with VLC Python Bindings
Posted: 27 Dec 2016 23:12
by Undefinedmaniac
Thanks again for the help, the CDDB module appears to be for python 2.0 and I am currently using python 3.5. I attempted to install the module regardless of the version mismatch however python 3.5 refused to run the files giving several errors. I also tried using the python 2to3 conversion tool to make the code python 3.5 compatible, but no success. Is there any way to have this work on python 3.5 or will I need to downgrade to python 2.0 or find a different way to play audio CDs?
Re: How to play an Audio CD / DVD with VLC Python Bindings
Posted: 27 Dec 2016 23:48
by kodela
Currently, I see no way to play with Python and the VLC audio CDs. But I'm looking.
Re: How to play an Audio CD / DVD with VLC Python Bindings
Posted: 28 Dec 2016 11:19
by kodela
My first answer with "for audio cd: 'cdda:///O:/'" was right. The call with "cddb: ///O:/" is only for the retrieval of metadata.
There remains the problem with the error: "can not pre fill buffer". I keep searching.
Re: How to play an Audio CD / DVD with VLC Python Bindings
Posted: 28 Dec 2016 22:53
by kodela
@Undefinedmaniac:
With this code you can play a single Track:
Code: Select all
import vlc
Player = vlc.MediaPlayer("cdda:///O:/", ":cdda-track=3")
Player.play()
while True:
pass
With this code you can play a Audio-CD:
Code: Select all
import vlc
def setup_player():
instance = vlc.Instance()
player = instance.media_player_new()
medialist = instance.media_list_new()
listplayer = instance.media_list_player_new()
listplayer.set_media_player(player)
for i in (range(1,10)): # the second value for range() can be set without problem also higher
track = instance.media_new("cdda:///O:/", (":cdda-track=" + str(i)))
medialist.add_media(track)
listplayer.set_media_list(medialist)
listplayer.play()
setup_player()
while True:
pass
Re: How to play an Audio CD / DVD with VLC Python Bindings
Posted: 28 Dec 2016 23:49
by Jean-Baptiste Kempf
Did you try cdda://O:\ ?
Re: How to play an Audio CD / DVD with VLC Python Bindings
Posted: 29 Dec 2016 08:43
by kodela
Yes, I've tried it with "cdda:///O:\\" ("cdda:///O:\" isn't possible).
Even then I get the error "core stream error: cannot pre fill buffer"
With "cdda://O:\\" I get the error "core input error: open of `cdda://O:\' failed"
Re: How to play an Audio CD / DVD with VLC Python Bindings
Posted: 31 Dec 2016 17:35
by Undefinedmaniac
@Undefinedmaniac:
With this code you can play a single Track:
Code: Select all
import vlc
Player = vlc.MediaPlayer("cdda:///O:/", ":cdda-track=3")
Player.play()
while True:
pass
With this code you can play a Audio-CD:
Code: Select all
import vlc
def setup_player():
instance = vlc.Instance()
player = instance.media_player_new()
medialist = instance.media_list_new()
listplayer = instance.media_list_player_new()
listplayer.set_media_player(player)
for i in (range(1,10)): # the second value for range() can be set without problem also higher
track = instance.media_new("cdda:///O:/", (":cdda-track=" + str(i)))
medialist.add_media(track)
listplayer.set_media_list(medialist)
listplayer.play()
setup_player()
while True:
pass
This is perfect, although I still had to change "O" to "H" before the CD's would play. Thank you very much for the help!
Re: How to play an Audio CD / DVD with VLC Python Bindings
Posted: 01 Jan 2017 18:36
by kodela
Hi,
Me optical drive has the letter "D:". This, of course, must be adapted to his situation.
If the second parameter for "range ()" is greater than the number of tracks on a CD, there will be an error event at the end. This is not a problem.