JavaFX MediaPlayer in Ubuntu 14.04 64 bits

2019-08-12 07:20发布

问题:

I am trying to execute the simple program below in Ubuntu 14.04 64 bits.

import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.media.*;
import javafx.stage.Stage;

public class simple extends Application {
  public static void main(String[] args) throws Exception { launch(args); }
  @Override public void start(final Stage stage) throws Exception {
    final MediaPlayer oracleVid = new MediaPlayer(
      new Media("http://download.oracle.com/otndocs/products/javafx/JavaRap/prog_index.m3u8")
    );
        oracleVid.setAutoPlay(true);
    stage.setScene(new Scene(new Group(new MediaView(oracleVid)), 540, 208));
    stage.show();

    oracleVid.play();
  }
}

I know that the video and audio format are correct. Actually, this URL was taken from a JavaFX's demo. Moreover, I already tested the application in Ubuntu 13.10 with JavaSDK 1.7 and the same hardware, everything was Ok. The application also executes in Windows. However, it fails when I try in Ubuntu 14.04 for both, Java SDK 1.7 and 1.8.

I guess it is related either to some codec I am missing in my configuration or to some library which is not available in 14.04.

The worst for me is the way the application fails. It doesn't throw an exception, it doesn't crash with a segmentation fault, it doesn't complaint about some missing library. Instead, it just shows a Window with the background colour, without sound, video or any kind of log.

Have anyone run into the same problem? I have been browsing for hours and nothing.

EDIT. I am using oracle-java always.

回答1:

This is a known issue with JavaFX running under Ubuntu 14.04.

  • RT-37914 [Linux] JavaFX Media does not run on Ubuntu 14.04

The issue has been fixed for Java 8u40.

Java 8u40 early access builds are available so you can test the fix and ensure it works on your system.



回答2:

For those looking for instructions for a workaround:

sudo apt-get install yasm
wget https://libav.org/releases/libav-0.8.16.tar.xz
tar xf libav-0.8.16.tar.xz
cd libav-0.8.16
./configure --enable-pic --enable-shared && make
sudo make install