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!

JavaFx Freeze and memory consumption

2673998May 15 2014 — edited May 18 2014

I just made an application with javafx that cycles videos in a folder.

I had to set the next video firing the setonendofmedia event, so they are in a cycle, but the problem is that the application loads every video at the beginning, so after a while it fills memory and crashes.Is there another way to cycle videos without pre-load them or a way to flush memory every while?


My Code :


package application;

import java.io.File;

import java.io.FilenameFilter;

import java.util.ArrayList;

import java.util.Collections;

import java.util.List;

import javax.swing.JOptionPane;

import javafx.application.Platform;

import javafx.geometry.Pos;

import javafx.scene.Scene;

import javafx.scene.layout.StackPane;

import javafx.scene.layout.VBox;

import javafx.scene.media.MediaView;

import javafx.scene.media.MediaPlayer;

import javafx.scene.media.Media;

class SceneGenerator {   

    private int xSize;

    private int ySize;

    private MediaPlayer playerNew;

    private int nextFileIndex = -1 ;

    //  private static ThreadChange createPlayerThread = new ThreadChange();   

    private List<String> videoFiles;

    private MediaView mediaView;

    //  private boolean first=true;

    Runnable finale;

    public SceneGenerator(int xSize,int ySize){

        this.xSize=xSize;

        this.ySize=ySize;

        finale = new Runnable() {

            @Override

            public void run() {

                esegui();

            }

        };

    }

    public Scene createScene() {

        final StackPane layout = new StackPane();

        // determine the source directory for the playlist

        final File dir = new File(System.getProperty("user.dir")+"\\video");

        if (!dir.exists() || !dir.isDirectory()) {

            JOptionPane.showMessageDialog(null,"Cannot find video source directory: " + dir);

            Platform.exit();

            System.exit(0);

            return null;

        }

        //inizializzo il toolkit

        mediaView = new MediaView();

        mediaView.setPreserveRatio(false);

        mediaView.setFitHeight(ySize-((ySize/100)*(JavaPlayer.panelSouthYDimension+1)-JavaPlayer.pixelAdattamento));

        mediaView.setFitWidth(xSize);

        videoFiles = new ArrayList<String>();

        for (String file : dir.list(new FilenameFilter() {

            @Override public boolean accept(File dir, String name) {

                return name.endsWith(".mp4")||name.endsWith(".flv");

            }

        })) videoFiles.add("file:///" + (dir + "/" + file).replace("\\", "/"));

        Collections.sort(videoFiles);

        for(int kk=0;kk<videoFiles.size();kk++){

            System.out.println(videoFiles.get(kk));

        }

       

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 15 2014
Added on May 15 2014
1 comment
1,946 views