I found this problem really interesting, so I downloaded the vlc
python module and tinkered with it, and I think I found a solution for you.
What I did is I built an array containing the VLC instances, I built a function that creates VLC instances, and a loop that makes sure they're running (and produces verbose output).
This does require you make sure that your VLC player allows multiple window instances.
My code:
import vlc
import time
VLCObjects = []
def VLCInstance(src, volume):
# creating vlc media player object
try:
vlc_instance = vlc.Instance()
player = vlc_instance.media_player_new()
media = vlc_instance.media_new(src)
player.set_media(media)
except:
return("Error: Was unable to mount media")
else:
pass
VLCObjects.append(player)
VLCObjects[0].audio_set_volume(volume)
VLCObjects[0].play()
# give time to initialize, then get length of audio & wait until done playing
time.sleep(1)
duration = VLCObjects[0].get_length()
#time.sleep(duration)
return("Success: Song playing")
Then you'd make all your calls or whatever here, and then the loop:
song1 = ...
song2 = ...
VLCInstance(song1, 100)
VLCInstance(song2, 20)
while(True):
playing = False
time.sleep(1)
print(VLCObjects)
for x in range(0, len(VLCObjects) ):
value = VLCObjects[x].is_playing()
if value == True:
print("... VLCObject #%d is playing" % x)
playing = True
else:
print("... VLCObject #%d needed to be restarted" % x)
VLCObjects[x].play()
if playing == False:
break
The resulting output will look something like this, and there will be two non-windowed VLC players.
Success: Song playing
Success: Song playing
[<vlc.MediaPlayer object at 0x7fa56d271520>, <vlc.MediaPlayer object at 0x7fa56d271cd0>]
... VLCObject #0 is playing
0
0
[<vlc.MediaPlayer object at 0x7fa56d271520>, <vlc.MediaPlayer object at 0x7fa56d271cd0>]
... VLCObject #0 is playing
... VLCObject #1 is playing
[<vlc.MediaPlayer object at 0x7fa56d271520>, <vlc.MediaPlayer object at 0x7fa56d271cd0>]
... VLCObject #0 is playing
... VLCObject #1 is playing
[<vlc.MediaPlayer object at 0x7fa56d271520>, <vlc.MediaPlayer object at 0x7fa56d271cd0>]
... VLCObject #0 is playing
... VLCObject #1 is playing
[<vlc.MediaPlayer object at 0x7fa56d271520>, <vlc.MediaPlayer object at 0x7fa56d271cd0>]
... VLCObject #0 is playing
... VLCObject #1 is playing
[<vlc.MediaPlayer object at 0x7fa56d271520>, <vlc.MediaPlayer object at 0x7fa56d271cd0>]
... VLCObject #0 is playing
... VLCObject #1 is playing
[<vlc.MediaPlayer object at 0x7fa56d271520>, <vlc.MediaPlayer object at 0x7fa56d271cd0>]
... VLCObject #0 is playing
... VLCObject #1 is playing
[<vlc.MediaPlayer object at 0x7fa56d271520>, <vlc.MediaPlayer object at 0x7fa56d271cd0>]
... VLCObject #0 is playing
... VLCObject #1 is playing
[<vlc.MediaPlayer object at 0x7fa56d271520>, <vlc.MediaPlayer object at 0x7fa56d271cd0>]
... VLCObject #0 is playing
... VLCObject #1 is playing
[<vlc.MediaPlayer object at 0x7fa56d271520>, <vlc.MediaPlayer object at 0x7fa56d271cd0>]
... VLCObject #0 is playing
... VLCObject #1 is playing
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…