Java – streaming video using xuggler
I can successfully play the video with xuggler using the following code I need to be able to stream from InputStream instead of file I try to create an icontainer with commented out code When I commented out the code, I did modify the gettestfile method to use string instead of input stream It initially gets the input stream correctly
When I call open on icontainer, it is an infinite block I don't know if I'm getting close to this correctly How do I do basically the same thing without using files and using input streams?
Thank you: -)
package com.plumber.testing; import com.xuggle.mediatool.IMediaReader; import com.xuggle.mediatool.IMediaViewer; import com.xuggle.mediatool.ToolFactory; import com.xuggle.xuggler.IContainer; import java.io.FileNotFoundException; import java.io.InputStream; public class VideoTest { public static void main(String[] args) throws FileNotFoundException { // IContainer iContainer = IContainer.make(); // iContainer.open(getTestFile("IMG_0983.MOV"),null); // I was originally passing the icontainer to make reader IMediaReader mediaReader = ToolFactory.makeReader(getTestFile("IMG_0983.MOV")); IMediaViewer mediaViewer = ToolFactory.makeViewer(true); mediaReader.addListener(mediaViewer); while (mediaReader.readPacket() == null) ; } private static String getTestFile(String fileName) { return VideoTest.class.getClassLoader().getResource("com/plumber/testing/testfiles/" + fileName).getPath(); } }
Solution
I think you need to do something like this:
IContainer iContainer = IContainer.make(); if (iContainer.open(inputStream,IContainer.Type.READ,format) >= 0) { IMediaReader mediaReader = ToolFactory.makeReader(iContainer); ... }
... based on JavaDocs It seems that you need to use the static method of icontainerformat class to get the format If you provide null format, the open method will try to guess the container type... Obviously