java - vlcj Error handling -
i'm working on selfmade video-media-player in javafx , therefore i'm using vlcj. i'm using directmediaplayercomponent renders video canvas. everthing fine here. video plays smooth , controlls working.
however, lot of runtimeerrors cause canvas turn black sound still played, example
java.lang.illegalargumentexception: image dimensions must > 0 @ com.sun.prism.image.<init>(image.java:271) @ com.sun.prism.image.<init>(image.java:241) @ com.sun.prism.image.frombytebgrapredata(image.java:79) @ com.sun.javafx.sg.prism.ngcanvas.renderstream(ngcanvas.java:591) @ com.sun.javafx.sg.prism.ngcanvas.rendercontent(ngcanvas.java:389) @ com.sun.javafx.sg.prism.ngnode.dorender(ngnode.java:201) @ com.sun.javafx.sg.prism.ngnode.dorender(ngnode.java:40) @ com.sun.javafx.sg.basenode.render(basenode.java:1145) @ com.sun.javafx.sg.prism.nggroup.rendercontent(nggroup.java:204) @ com.sun.javafx.sg.prism.ngregion.rendercontent(ngregion.java:420) @ com.sun.javafx.sg.prism.ngnode.dorender(ngnode.java:201) @ com.sun.javafx.sg.prism.ngnode.dorender(ngnode.java:40) @ com.sun.javafx.sg.basenode.render(basenode.java:1145) @ com.sun.javafx.sg.prism.nggroup.rendercontent(nggroup.java:204) @ com.sun.javafx.sg.prism.ngregion.rendercontent(ngregion.java:420) @ com.sun.javafx.sg.prism.ngnode.dorender(ngnode.java:201) @ com.sun.javafx.sg.prism.ngnode.dorender(ngnode.java:40) @ com.sun.javafx.sg.basenode.render(basenode.java:1145) @ com.sun.javafx.sg.prism.nggroup.rendercontent(nggroup.java:204) @ com.sun.javafx.sg.prism.ngregion.rendercontent(ngregion.java:420) @ com.sun.javafx.sg.prism.ngnode.dorender(ngnode.java:201) @ com.sun.javafx.sg.prism.ngnode.dorender(ngnode.java:40) @ com.sun.javafx.sg.basenode.render(basenode.java:1145) @ com.sun.javafx.sg.prism.nggroup.rendercontent(nggroup.java:204) @ com.sun.javafx.sg.prism.ngregion.rendercontent(ngregion.java:420) @ com.sun.javafx.sg.prism.ngnode.dorender(ngnode.java:201) @ com.sun.javafx.sg.prism.ngnode.dorender(ngnode.java:40) @ com.sun.javafx.sg.basenode.render(basenode.java:1145) @ com.sun.javafx.sg.prism.nggroup.rendercontent(nggroup.java:204) @ com.sun.javafx.sg.prism.ngregion.rendercontent(ngregion.java:420) @ com.sun.javafx.sg.prism.ngnode.dorender(ngnode.java:201) @ com.sun.javafx.sg.prism.ngnode.dorender(ngnode.java:40) @ com.sun.javafx.sg.basenode.render(basenode.java:1145) @ com.sun.javafx.tk.quantum.viewpainter.dopaint(viewpainter.java:117) @ com.sun.javafx.tk.quantum.abstractpainter.paintimpl(abstractpainter.java:182) @ com.sun.javafx.tk.quantum.presentingpainter.run(presentingpainter.java:73) @ java.util.concurrent.executors$runnableadapter.call(executors.java:471) @ java.util.concurrent.futuretask.runandreset(futuretask.java:304) @ com.sun.prism.render.renderjob.run(renderjob.java:37) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) @ com.sun.javafx.tk.quantum.quantumrenderer$pipelinerunnable.run(quantumrenderer.java:108) @ java.lang.thread.run(thread.java:744)
or
java.lang.internalerror: unrecognized pgcanvas token: -128 @ com.sun.javafx.sg.prism.ngcanvas.renderstream(ngcanvas.java:780) @ com.sun.javafx.sg.prism.ngcanvas.rendercontent(ngcanvas.java:389) @ com.sun.javafx.sg.prism.ngnode.dorender(ngnode.java:201) @ com.sun.javafx.sg.prism.ngnode.dorender(ngnode.java:40) @ com.sun.javafx.sg.basenode.render(basenode.java:1145) @ com.sun.javafx.sg.prism.nggroup.rendercontent(nggroup.java:204) @ com.sun.javafx.sg.prism.ngregion.rendercontent(ngregion.java:420) @ com.sun.javafx.sg.prism.ngnode.dorender(ngnode.java:201) @ com.sun.javafx.sg.prism.ngnode.dorender(ngnode.java:40) @ com.sun.javafx.sg.basenode.render(basenode.java:1145) @ com.sun.javafx.sg.prism.nggroup.rendercontent(nggroup.java:204) @ com.sun.javafx.sg.prism.ngregion.rendercontent(ngregion.java:420) @ com.sun.javafx.sg.prism.ngnode.dorender(ngnode.java:201) @ com.sun.javafx.sg.prism.ngnode.dorender(ngnode.java:40) @ com.sun.javafx.sg.basenode.render(basenode.java:1145) @ com.sun.javafx.sg.prism.nggroup.rendercontent(nggroup.java:204) @ com.sun.javafx.sg.prism.ngregion.rendercontent(ngregion.java:420) @ com.sun.javafx.sg.prism.ngnode.dorender(ngnode.java:201) @ com.sun.javafx.sg.prism.ngnode.dorender(ngnode.java:40) @ com.sun.javafx.sg.basenode.render(basenode.java:1145) @ com.sun.javafx.sg.prism.nggroup.rendercontent(nggroup.java:204) @ com.sun.javafx.sg.prism.ngregion.rendercontent(ngregion.java:420) @ com.sun.javafx.sg.prism.ngnode.dorender(ngnode.java:201) @ com.sun.javafx.sg.prism.ngnode.dorender(ngnode.java:40) @ com.sun.javafx.sg.basenode.render(basenode.java:1145) @ com.sun.javafx.sg.prism.nggroup.rendercontent(nggroup.java:204) @ com.sun.javafx.sg.prism.ngregion.rendercontent(ngregion.java:420) @ com.sun.javafx.sg.prism.ngnode.dorender(ngnode.java:201) @ com.sun.javafx.sg.prism.ngnode.dorender(ngnode.java:40) @ com.sun.javafx.sg.basenode.render(basenode.java:1145) @ com.sun.javafx.tk.quantum.viewpainter.dopaint(viewpainter.java:117) @ com.sun.javafx.tk.quantum.abstractpainter.paintimpl(abstractpainter.java:182) @ com.sun.javafx.tk.quantum.presentingpainter.run(presentingpainter.java:73) @ java.util.concurrent.executors$runnableadapter.call(executors.java:471) @ java.util.concurrent.futuretask.runandreset(futuretask.java:304) @ com.sun.prism.render.renderjob.run(renderjob.java:37) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) @ com.sun.javafx.tk.quantum.quantumrenderer$pipelinerunnable.run(quantumrenderer.java:108) @ java.lang.thread.run(thread.java:744)
the errors occure unpredictable, not depend on video or videoformat, tested several different files.
my question is, how can catch errors , implement recovery strategy. have tried override error method of 'mediaplayereventlistener'
public void error(mediaplayer mediaplayer)
but seems have no effect.
edit: code i'm using:
mediaplayercomponent = new testmediaplayercomponent(); mediaplayercomponent.getmediaplayer().playmedia(video_file); private class testmediaplayercomponent extends directmediaplayercomponent { @override public void display(directmediaplayer mediaplayer, memory[] nativebuffers, bufferformat bufferformat) { memory nativebuffer = nativebuffers[0]; bytebuffer bytebuffer = nativebuffer.getbytebuffer(0, nativebuffer.size()); pixelwriter.setpixels(0, 0, bufferformat.getwidth(), bufferformat.getheight(), pixelformat, bytebuffer, bufferformat.getpitches()[0]); } @override public void error(mediaplayer mediaplayer) { system.out.println("error detected!"); } public testmediaplayercomponent() { super(new testbufferformatcallback()); } } private class testbufferformatcallback implements bufferformatcallback { @override public bufferformat getbufferformat(int sourcewidth, int sourceheight) { int width = (int) stackpane.getwidth(); int height = (int) stackpane.getheight(); double ratio = stackpane.getwidth()/stackpane.getheight(); double sourceratio = double.valueof(sourcewidth)/double.valueof(sourceheight); if(ratio <= sourceratio) { height = (int) (width/sourceratio); } else { width = (int) (height * sourceratio); } canvas.setwidth(width); canvas.setheight(height); anchorpane.setprefwidth(width); anchorpane.setprefheight(height); return new rv32bufferformat(width, height); } }
Comments
Post a Comment