Python VLC MediaList – Getting Index of given item
In this article we will see how we can get the index of given media object in 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. Multiple media can be added to the media list object with the help of add_media method, so each media is lying at their respective index in the list. We can get the media from index with the help of item_at_index method.
In order to do this we will use index_of_item method with the MediaList object Syntax : media_list.index_of_item(media) Argument : It takes media object as argument Return : It returns integer
Below is the implementation
Python3
import vlc
import time
media_player = vlc.MediaListPlayer()
player = vlc.Instance()
media_list = vlc.MediaList()
media1 = player.media_new("death_note.mkv")
media_list.add_media(media1)
media2 = player.media_new(" 1.mp4 ")
media_list.add_media(media2)
media_player.set_media_list(media_list)
media_player.play()
time.sleep( 5 )
value = media_list.index_of_item(media1)
print (value)
|
Output :
0
Another example
Python3
import vlc
import time
media_player = vlc.MediaListPlayer()
player = vlc.Instance()
media_list = vlc.MediaList()
media1 = player.media_new(" 1.mp4 ")
media_list.add_media(media1)
media2 = player.media_new("death_note.mkv")
media_list.add_media(media2)
media_player.set_media_list(media_list)
media_player.play()
time.sleep( 5 )
value = media_list.index_of_item(media2)
print (value)
|
Output :
1
Last Updated :
10 Apr, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...