Vlcj not displaying Video in JavaFx 8

2.7k views Asked by At

To implement VLCJ in JavaFx. I had tried below two example from two separate links. I am currently using JavaFX and JDK 8 in windows

https://forums.oracle.com/thread/2436712

https://github.com/caprica/vlcj-javafx/blob/master/src/test/java/uk/co/caprica/vlcj/javafx/test/JavaFXDirectRenderingTest.java

Both above examples are not giving any results in JavaFX 8

I am posting code of oracle forum:

import java.nio.ByteBuffer;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.image.PixelFormat;
import javafx.scene.image.PixelWriter;
import javafx.scene.image.WritablePixelFormat;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import uk.co.caprica.vlcj.component.DirectMediaPlayerComponent;

import com.sun.jna.Memory;
import com.sun.jna.NativeLibrary;

public class VLCDirectTest extends Application {
  private static final int WIDTH = 1920;
  private static final int HEIGHT = 1080;
  public static void main(final String[] args) {
    Application.launch(args);
  }

  private DirectMediaPlayerComponent mp;

  @Override
  public void start(Stage primaryStage) throws Exception {
    NativeLibrary.addSearchPath("libvlc", "c:/program files (x86)/videolan/vlc");

    BorderPane borderPane = new BorderPane();
    final Canvas canvas = new Canvas(WIDTH, HEIGHT);
    borderPane.setCenter(canvas);
    System.out.println(">>> " + canvas.getGraphicsContext2D().getPixelWriter().getPixelFormat());
    Scene scene = new Scene(borderPane);
    final PixelWriter pixelWriter = canvas.getGraphicsContext2D().getPixelWriter();
    final WritablePixelFormat<ByteBuffer> byteBgraInstance = PixelFormat.getByteBgraPreInstance();

    mp = new DirectMediaPlayerComponent("RV32", WIDTH, HEIGHT, WIDTH*4) {
      private long totalTime;
      private long totalFrames;
      private long tooLateFrames;

      @Override
      public void display(Memory nativeBuffer) {
        long startTime = System.currentTimeMillis();
        ByteBuffer byteBuffer = nativeBuffer.getByteBuffer(0, nativeBuffer.size());
        pixelWriter.setPixels(0, 0, WIDTH, HEIGHT, byteBgraInstance, byteBuffer, WIDTH*4);
        long renderTime = System.currentTimeMillis() - startTime;
        totalTime += renderTime;
        totalFrames++;
        if(renderTime > 20) {
          tooLateFrames++;
        }

        System.out.printf("Frames: %4d   Avg.time: %4.1f ms   Frames>20ms: %d   (Max)FPS: %3.0f fps\n", totalFrames, (double)totalTime / totalFrames, tooLateFrames, 1000.0 / ((double)totalTime / totalFrames));
        if(totalFrames > 1500) {
          System.exit(0);
        }
      }
    };

    mp.getMediaPlayer().playMedia("L:\\Movies\\HD\\2012 [2009, Action Adventure Drama SF Thriller, 1080p].mkv");

    primaryStage.setScene(scene);
    primaryStage.show();
  }
}

Code above is mentioned to be working without any errors on forum. I have all vlcj jars in my classpath but still i am with no success.

But when i use this code I am getting the following error which i am unable to understand.

The method display(Memory) of type new DirectMediaPlayerComponent(){} must override or implement a supertype method

By any mean i am unable to run these examples . I appreciate any help or advice. Thanks

1

There are 1 answers

1
caprica On

You are using a newer version of vlcj than your example code was written for. The display(...) method signature has changed to:

void display(DirectMediaPlayer mediaPlayer, Memory[] nativeBuffers, BufferFormat bufferFormat);

But this is just your first problem, see [1].

[1] https://github.com/caprica/vlcj-javafx/issues/3