pythonvlcpython-vlc

Can't set_fullscreen for VLC MediaList in Python


I've got a VLC MediaList that is imported from a directory and randomized. I want to set it to fullscreen. I'm doing this on a Raspberry Pi 4 if that makes a difference.

from vlc import Instance
import time
import os
import random

#VLC setup
class VLC:
    def __init__(self):
        self.Player = Instance('--fullscreen')

    def addPlaylist(self):
        self.mediaList = self.Player.media_list_new()
        path = "/home/kitchentv/Videos"
        episodes = os.listdir(path)
        random.shuffle(episodes)
        for s in episodes:
            self.mediaList.add_media(self.Player.media_new(os.path.join(path,s)))
        self.listPlayer = self.Player.media_list_player_new()
        self.listPlayer.set_media_list(self.mediaList)
    def play(self):
        self.listPlayer.play()
    def next(self):
        self.listPlayer.next()
    def pause(self):
        self.listPlayer.pause()
    def previous(self):
        self.listPlayer.previous()
    def stop(self):
        self.listPlayer.stop()

player = VLC()
player.addPlaylist()
player.play()
player.set_fullscreen(True)

The --fullscreen tag on the Instance doesn't seem to do anything at all.

The final line where I set the player to fullscreen returns this error code

AttributeError: 'VLC' object has no attribute 'set_fullscreen'

As far as I can tell, the MediaList attribute doesn't accept set_fullscreen the way MediaPlayer does. Is there any other way to achieve fullscreen? Some have suggested setting it through libvlc, but I'm not sure how to do that in this context.


Solution

  • --fullscreen flag won't work here self.Player = Instance('--fullscreen') Because it would typically work if VLC was being used from the command line, but we need to set fullscreen programmatically when using it with python bindings.

    I also created a new media player instance as an attribute. In addPlaylist method, I set the MediaPlayer of the MediaListPlayer with self.listPlayer.set_media_player(self.mediaPlayer). And finally I set the MediaPlayer to fullscreen with self.mediaPlayer.set_fullscreen(True) inside the self.play method.

    You can try this code:

    from vlc import Instance
    import time
    import os
    import random
    
    class VLC:
        def __init__(self):
            self.Player = Instance()
            self.mediaPlayer = self.Player.media_player_new()
    
        def addPlaylist(self):
            self.mediaList = self.Player.media_list_new()
            path = "/home/kitchentv/Videos"
            episodes = os.listdir(path)
            random.shuffle(episodes)
            for s in episodes:
                self.mediaList.add_media(self.Player.media_new(os.path.join(path, s)))
            self.listPlayer = self.Player.media_list_player_new()
            self.listPlayer.set_media_list(self.mediaList)
            self.listPlayer.set_media_player(self.mediaPlayer)
    
        def play(self):
            self.listPlayer.play()
            self.mediaPlayer.set_fullscreen(True)
    
        def next(self):
            self.listPlayer.next()
    
        def pause(self):
            self.listPlayer.pause()
    
        def previous(self):
            self.listPlayer.previous()
    
        def stop(self):
            self.listPlayer.stop()
    
    player = VLC()
    player.addPlaylist()
    player.play()