I am happy and successful with my internet radio based on vlc and now struggling with the music cdrom part.
I can select and play any audio track with the MediaPlayer. I can also create and play the whole audio cd with a playlist.
But I am still unable to select and play an item of the created playlist.
root = Tk() and root.mainloop() are only embedded, of course, I deleted all of the developed GUI elements to simplify the presentation.
I created three simple examples to make my problem clear.
Example 1 works fine for every selected track.
Example 2 works also fine for the playlist as a whole.
Example 3 shows my problem. Even after reading the documented vlc Binding for Python I still stuck.
I simply do not understand what parameter(s) I have to use.
Neither for
Code: Select all
'play_item_at_index'
Code: Select all
'play_item'
Maybe an expert here can give me a hint of the meaning of the error message.
And hopefully, someone can give me useful advice on how to handle these commands.
Or tell me a better way to manage the playlist.
Code: Select all
import vlc
import platform
from tkinter import *
root = Tk()
# define parameters depending on OS
if platform.system() == 'Windows':
instance = vlc.Instance('--quiet')
cd_lw = 'cdda:///E:/'
else:
instance = vlc.Instance('--quiet', '--aout=alsa')
cd_lw = 'cdda:///dev/sr0/'
mrl = ':cdda-track='
# Example 1
# player settings
player = instance.media_player_new()
player.set_mrl(cd_lw, mrl + str(4))
# this works fine, track nr. 4 is played
# player.play()
# Example 2
# creating a playlist with all the audio tracks on the audio cd
# listplayer settings
listplayer = instance.media_list_player_new()
# media list setings
playlist = instance.media_list_new()
tracks = instance.media_new(cd_lw)
# adds all tracks of the audio cd to the playlist
playlist.add_media(tracks)
listplayer.set_media_list(playlist)
# this works also fine, all tracks are played and then the program ended
# listplayer.play()
# Example 3
# here starts my problem. I did not find a way to tell
# vlc playing a selected song from the previous created playlist
'''
info from http://www.olivieraubert.net/vlc/python-ctypes/doc/
3242 - def play_item_at_index(self, i_index):
3243 Play media list item at position index.
3244 @param i_index: index in media list to play.
3245 @return: 0 upon success -1 if the item wasn't found.
3246
3247 return libvlc_media_list_player_play_item_at_index(self, i_index)
...
3257 - def play_item(self, p_md):
3258 Play the given media item.
3259 @param p_md: the media instance.
3260 @return: 0 upon success, -1 if the media is not part of the media list.
3261
3262 return libvlc_media_list_player_play_item(self, p_md)
'''
# this works with index=0 and plays the playlist
# but with no other index
# listplayer.play_item_at_index(0)
# this does not work at all
listplayer.play_item(4)
'''
And give this error message
Traceback (most recent call last):
File "D:/Python-Programme/gui-beispiel/CD-Project/question2.py", line 62, in <module>
listplayer.play_item(4)
File "D:\Python-Programme\gui-beispiel\venv\lib\site-packages\vlc.py", line 3262, in play_item
return libvlc_media_list_player_play_item(self, p_md)
File "D:\Python-Programme\gui-beispiel\venv\lib\site-packages\vlc.py", line 8362, in libvlc_media_list_player_play_item
return f(p_mlp, p_md)
ctypes.ArgumentError: argument 2: <class 'AttributeError'>: 'int' object has no attribute '_as_parameter_'
'''
root.mainloop()