Skip to main content

Videoplayer and animate

5 replies [Last post]
damkea
Offline
Joined: 2008-07-22

Hi all (again),

I've still have some issues with the MediaComponent. I'm coding a simple videoplayer that uses a label to show the current mediatime (updates with animate() ).

In another thread (http://forums.java.net/jive/thread.jspa?threadID=43208&tstart=15) I asked what causes the video (in a mediacomponent) to flicker. In response Shai Almog adviced me to override setShouldCalcPreferredSize() method on the label that updates the current time with animate.

But still after overriding this method when creating the label I get this flickering. What I'm doing wrong?

Here below I posted an example piece of code:

import java.io.InputStream;

import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.Label;
import com.sun.lwuit.MediaComponent;
import com.sun.lwuit.layouts.BorderLayout;

public class AppMidlet extends MIDlet {

public AppMidlet() {

Display.getInstance().init(this);

Form f = new Form("Video");

f.setLayout(new BorderLayout());

try {
InputStream file = getClass().getResourceAsStream("/video.mpg");
Player player = Manager.createPlayer(file, "video/mpeg");
player.prefetch();
player.realize();
player.start();

MediaComponent media = new MediaComponent(player);
f.addComponent(BorderLayout.CENTER,media);

}
catch(Exception e) {

}

// label that uses animate
Label curTime = new Label("") {

public boolean animate() {

setText("time = " + System.currentTimeMillis());
return true;
}

// override ???
protected void setShouldCalcPreferredSize(boolean var) {

var = false;
}

};

f.show();
f.addComponent(BorderLayout.NORTH,curTime); // after f.show(), cause otherwise it doesnt show up
f.registerAnimated(curTime); // animate

}

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {

}

protected void pauseApp() {

}

protected void startApp() throws MIDletStateChangeException {

}

}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Francis De Brabandere

(from the other post)
have you tried this after Display.init()?

Display.setFlashGraphicsBug(false);

On Sat, Jul 26, 2008 at 10:01 PM, wrote:
> Hi all (again),
>
> I've still have some issues with the MediaComponent. I'm coding a simple videoplayer that uses a label to show the current mediatime (updates with animate() ).
>
> In another thread (http://forums.java.net/jive/thread.jspa?threadID=43208&tstart=15) I asked what causes the video (in a mediacomponent) to flicker. In response Shai Almog adviced me to override setShouldCalcPreferredSize() method on the label that updates the current time with animate.
>
> But still after overriding this method when creating the label I get this flickering. What I'm doing wrong?
>
> Here below I posted an example piece of code:
>
> import java.io.InputStream;
>
> import javax.microedition.media.Manager;
> import javax.microedition.media.Player;
> import javax.microedition.midlet.MIDlet;
> import javax.microedition.midlet.MIDletStateChangeException;
>
> import com.sun.lwuit.Display;
> import com.sun.lwuit.Form;
> import com.sun.lwuit.Label;
> import com.sun.lwuit.MediaComponent;
> import com.sun.lwuit.layouts.BorderLayout;
>
>
> public class AppMidlet extends MIDlet {
>
> public AppMidlet() {
>
> Display.getInstance().init(this);
>
> Form f = new Form("Video");
>
> f.setLayout(new BorderLayout());
>
> try {
> InputStream file = getClass().getResourceAsStream("/video.mpg");
> Player player = Manager.createPlayer(file, "video/mpeg");
> player.prefetch();
> player.realize();
> player.start();
>
> MediaComponent media = new MediaComponent(player);
> f.addComponent(BorderLayout.CENTER,media);
>
> }
> catch(Exception e) {
>
> }
>
> // label that uses animate
> Label curTime = new Label("") {
>
> public boolean animate() {
>
> setText("time = " + System.currentTimeMillis());
> return true;
> }
>
> // override ???
> protected void setShouldCalcPreferredSize(boolean var) {
>
> var = false;
> }
>
> };
>
> f.show();
> f.addComponent(BorderLayout.NORTH,curTime); // after f.show(), cause otherwise it doesnt show up
> f.registerAnimated(curTime); // animate
>
> }
>
> protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
>
>
> }
>
> protected void pauseApp() {
>
>
> }
>
> protected void startApp() throws MIDletStateChangeException {
>
> }
>
> }
> [Message sent by forum member 'damkea' (damkea)]
>
> http://forums.java.net/jive/thread.jspa?messageID=289576
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

--
http://www.somatik.be
Microsoft gives you windows, Linux gives you the whole house.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

damkea
Offline
Joined: 2008-07-22

Hi Francis,

Thanks! Your solution works or is atleast a work-around.

thx!

Francis De Brabandere

On what phone(s)/emulator(s) are you having this flickering?

On Mon, Jul 28, 2008 at 3:07 PM, wrote:
> Hi Francis,
>
> Thanks! Your solution works or is atleast a work-around.
>
> thx!
> [Message sent by forum member 'damkea' (damkea)]
>
> http://forums.java.net/jive/thread.jspa?messageID=289778
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

--
http://www.somatik.be
Microsoft gives you windows, Linux gives you the whole house.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

damkea
Offline
Joined: 2008-07-22

Just the default emulators coming with the Sun Wireless Toolkit (2.5.2). I tested the midlet only on a nokia n70 where the flickering happened as well.

Shai Almog

Hi,
I looked over your code a bit and there are is a minor issue there:

public boolean animate() {
setText("time = " + System.currentTimeMillis());
return true;
}

animate() should return false here since you don't want to trigger a
repaint (setText does this implicitly).

I also looked over the code for the media player and I think there is
an issue there which I will try to workaround for the next drop. It
might cause an issue on some buggy devices though... but only while
playing media files.

Thanks.

> Just the default emulators coming with the Sun Wireless Toolkit
> (2.5.2). I tested the midlet only on a nokia n70 where the
> flickering happened as well.
> [Message sent by forum member 'damkea' (damkea)]
>
> http://forums.java.net/jive/thread.jspa?messageID=289935
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

Shai Almog
http://lwuit.blogspot.com/

[att1.html]