{
if (TRACE) logger.fine("DataSource: " + source);
if (!source.getLocator().getProtocol().equals("file"))
throw new IncompatibleSourceException("Only file URLs supported: " + source);
// TODO: only handling file URLs right now.
String path = URLUtils.extractValidPathFromFileUrl(source.getLocator().toExternalForm());
if (path == null)
throw new IncompatibleSourceException("Unable to extract valid file path from URL: " + source.getLocator().toExternalForm());
try
{
// because Java thinks that /C: is a valid way to start a path on Windows, we have to turn it
// into something more normal.
path = new File(path).getCanonicalPath();
}
catch (IOException e1)
{
final String msg = "Unable to get canonical path from " + path + ": " + e1;
logger.log(Level.WARNING, msg, e1);
throw new IncompatibleSourceException(msg);
}
logger.info("Path: " + path);
try
{
System.loadLibrary("jdshow");
}
catch (Throwable e)
{ logger.log(Level.WARNING, "" + e, e);
throw new IncompatibleSourceException();
}
// TODO: check if media has visual
visualComponent = new MyCanvas();
visualComponent.addComponentListener(new MyComponentListener());
try
{
Com.CoInitialize();
int hr;
long[] p = new long[1];
hr = Com.CoCreateInstance(Com.CLSID_FilterGraph, 0L, Com.CLSCTX_ALL, Com.IID_IGraphBuilder, p);
if (Com.FAILED(hr))
throw new ComException(hr);
graphBuilder = new IGraphBuilder(p[0]);
hr = graphBuilder.RenderFile(path, "");
if (Com.FAILED(hr))
throw new ComException(hr);
hr = graphBuilder.QueryInterface(Com.IID_IMediaControl, p);
if (Com.FAILED(hr))
throw new ComException(hr);
mediaControl = new IMediaControl(p[0]);
hr = graphBuilder.QueryInterface(Com.IID_IMediaSeeking, p);
if (Com.FAILED(hr))
throw new ComException(hr);
mediaSeeking = new IMediaSeeking(p[0]);
hr = graphBuilder.QueryInterface(Com.IID_IVideoWindow, p);
if (Com.FAILED(hr))
throw new ComException(hr);
// determine video size:
final IVideoWindow videoWindow = new IVideoWindow(p[0]);
{
long[] width = new long[1];
hr = videoWindow.get_Width(width);
if (Com.FAILED(hr))
throw new ComException(hr);
//logger.fine("width: " + width[0]);
long[] height = new long[1];
hr = videoWindow.get_Height(height);
if (Com.FAILED(hr))
throw new ComException(hr);
//logger.fine("height: " + height[0]);
videoSize = new Dimension((int) width[0], (int) height[0]);
}
videoWindow.Release();
}
catch (ComException e)
{
logger.log(Level.WARNING, "" + e, e);
throw new IncompatibleSourceException(e.getMessage());
}
super.setSource(source);
}