In this article we will see how we can get media object from the MediaList object in the python vlc module. VLC media player is a free and open-source portable cross-platform media player software and streaming media server developed by the VideoLAN project. MediaList object contains the multiple media, in other words it has list of media which can be used with MediaListPlayer object to play these multiple media object. We can add multiple video to the media list with the help of add_media method and single media object can be set with the help of set_media method.
In order to do this we will use
mediamethod with the MediaList objectSyntax : media_list.media()
Argument : It takes no argument
Return : It returns Media object
Below is the implementation
# importing vlc moduleimport vlc # importing time moduleimport time # creating a media player objectmedia_player = vlc.MediaListPlayer() # creating Instance class objectplayer = vlc.Instance() # creating a media list objectmedia_list = vlc.MediaList() # creating a new mediamedia = player.media_new("death_note.mkv") # setting media object to the media listmedia_list.set_media(media) # setting media list to the media playermedia_player.set_media_list(media_list) # start playing videomedia_player.play() # wait so the video can be played for 5 seconds# irrespective for length of videotime.sleep(5) # getting media object from the media listvalue = media_list.media() # printing valueprint(value) |
Output :
vlc.Media object at 0x000001FB38155A01
Another example
# importing vlc moduleimport vlc # importing time moduleimport time # creating a media player objectmedia_player = vlc.MediaListPlayer() # creating Instance class objectplayer = vlc.Instance() # creating a media list objectmedia_list = vlc.MediaList() # creating a new mediamedia = player.media_new("1.mp4") # setting media object to the media listmedia_list.set_media(media) # setting media list to the media playermedia_player.set_media_list(media_list) # start playing videomedia_player.play() # wait so the video can be played for 5 seconds# irrespective for length of videotime.sleep(5) # getting media object from the media listvalue = media_list.media() # printing valueprint(value) |
Output :
vlc.Media object at 0x000001FB38155808
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.


