5

I have installed Ubuntu 14.04 and i'm getting an error when i instantiate a MediaPlayer.

package mediatest;

import java.io.File;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Stage;

/**
 *
 * @author DESARROLLO
 */
public class MediaTest extends Application {

    @Override
    public void start(Stage primaryStage) {
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                Media media = new Media(new File("rotate.mp4").toURI().toASCIIString());
                MediaPlayer player = new MediaPlayer(media);
            }
        });

        StackPane root = new StackPane();
        root.getChildren().add(btn);

        Scene scene = new Scene(root, 300, 250);

        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

}

The problem is when i create the MediaPlayer:

Media media = new Media(new File("rotate.mp4").toURI().toASCIIString());
MediaPlayer player = new MediaPlayer(media);

The Exception message:

Caused by: MediaException: UNKNOWN : com.sun.media.jfxmedia.MediaException: Could not create player! : com.sun.media.jfxmedia.MediaException: Could not create player!
at javafx.scene.media.MediaException.exceptionToMediaException(MediaException.java:146)
at javafx.scene.media.MediaPlayer.init(MediaPlayer.java:511)
at javafx.scene.media.MediaPlayer.<init>(MediaPlayer.java:414)
at javafxapplication2.FXMLDocumentController.handleButtonAction(FXMLDocumentController.java:34)

I have already installed ubuntu-restricted-extras, and all codecs needed to display mp4 videos. When i play the video with Vlc or other player, there is no problem.

May it be a JavaFx issue in Ubuntu 14.04?

I have tried with jre-1.8

juancito
  • 866
  • 2
  • 9
  • 22

3 Answers3

2

You can manually install the required version of av libraries downloading them from http://www.ubuntuupdates.org/. Search for packages libavutil51, libavformat53, libavcodec53

Download the ones matches the architecture of your JVM and use sudo dpkg -i libav*.deb to install them.

  • Obtaining the packages listed above (along with their dependencies) worked for me on Ubuntu 14.10 using oracle java 8u40 jdk to build and run. I added `http://archive.ubuntu.com/ubuntu precise main` to Software Sources and used Synaptic Package Manager. I went ahead and removed libavutil54 beforehand just in case. Simply updating to java 8u40 does not address the error in the original question. – entitycs Apr 01 '15 at 05:49
2

I had the same issue on Ubuntu 14.04, it seems that the latest version of javaFx which comes with the jdk 8 doesn't recognize libavcodec54 (which comes shipped with Ubuntu 14.04)

To be able to use video: Install the latest version of oracle (8u40) from the Oracle website.

Steps:

  1. Download the latest Jdk version for your system from (http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)

  2. Decompress the file to /usr/lib/jvm

    tar -xvf jdk-8u40-linux-[arch_type].tar.gz
    mv jdk-8u40 /usr/lib/jvm

  3. Set the current java version with:

    update-alternatives --config java
    update-alternatives --config javac

To see more details on the bug see: https://bugs.openjdk.java.net/browse/JDK-8094633

Alex Mantaut
  • 3,657
  • 3
  • 35
  • 45
  • If you arrived here from the linked "duplicate" question, note that updating to java 8u40 does not address the issue in Ubuntu 14.10. – entitycs Apr 01 '15 at 05:51
  • 1
    Yes, @DustinCharles is right, this answer assumes that you have libavcodec54/libavutil54 installed on your system. I don't know which version of libavutil54 ships with Ubuntu 14.10. To fix this you can download libavutil54 as mentioned in your comment on the previous post. If you want I can edit the instructions to include that. – Alex Mantaut Apr 06 '15 at 17:51
1

Ubuntu 14 isn't (currently) a supported configuration for Java 8, maybe it will work, maybe it won't (Ubuntu 12 and 13 are supported). Also, do you have the right libraries installed? That it works with VLC, doesn't matter. For Linux, the requirements for Java media are listed in the supported configurations document:

You must install GLIB 2.28 in order to run JavaFX Media.

You must install the following in order to support AAC audio, MP3 audio, H.264 video, and HTTP Live Streaming:

libavcodec53 and libavformat53 on Ubuntu Linux 12.04 or equivalent.
  • VP6 video support does not require any third party modules.
  • On Linux platforms, installing libavformat automatically causes libavcodec to be installed.

Also, MP4 is just a container format and not all MP4 files are created equal. You need to ensure that in addition to the container type being used, that the media inside the encoder conforms to a supported encoding type and that you are accessing the media using a supported protocol.

If you have some non-ubuntu machine (e.g. a Windows or OS X machine), try running your application to play back your media using that (just to see if your issue is specific to your runtime installation or - if that didn't work - it is likely related to the encoding you are using rather than the runtime).

jewelsea
  • 150,031
  • 14
  • 366
  • 406
  • Tried installing all what you said and nothing happened. In W7 and Ubuntu 12.04 it's running, so i guess it's an Ubuntu 14.04 issue – juancito Jun 09 '14 at 15:19