Add a Media Cache source with the Wowza Streaming Engine Java API

The following code example illustrates how to add a MediaCacheSource on the fly using the Wowza Streaming Engine™ Java API.

Notes:
  • This code example isn't a complete solution.
  • The new MediaCacheSource isn't added to [install-dir]/conf/MediaCache.xml automatically. You'll need to do this as well so the MediaCacheSource is available the next time the media server is started.
import com.wowza.wms.mediacache.impl.*;
import com.wowza.wms.mediacache.model.*;
import com.wowza.wms.application.*;

public class ModuleAddMediaCacheSource
{
	public void addMediaCacheSource()
	{
		MediaCache mediaCache = MediaCacheImpl.getMediaCache();

		if (mediaCache != null)
		{
			String sourceName = "newSource";

			MediaCacheSourceBasic source = new MediaCacheSourceBasic();

			source.setName(sourceName);
			source.setPrefix("http/");
			source.setSourcePath("http://media.example.com/");
			source.setBaseClass("com.wowza.wms.plugin.mediacache.impl.MediaCacheItemHTTPImpl");
			source.setDefaultBlockSize(256*1024);
			source.setMaxTimeToLive(1200000);
			source.setMinTimeToLive(600000);
			source.setReadAhead(true);
			source.setReadAheadThreshold(50);

			WMSProperties props = source.getProperties();

			props.setProperty("maxPoolSize", 25);
			props.setProperty("httpReadTimeout", 6000);
			props.setProperty("httpConnectionTimeout", 6000);
			props.setProperty("httpReadRetries", 3);
			props.setProperty("httpSendBufferSize", 8000);
			props.setProperty("httpReceiveBufferSize", 65000);
			props.setProperty("isAmazonS3", false);
			props.setProperty("s3BucketNameInDomain", false);

			mediaCache.addSource(sourceName, source);
		}
	}
}