streamer.py
import vlc # libVLC
import time
class Streamer():
def __init__(self):
self.Instance = vlc.Instance()
sout = "#transcode{acodec=mp3,ab=128,channels=2,samplerate=44100}:http{dst=:8090/streamer.mp3}"
self.media_files = ["file.mp3", "file2.mp3"]
self.Instance.vlm_add_broadcast("0", self.media_files[0], sout, 0, None, True, False)
self.Instance.vlm_add_broadcast("1", self.media_files[1], sout, 0, None, True, False)
self.Instance.vlm_play_media("0")
time.sleep(10)
self.Instance.vlm_stop_media("0")
self.Instance.vlm_play_media("1")
time.sleep(10)
rs = RasStreamer()
Player:
I am using Jplayer (demo-8) at the client end.
The problem:
As soon as I stop media "0" and play media "1" it stops my player and I have to press the play button again. Is there a way to switch media without stopping the player?
Preface: I'm no expert on streaming; everything I know I've learned from researching how to use libvlc.
In between stopping one media and starting the next one, the stream of data physically ends and begins again. As in, there will be a short period of time when nothing is being broadcast, so the player stops. Theoretically, you could append the new stream to the previous one, provided they have the same encoding and container format (as your two streams do). However, I don't think libvlc's bindings support this.
So I think your best bet would be to make a client that periodically tries to reconnect to the stream when the stream ends.