Wowza Community

How to play a Stream file using the Java APIs?

I am trying to play a m3u8 file when an HTTP provider is called. I tried putting it directly and putting it in a stream file but both ways are not working. How do I do this?

This is my code:

public class HttpTest extends HTTProvider2Base {

public void onHTTPRequest(IVHost vhost, IHTTPRequest req, IHTTPResponse resp) {
	if (!doHTTPAuthentication(vhost, req, resp))
		return;
	
	IApplicationInstance appInstance = vhost.getApplicationInstance("mkktest", "_definst_");
	 Stream	stream = Stream.createInstance(appInstance, "myStream");
	 stream.addToPlaylist(0, "bipbop.stream", 0, 100);
	 // stream.addToPlaylist(1, "m3u8:https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8", 0, 100);
	 stream.play(0);

	String helloStr = stream.toString();
	String retStr = "<html><head><title>" + helloStr + "</title></head><body>" + helloStr + "</body></html>";

	try {
		OutputStream out = resp.getOutputStream();
		byte[] outBytes = retStr.getBytes();
		out.write(outBytes);
	} catch (Exception e) {
		WMSLoggerFactory.getLogger(null).error("HttpTest: " + e.toString());
	}

}

}

My bipbop.stream file is:

https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8

With putting the stream file, I get the error:

Container failed: java.lang.Exception: QTUtils.parseQTMediaContainer: File is missing 'moov' atom.

With putting the m3u8 directly, I get the error:

INFO server comment - Stream.switch[mkktest/_definst_/myStream]: index: 0 name:m3u8:https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8 start:0 length:100 interItemGap(a/v/c/u):0/0/0/0
ERROR server comment - MediaReaderFactory.getInstance: Missing definition for m3u8
ERROR server comment - PublishingProviderMediaReader.play : java.lang.NullPointerException|at com.wowza.wms.stream.publish.PublishingProviderMediaReader.play(PublishingProviderMediaReader.java:474)|at com.wowza.wms.stream.publish.Stream.run(Stream.java:226)|at java.base/java.lang.Thread.run(Unknown Source)|

How do I solve this?

@khat33b I see in your logging it’s still referencing the stream name as the M3U8 url, as you did comment out this in your code:
// stream.addToPlaylist(1, “m3u8:https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8”, 0, 100);
stream.play(0);

Only the stream name can be added to a playlist:
https://www.wowza.com/resources/serverapi/com/wowza/wms/stream/publish/Playlist.html#addItem(java.lang.String,int,int)

Missing a moov atom is usually an error with MP4 content that does that was not closed properly when created.

I would recommend testing with another source, if having further issues, reach out to Wowza support with full workflow details and the below support info:
[install-dir]/conf
[install-dir]/logs
[install-dir]/content (your stream file that you’re connecting to)