Automatically restart a stream file after application restart

This is a small blurb of code that demonstrates how you might leverage the Mediacaster API to restart streams after an application restart.  You can add these to startup streams but upon the event where only the application is restarted, the startup streams do not reload.

You can start (again) the startup streams but this may not be necessary if only one application is restarted:

IVHost vhost = VHostSingleton.getInstance(IVHost.VHOST_DEFAULT);

As mentioned above this could be problematic.  So another approach would be to just check a specific file or files and see if they are already being utilized by the Mediacaster. You could place this check in a thread that checks every x seconds:


// configuration
String vhostName = IVHost.VHOST_DEFAULT;
String appName = "live";
String appInstanceName = "_definst_";
String streamName = "";
String mediaCasterType = "rtp";

IVHost vhost = VHostSingleton.getInstance(vhostName);
IApplication application = vhost.getApplication(appName);
IApplicationInstance appInstance = application.getAppInstance(appInstanceName);
	appInstance.startMediaCasterStream(streamName, mediaCasterType);

Note this is a simple example (no validation checking etc) to illustrate how we’d verify if a stream is already being ingested by the Mediacaster subsystem.

You can add this as a server listener as follows:


The complete source is attached here.

Comments are closed.