JavaFX - Playing loop video


How should I loop a video in JavaFX? I'm trying to just play a video one time after another, so I was looking for some sample code in many places and I could'nt make it work!

This is what doesn't work for me:

public MyMediaPlayer (){
    media = new Media(getVideo());
    mediaPlayer = new MediaPlayer(media);
    mediaView = new MediaView(mediaPlayer);

private String getVideo() {
    return getClass().getResource("videos/limbo.mp4").toString();

public final void startMediaPlayer() {
    mediaPlayer.setCycleCount(; //this is the line that should do the magic, but it doesn't...;
10/25/2013 6:55:00 PM

Accepted Answer

The following works for me (video loops forever). I can't replicate your issue.

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

public class VideoPlayerExample 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("")
    stage.setScene(new Scene(new Group(new MediaView(oracleVid)), 540, 208));;



I'm under Java 7, doesn't work there . . . the problem seems to be MP4 format.

If you can't play MP4 files, either:

  1. The MP4 is not encoded in a format JavaFX understands (the JavaFX 2.2 Media javadoc details the allowed formats).


  2. You don't have appropriate codecs installed on your machine to allow the MP4 file to be decoded. See the JavaFX 2.2 Media system requirements for information on what you need to install on your machine to allow MP4 files to be displayed.

11/3/2013 11:22:30 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow