Cookbook Example
How can I...?
Example 12 : Simple TCP based streamer that repeatedly streams (3 times) the same audio file. The reason it's the same file is because it's configured with a playlist that is created: [ shortfile, shortfile, shortfile ]. If this was [ song_one, song_two, song_three ], then this would be a simple streamer that had a playlist of 3 songs played repeatedly. Something that does this is often referred to as a carousel. Components used: SimpleServer, JoinChooserToCarousel, FixedRateControlledReusableFileReader, ForwardIteratingChooser, pipeline
#!/usr/bin/pythonSource: Examples/example12/SimpleMultiFileStreamer.py
from Kamaelia.Chassis.ConnectedServer import SimpleServer
from Kamaelia.Chassis.Prefab import JoinChooserToCarousel
from Kamaelia.File.Reading import FixedRateControlledReusableFileReader
from Kamaelia.Util.PipelineComponent import pipeline
from Kamaelia.Util.Graphline import Graphline
from Kamaelia.Util.Chooser import ForwardIteratingChooser
shortfile = "/opt/kde3/share/sounds/KDE_Startup_2.ogg"
FILES_TO_STREAM = [ shortfile, shortfile, shortfile ]# [ file_to_stream, file_to_stream2 ]
BITRATE = 800000 # 38000
CHUNKSIZEBYTES = 512
SERVERPORT = 1500
def MultiFileReaderProtocol(filenames, bitrate, chunksizebytes):
def protocolFactory(*argv, **argd):
return JoinChooserToCarousel(
ForwardIteratingChooser(filenames),
FixedRateControlledReusableFileReader(readmode="bytes",
rate=bitrate/8,
chunksize=chunksizebytes)
)
return protocolFactory
if __name__ == '__main__':
filereader = MultiFileReaderProtocol( FILES_TO_STREAM, BITRATE, CHUNKSIZEBYTES)
server = SimpleServer( protocol = filereader, port = SERVERPORT ).run()
(C) 2006 Kamaelia Contributors, including the British Broadcasting Corporation, All Rights Reserved, This is an ongoing community based development site. As a result the contents of this page is the opinions of the contributors of the pages involved not the organisations involved. Specificially, this page may contain personal views which are not the views of the BBC.