(newbie) video freeze

Hello, I am sorry this is probably a silly question but I can't find any answer in forums on internet so I post it here.

Basically I am develloping a stand-alone application.

I need to display a video (mpeg) stored locally. I use JMF for that.

Using SWING for GUI I used the hint lightweight_renderer for the video to work correctly (error if used in heavy-weight component because I resize the video and it crashes in full screen).

The main problem si now that the video seemed to start with a delay and after some time (always the same, something like 7s on 10s) the video freezes .

I may have some clues,like memory troubles or something like that, but being a real newbie in Java and even in programming I think I need some help.

So please if you have got any clues Ii will be really appreciated.

Thanks by advance and excuse my bad english (french dude!)

Ben

[921 byte] By [BenGillesa] at [2007-11-26 12:24:46]
# 1
Take a look at this thread http://forum.java.sun.com/thread.jspa?forumID=28&threadID=768751hopefully some of this will help
SMarica at 2007-7-7 15:28:08 > top of Java-index,Security,Cryptography...
# 2
thanx for your quick answer but I already tried stop, deallocate etc etc...not working...still trying...help needed!!Ben
BenGillesa at 2007-7-7 15:28:08 > top of Java-index,Security,Cryptography...
# 3
Perhaps you can post up some of your code for us - then maybe we can help further
Stefan_Marica at 2007-7-7 15:28:08 > top of Java-index,Security,Cryptography...
# 4

ok I have got some news :

Firstly It seems that there is a problem of synchronisation with my video :

It starts with a black screen for several seconds but the sound starts right at the beginning so the images of the video are delayed basically of several seconds.

My video is included in a JPanel (in lightweight as I said)

here is the code (sorry comments in French, my native tongue!) :

/**

* La classe JPanelContentVideo d閒init un panneau de contenu vid閛 pour le JanelDesktop.

*/

package IHM.navigation;

import java.awt.Component;

import java.io.IOException;

import javax.media.ControllerEvent;

import javax.media.ControllerListener;

import javax.media.EndOfMediaEvent;

import javax.media.Manager;

import javax.media.MediaLocator;

import javax.media.NoPlayerException;

import javax.media.Player;

import javax.media.RealizeCompleteEvent;

import javax.swing.BoxLayout;

import javax.swing.JOptionPane;

/**

* @author Jacques

* @date 08/12/2006

* @version 1.0

*/

public class JPanelContentVideo extends JPanelContent implements ControllerListener {

private static final long serialVersionUID = -1227222453854714422L;

private Player player; // player de vid閛

private Component playerComponent;

private Component playerControls;

private String videoFile; // chemin du fichier vid閛

public JPanelContentVideo(String videoFilePath) {

setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));

this.videoFile = "file:"+videoFilePath;

setDoubleBuffered(true);

// cr閍tion d'un player ?partir d'un fichier source

try {

Manager.setHint(Manager.PLUGIN_PLAYER, new Boolean(true));

Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, new Boolean(true));

player = Manager.createPlayer(new MediaLocator(videoFile));

} catch (NoPlayerException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

// ajout d'un listener afin de contr鬺er les 閠ats

player.addControllerListener(this);

player.realize();

}

/**

*

*/

public void start(){

}

/**

* Stop playing

*/

public void stop() {

if (player != null) {

player.stop();

}

}

public void controllerUpdate(ControllerEvent controllerEvent) {

// end of initializations

if (controllerEvent instanceof RealizeCompleteEvent) {

playerComponent = player.getVisualComponent();

playerControls = player.getControlPanelComponent();

// composant valide ?

if (playerComponent != null) {

add(playerComponent);

if (playerControls != null) {

add(playerControls);

}

setVisible(true);

} else {

JOptionPane.showMessageDialog(this, "Impossible de lire votre vid閛 : " + videoFile);

}

}

// end of playing

else if (controllerEvent instanceof EndOfMediaEvent) {

System.out.println("end of playing : " + videoFile);

}

}

}

BenGillesa at 2007-7-7 15:28:08 > top of Java-index,Security,Cryptography...
# 5

The code you posted would not compile here,

let alone run. This variant is an SSCCE, and it

compiels and runs (if you have the JMF installed),

but does not freeze (although it still has serious

layout problems).

Does this code display what you are talking about?

/**

* La classe JPanelContentVideo d閒init un panneau

* de contenu vid閛 pour le JanelDesktop.

*/

import java.awt.*;

import java.io.IOException;

import javax.media.*;

import javax.swing.*;

public class JPanelContentVideo extends

JPanel implements ControllerListener {

private Player player; // player de vid閛

private Component playerComponent;

private Component playerControls;

private String videoFile; // chemin du fichier vid閛

public JPanelContentVideo(String videoFilePath) {

setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));

this.videoFile = "file:"+videoFilePath;

setDoubleBuffered(true);

// cr閍tion d'un player ?partir d'un fichier source

try {

Manager.setHint(

Manager.PLUGIN_PLAYER, new Boolean(true));

Manager.setHint(

Manager.LIGHTWEIGHT_RENDERER, new Boolean(true));

player = Manager.createPlayer(

new MediaLocator(videoFile));

} catch (NoPlayerException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

// ajout d'un listener afin de contr鬺er les 閠ats

player.addControllerListener(this);

player.realize();

}

public void start(){

if (player != null) {

player.start();

}

}

public void stop() {

if (player != null) {

player.stop();

}

}

public void controllerUpdate(

ControllerEvent controllerEvent) {

// end of initializations

if (controllerEvent instanceof RealizeCompleteEvent) {

playerComponent = player.getVisualComponent();

playerControls = player.getControlPanelComponent();

// composant valide ?

if (playerComponent != null) {

add(playerComponent);

if (playerControls != null) {

add(playerControls);

}

//setVisible(true);

validate();

} else {

JOptionPane.showMessageDialog(this,

"Impossible de lire votre vid閛 : " +

videoFile);

}

}

// end of playing

else if (controllerEvent instanceof EndOfMediaEvent) {

System.out.println("end of playing : " + videoFile);

}

}

public static void main(String[] args) {

JFrame f = new JFrame();

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanelContentVideo jpcv = new

JPanelContentVideo(

JOptionPane.showInputDialog( f,

"Display File",

"D:/movies/avi/100_1330.avi" ));

f.getContentPane().add(jpcv);

f.pack();

f.setSize(

Toolkit.getDefaultToolkit().getScreenSize() );

f.setVisible(true);

}

}

AndrewThompson64a at 2007-7-7 15:28:08 > top of Java-index,Security,Cryptography...