How to add a Media Cache source using the Wowza Streaming Engine server-side API

The following code example illustrates how to add a MediaCacheSource on the fly.

Note: This code example isn't a complete solution.
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);
		}
	}
}
Note: The new MediaCacheSource isn't added to [install-dir]/conf/MediaCache.xml automatically so you'll need to do this as well so the MediaCacheSource is available the next time the media server is started.

Originally Published: 10-17-2012.

If you're having problems or want to discuss this article, post in our forum.