Open In App

Python VLC MediaList – Getting Media object from it

Last Updated : 29 Aug, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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 media method with the MediaList object

Syntax : media_list.media()

Argument : It takes no argument

Return : It returns Media object

Below is the implementation




# importing vlc module
import vlc
  
# importing time module
import time
  
# creating a media player object
media_player = vlc.MediaListPlayer()
  
# creating Instance class object
player = vlc.Instance()
  
# creating a media list object
media_list = vlc.MediaList()
  
# creating a new media
media = player.media_new("death_note.mkv")
  
# setting media object to the media list
media_list.set_media(media)
  
# setting media list to the media player
media_player.set_media_list(media_list)
  
  
# start playing video
media_player.play()
  
# wait so the video can be played for 5 seconds
# irrespective for length of video
time.sleep(5)
  
# getting media object from the media list
value = media_list.media()
  
# printing value
print(value)


Output :

vlc.Media object at 0x000001FB38155A01

Another example




# importing vlc module
import vlc
  
# importing time module
import time
  
# creating a media player object
media_player = vlc.MediaListPlayer()
  
# creating Instance class object
player = vlc.Instance()
  
# creating a media list object
media_list = vlc.MediaList()
  
# creating a new media
media = player.media_new("1.mp4")
  
# setting media object to the media list
media_list.set_media(media)
  
# setting media list to the media player
media_player.set_media_list(media_list)
  
  
# start playing video
media_player.play()
  
# wait so the video can be played for 5 seconds
# irrespective for length of video
time.sleep(5)
  
# getting media object from the media list
value = media_list.media()
  
# printing value
print(value)


Output :

vlc.Media object at 0x000001FB38155808


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads