help required with creating and playing a dynamic music video playlist with Python-vlc bindings

This forum is about all development around libVLC.
jason6565
New Cone
New Cone
Posts: 4
Joined: 11 Sep 2018 23:12

help required with creating and playing a dynamic music video playlist with Python-vlc bindings

Postby jason6565 » 30 Aug 2019 11:06

Hello all

I'm trying to create a simple music video player that creates an updated playlist from any MP4 files that are dropped into a specific folder (in this case a folder named 'Media')

The player then plays the videos that are listed on the playlist in a continuous loop.

I'm using a Windows 7 PC and Python 3.7

I've attached a working sample of my code, it does all of the above requirements, BUT it's not exactly seamless when switching to the next video.

I don't think I'm changing to the next video in the most efficient way. Is there a player.next_track() method or something equivalent?

Is it even possible to have a 'transition' between each video, something like a cross-fade?

Any help would be much appreciated

cheers - Jason

Code: Select all

import vlc import time import glob def createPlaylist(): folder = ("./Media") playlist = glob.glob(folder+"/*.mp4") if len(playlist) == 0: print("No recognisable MP4 files in ", folder) return playlist Instance = vlc.Instance('--input-repeat=999999', '--no-video-title-show', '--mouse-hide-timeout=5000') a = 0 playlist = createPlaylist() while True: if a == len(playlist): a = 0 playlist = createPlaylist() print("Media folder contains ", len(playlist), "MP4 files\n") player = Instance.media_player_new() player.set_fullscreen(True) MusicVideo = Instance.media_new(playlist[a]) player.set_media(MusicVideo) player.play() #get duration of movie file time.sleep(1.5) duration = player.get_length()/1000 dwell = duration -1.5 time.sleep(dwell) player.stop() a += 1

chubinou
Developer
Developer
Posts: 521
Joined: 23 Jul 2015 15:19

Re: help required with creating and playing a dynamic music video playlist with Python-vlc bindings

Postby chubinou » 04 Sep 2019 15:42

Hi,

you can look at MediaList/MediaListPlayer if you want :

https://www.olivieraubert.net/vlc/python-ctypes/doc/vlc.MediaList-class.html
https://www.olivieraubert.net/vlc/python-ctypes/doc/vlc.MediaListPlayer-class.html

If you wan to wait for the end of a media you should rather use the event manager

https://www.olivieraubert.net/vlc/python-ctypes/doc/vlc.EventManager-class.html
https://www.olivieraubert.net/vlc/python-ctypes/doc/vlc.EventType-class.html

VLC doesn't provide gapless playback (as vlc 3.0.x)

jason6565
New Cone
New Cone
Posts: 4
Joined: 11 Sep 2018 23:12

Re: help required with creating and playing a dynamic music video playlist with Python-vlc bindings

Postby jason6565 » 05 Sep 2019 09:55

Hi Chubinou

thank you for the reply. Since I made my post I did some searching on the forums for similar topics, and came to the same conclusion that you've just confirmed, that VLC is not capable of seamless gapless playback between tracks. This is a real shame, and somewhat surprising, because this is a key requirement of any media player that is being considered for deployment in a professional environment

seanlanders
New Cone
New Cone
Posts: 1
Joined: 18 Sep 2019 00:57

Re: help required with creating and playing a dynamic music video playlist with Python-vlc bindings

Postby seanlanders » 18 Sep 2019 01:10

Hi,

I ran into the same problem in our installation. This is the work-around we wound up putting into practice. I hope this is helpful.

First, we made sure that our playlist began and ended with a single solid color (a fade out of and into black), then executed the following steps:

1) remove all identifying information from the desktop --

coloring the background the same single solid color I used in the videos,
removing icons from the desktop,
setting the toolbar to hide when idle, et cetera --

so that in an idle state, it seems to present a simple black screen. (This was on an RPi -- not sure how workable this is in Windows 7, but shouldn't be impossible, I think it has similar functionality.)

2) produce a delay between execution of the script and the beginning of playback sufficient to let you minimize the terminal window to preserve the illusion a clean desktop presents

in my case, that was binding the initialization of the script to an input from a button on the GPIO, but it could be simply a delay long enough to let you execute point 2, adding a time.sleep(15) to the beginning of your while loop if a==0 should give you sufficient time

2) hide the terminal window before the script initializes

When the playlist loops, the momentary gap is disguised, and shouldn't necessarily be visible to the casual observer.
We can get away with it, because we have a relatively long loop and don't anticipate viewers focusing on it at the moment of the loop.
The solution is more about stage magic than programming...
Not an ideal solution, but one that has proved sufficient for our circumstance.
YMMV. Hope it helps!

jason6565
New Cone
New Cone
Posts: 4
Joined: 11 Sep 2018 23:12

Re: help required with creating and playing a dynamic music video playlist with Python-vlc bindings

Postby jason6565 » 18 Sep 2019 09:00

Hi Sean

Thank you very much for your reply. I did develop a similar work-around by setting the desktop colour to a basic black background. I then prevented any desktop icons / taskbar etc showing by killing explorer.exe. I launch the python script with a simple windows batch file which includes the line:
Taskkill /IM explorer.exe /F

As you said, it's still not a perfect solution, but it just about does the job, even for my application which is playing video clips of short duration (10 to 30 seconds)

thanks again - Jason


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 24 guests