Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

JavaFX MediaPlayer

4301785Aug 5 2020 — edited Aug 5 2020

I've been trying to create a Video Player in JavaFX using the Media/MediaView and MediaPlayer libraries. Everything seems to be working just fine except for the Media library, which crashes the program before anything display. I'm getting an error saying that I don't have the media library, or more specifically, the scene.control.media library. I've tried this on two different devices with different installations as well. I saw another similar issue on stack overflow where someone posted this problem, but their was no response. Any suggestions?

My current version:

package application;

import java.io.File;

import javafx.application.Application;

import javafx.stage.Stage;

import javafx.scene.Scene;

import javafx.scene.control.Button;

import javafx.scene.control.Label;

import javafx.scene.layout.GridPane;

import javafx.scene.layout.HBox;

import javafx.scene.layout.Pane;

import javafx.scene.layout.StackPane;

import javafx.scene.layout.TilePane;

import javafx.scene.layout.VBox;

import javafx.scene.media.Media;

import javafx.scene.media.MediaPlayer;

import javafx.scene.media.MediaView;

public class Main extends Application  {

public static void main(String args[]){       

launch(args);  

}

@Override  

public void start(Stage primaryStage) throws Exception {

String file = "https://coderslegacy.com/wp-content/uploads/2020/07/Pygame_Platformer.mp4";

Media media = new Media(new File(file).toURI().toString());

MediaPlayer mediaplayer = new MediaPlayer(media);

MediaView mediaView = new MediaView (mediaplayer);

Button button1 = new Button("Play");

button1.setOnAction(e -> {

mediaplayer.play();

});

GridPane layout = new GridPane();

layout.setHgap(10);

layout.setVgap(10);

layout.add(mediaView, 1, 0);

layout.add(button1, 0, 1);

Scene scene = new Scene(layout, 300, 200);

primaryStage.setTitle("JavaFX example");

primaryStage.setScene(scene);

primaryStage.show();

    }

}

I've tried looking all over the place, but can't find a solution. I've tried directly copy pasting code from working examples and tried to run it but it doesn't work. This kind of implies that the problem is with me. I have all the required files (I double checked) and I've installed everything correctly. I've been learning JavaFX from this site for over a month now.

Comments
Post Details
Added on Aug 5 2020
0 comments
538 views