OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Getting file path of current track from Python-VLC's MediaListPlayer

  • Thread starter Thread starter MillerTime
  • Start date Start date
M

MillerTime

Guest
I'm using MediaListPlayer from the python-vlc library. I use the following code to create a list of all the songs in a directory and begin them playing as a playlist, so that once one song ends another begins.

Code:
import os
from vlc import MediaListPlayer

class Music:
    def __init__(self, path):
        self.path = path
        self.get_playlist()
        self.play()
    
    def get_songs(self):
        self.pathlist = []
        for file in os.listdir(self.path):
            if file.endswith('.mp3'):
                self.pathlist.append(os.path.join(self.path, file))

    def get_playlist(self):
        self.player = MediaListPlayer()

        inst = self.player.get_instance()
        playlist = inst.media_list_new()
        
        self.get_songs()
        
        for path in self.pathlist:
            song = inst.media_new(path)
            playlist.add_media(song)

        self.player.set_media_list(playlist)

    def play(self):
        self.player.play()

Music('path/to/music')

This works perfectly, and plays one song after the next. What I'm looking for is a way to get the file path of the current track. Something along the lines of self.player.get_current_track(). I've scoured the documentation, found here, and there seems to be no way to do this. Does anybody have a solution?
<p>I'm using <code>MediaListPlayer</code> from the <code>python-vlc</code> library. I use the following code to create a list of all the songs in a directory and begin them playing as a playlist, so that once one song ends another begins.</p>
<pre><code>import os
from vlc import MediaListPlayer

class Music:
def __init__(self, path):
self.path = path
self.get_playlist()
self.play()

def get_songs(self):
self.pathlist = []
for file in os.listdir(self.path):
if file.endswith('.mp3'):
self.pathlist.append(os.path.join(self.path, file))

def get_playlist(self):
self.player = MediaListPlayer()

inst = self.player.get_instance()
playlist = inst.media_list_new()

self.get_songs()

for path in self.pathlist:
song = inst.media_new(path)
playlist.add_media(song)

self.player.set_media_list(playlist)

def play(self):
self.player.play()

Music('path/to/music')
</code></pre>
<p>This works perfectly, and plays one song after the next. What I'm looking for is a way to get the file path of the current track. Something along the lines of <code>self.player.get_current_track()</code>.
I've scoured the documentation, found <a href="https://www.olivieraubert.net/vlc/python-ctypes/doc/index.html" rel="nofollow noreferrer">here</a>, and there seems to be no way to do this. Does anybody have a solution?</p>
 

Latest posts

P
Replies
0
Views
1
Paras Chouhan
P
Top