3

I'm trying to write an little application that dynamically plays a single movie file repeatedly. I wrote it in Python, using these VLC-Python bindings

I would say that this wouldn't be so hard and even though the very sparse documentation I can get a movie fullscreen without anything else on the screen and even change the file I want to play. What I cannot is simply let a single movie repeat.

I use the following code:

self.media = []

A --repeat-tag here:

self.vlc_inst = vlc.Instance('--mouse-hide-timeout=0', '--fullscreen', '--repeat')

And a '--repeat' tag here:
self.media = self.vlc_inst.media_new(NEW_VIDEO_NAME + str(currentVideoN) + VIDEO_EXTENSION, '--repeat')

    self.player = self.vlc_inst.media_player_new()                  
    self.player.set_fullscreen(True)    
    self.player.set_media(self.media[currentVideoN])
    self.player.play()

These repeat tags don't seem to do anything. The Instance class does have a function vlm_set_loop(self, psz_name, b_loop) but I have no idea what mrl should be. In the original code I figured out it should be a char-array (String), but I have no clue what kind of String this should be.

Anyone who does have a clue?

Gilles
  • 343
  • 1
  • 4
  • 12

4 Answers4

5

well, this question is pretty old, but anyways... i think instead of using '--repeat' (which only works with a medialist rather than a single mediafile afaik) in your vlc.Instance you could use somthing like '--input-repeat=999999' it's not really a loop, but as close as it gets (again: afaik ;-) )

flo
  • 51
  • 1
  • 2
  • Or you can do : `vlc.Instance('--input-repeat=-1', '--no-video-title-show', '--fullscreen', '--mouse-hide-timeout=0')` –  Feb 12 '14 at 09:52
2

I was able to make the media replay by setting the media to it's current media and calling play. Is the code trash? Yes, it is: the back function may not be called inside the onEnd function, else i won't full fill by some reason. Does it work? Yes

import vlc


doTrashCode = False
player = vlc.MediaPlayer("C:/Users/benj5/Videos/2019-04-29 22-14-55_Trim.mp4")


def start():
    player.set_fullscreen(True)
    em = player.event_manager()
    em.event_attach(vlc.EventType.MediaPlayerEndReached, onEnd)
    player.play()


def onEnd(event):
    global doTrashCode
    if event.type == vlc.EventType.MediaPlayerEndReached:
        doTrashCode = True


def back():
    player.set_media(player.get_media())
    player.play()


start()

while True:
    if doTrashCode:
        back()
        doTrashCode = False
  • The code works for me (I'm using it on a RaspberryPi). Problem is that, this way, when the movie ends, just before restarting it from the beginning, I see the desktop as the background :( Is there a way to prevent this from happening? (I don't want to use, say, tkinter, opencv or pygame, just to print a fullscreen black image as a background under VLC) – orestino Oct 19 '22 at 11:45
1

Looking at the source code I found this works to be a working solution.

Once you define a media list, you add the media list to a media_list_player, to which you can set a playback mode on the player. In the documentation this is an enum.

class PlaybackMode(_Enum):
    '''Defines playback modes for playlist.
    '''
    _enum_names_ = {
        0: 'default',
        1: 'loop',
        2: 'repeat',
    }
PlaybackMode.default = PlaybackMode(0)
PlaybackMode.loop    = PlaybackMode(1)
PlaybackMode.repeat  = PlaybackMode(2)

All you need to do is set the mode in the list player:

listPlayer.set_playback_mode() to be listPlayer.set_playback_mode(vlc.PlaybackMode(1)) or listPlayer.set_playback_mode(vlc.PlaybackMode().loop)

import vlc
from pathlib import Path
import time
import os


class Player:

    def __init__(self):
        self.player = vlc.Instance()

    def addPlayList(self, localPath):
        self.mediaList = self.player.media_list_new()
        path = os.path.join(os.getcwd(), localPath)
        self.mediaList.add_media(path)
        self.listPlayer = self.player.media_list_player_new()
        self.listPlayer.set_media_list(self.mediaList)
        self.listPlayer.set_playback_mode(vlc.PlaybackMode(1))

    def play(self):
        self.listPlayer.play()

    def stop(self):
        self.listPlayer.stop()


play = Player()
play.addPlayList("test.mp4")
play.play()
while True:
    time.sleep(4)
0

you can use subprocess

p = subprocess.Popen('cvlc', 'fullscreen', 'home/pi/demo.mp4', '--loop')

I used VLC instead of CVLC earlier but it wasn't working fine for me, it was reloading and resizing the VLC player when the loop end