How to play an Audio CD / DVD with VLC Python Bindings

This forum is about all development around libVLC.
Undefinedmaniac
New Cone
New Cone
Posts: 5
Joined: 12 Nov 2016 22:12

How to play an Audio CD / DVD with VLC Python Bindings

Postby Undefinedmaniac » 15 Dec 2016 02:21

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()

kodela
Big Cone-huna
Big Cone-huna
Posts: 632
Joined: 25 Sep 2012 19:40
VLC version: 2.2.4
Operating System: Windows 10
Location: Germany

Re: How to play an Audio CD / DVD with VLC Python Bindings

Postby kodela » 21 Dec 2016 12:25

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

Undefinedmaniac
New Cone
New Cone
Posts: 5
Joined: 12 Nov 2016 22:12

Re: How to play an Audio CD / DVD with VLC Python Bindings

Postby Undefinedmaniac » 24 Dec 2016 00:34

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".

kodela
Big Cone-huna
Big Cone-huna
Posts: 632
Joined: 25 Sep 2012 19:40
VLC version: 2.2.4
Operating System: Windows 10
Location: Germany

Re: How to play an Audio CD / DVD with VLC Python Bindings

Postby kodela » 26 Dec 2016 09:16

How does your code look and is the DVD played?

Undefinedmaniac
New Cone
New Cone
Posts: 5
Joined: 12 Nov 2016 22:12

Re: How to play an Audio CD / DVD with VLC Python Bindings

Postby Undefinedmaniac » 26 Dec 2016 19:11

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

kodela
Big Cone-huna
Big Cone-huna
Posts: 632
Joined: 25 Sep 2012 19:40
VLC version: 2.2.4
Operating System: Windows 10
Location: Germany

Re: How to play an Audio CD / DVD with VLC Python Bindings

Postby kodela » 27 Dec 2016 13:26

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/

Undefinedmaniac
New Cone
New Cone
Posts: 5
Joined: 12 Nov 2016 22:12

Re: How to play an Audio CD / DVD with VLC Python Bindings

Postby Undefinedmaniac » 27 Dec 2016 23:12

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?

kodela
Big Cone-huna
Big Cone-huna
Posts: 632
Joined: 25 Sep 2012 19:40
VLC version: 2.2.4
Operating System: Windows 10
Location: Germany

Re: How to play an Audio CD / DVD with VLC Python Bindings

Postby kodela » 27 Dec 2016 23:48

Currently, I see no way to play with Python and the VLC audio CDs. But I'm looking.

kodela
Big Cone-huna
Big Cone-huna
Posts: 632
Joined: 25 Sep 2012 19:40
VLC version: 2.2.4
Operating System: Windows 10
Location: Germany

Re: How to play an Audio CD / DVD with VLC Python Bindings

Postby kodela » 28 Dec 2016 11:19

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.

kodela
Big Cone-huna
Big Cone-huna
Posts: 632
Joined: 25 Sep 2012 19:40
VLC version: 2.2.4
Operating System: Windows 10
Location: Germany

Re: How to play an Audio CD / DVD with VLC Python Bindings

Postby kodela » 28 Dec 2016 22:53

@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

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: How to play an Audio CD / DVD with VLC Python Bindings

Postby Jean-Baptiste Kempf » 28 Dec 2016 23:49

Did you try cdda://O:\ ?
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

kodela
Big Cone-huna
Big Cone-huna
Posts: 632
Joined: 25 Sep 2012 19:40
VLC version: 2.2.4
Operating System: Windows 10
Location: Germany

Re: How to play an Audio CD / DVD with VLC Python Bindings

Postby kodela » 29 Dec 2016 08:43

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"

Undefinedmaniac
New Cone
New Cone
Posts: 5
Joined: 12 Nov 2016 22:12

Re: How to play an Audio CD / DVD with VLC Python Bindings

Postby Undefinedmaniac » 31 Dec 2016 17:35

@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!

kodela
Big Cone-huna
Big Cone-huna
Posts: 632
Joined: 25 Sep 2012 19:40
VLC version: 2.2.4
Operating System: Windows 10
Location: Germany

Re: How to play an Audio CD / DVD with VLC Python Bindings

Postby kodela » 01 Jan 2017 18:36

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.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 10 guests