Hi all,
I'm having a bit of trouble with Java Media Framework's MediaPlayer Bean.
I'm making an application that has a MediaPlayer set in a JTabbedPane.
The problem is, once I've called setMediaTime() on the Player, I can't
get it to repaint its visual component. In other words, changing the
media time won't change the contents of the video display.
(I think it starts from the new position when I call Player.start(),
though... but it does not update the display if I call Player.start()
and then immediately Player.stop().)
Is there some "trick" other than calling repaint() or
getVisualComponent().repaint() on the Player to make it update its contents?
TIA,

Signature
-Aki "Sus" Laukkanen
Aki \ - 28 Feb 2005 17:28 GMT
There, I've done and made an SSCCE illustrating my problem:
<SSCCE>
package bug;
/*A rather simple example of setMediaTime() using a SeekBar slider
* More advanced functionality such as updating the seek bar is omitted.
* Note that you also have to resize the frame for the Player to become
* visible initially.
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.media.Time;
import javax.media.bean.playerbean.*;
public class Frame1 extends JFrame {
private final String mediaFile = "C:\\cow[1].mpg";
//Tested on several different mpeg and avi files, so this can't be
the problem.
//Change mediaFile to any mpeg or avi of supported format on your
computer.
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
MediaPlayer thePlayer = new MediaPlayer();
JSlider theSeekBar = new JSlider();
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
init();
this.pack();
this.setSize(500,350);
this.setVisible(true);
thePlayer.repaint(); //This doesn't work
this.repaint();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization (Create an instance of Player and a simple
Seek bar)
private void init() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
this.setTitle("JMF Repaint Bug demo");
theSeekBar.setMinimum(0);
theSeekBar.setMaximum(100);
thePlayer.setMediaLocation("file:"+mediaFile);
thePlayer.realize();
thePlayer.prefetch();
theSeekBar.setValue(0);
theSeekBar.addChangeListener(new SeekBarListener(thePlayer));
contentPane.add(thePlayer, BorderLayout.NORTH);
contentPane.add(theSeekBar, BorderLayout.SOUTH);
}
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
}
class SeekBarListener implements ChangeListener {
private javax.media.bean.playerbean.MediaPlayer target;
public SeekBarListener(javax.media.bean.playerbean.MediaPlayer targ){
this.target = targ;
}
public void stateChanged(ChangeEvent e) {
JSlider source = (JSlider) e.getSource();
if (!source.getValueIsAdjusting()) {
long durationNanoseconds =
(this.target.getDuration().getNanoseconds());
int percent = source.getValue();
long t = (durationNanoseconds / 100) * percent;
Time newTime = new Time(t);
this.target.stop();
this.target.setMediaTime(newTime);
//So far, so good...
//The Seek bar knob on the Plyers default control panel even
moves, but:
this.target.repaint(); //does not work
this.target.getVisualComponent().repaint(); //does not work
either
//Result: The players visual component still displays the old
frame
}
}
}
</SSCCE>
Could you guys please run this example and see if it performs the same
way as described in my previous post on your system?
(And, most importantly, why? And how to correct this?)

Signature
-Aki "Sus" Laukkanen