Application j2me

SAS1986 Messages postés 12 Date d'inscription mardi 19 mai 2009 Statut Membre Dernière intervention 23 février 2011 - 2 déc. 2009 à 18:50
amounadaknou Messages postés 1 Date d'inscription mercredi 21 septembre 2011 Statut Membre Dernière intervention 21 septembre 2011 - 21 sept. 2011 à 13:51
Slt,
je suis en train de develloper une application mobile avec J2ME.
Cette application permet de lire un video à partir d'un url.Je veux ajouter des threads pour le snapshot et play mais je n'arrive pas à le faire.
voila mon code pour le midlet

/*--------------------------------------------------
* VideoPlayer.java
*-------------------------------------------------*/
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import java.io.*;

/**
* Un example de MIDlet qui lit une vidéo depuis un URL"
* @author Tebourbi
* @version
*/

public class VideoPlayer extends MIDlet implements CommandListener,ItemStateListener,Runnable
{
private Display display = null; // Reference to Display object
private Form fmMain; // The main form
private Command cmExit,playCommand, pauseCommand,stopCommand,snapshotCommand; // Command to exit the MIDlet
private StringItem Msg;
private Player p;
private VideoControl vc;
private int a,b;
private Gauge gauge = null;
private StringItem gaugeLabel = null;
Thread th;
public void run(){


}
public VideoPlayer()
{
display = Display.getDisplay(this);

cmExit = new Command("Exit", Command.EXIT, 1);
playCommand = new Command("Play", Command.SCREEN, 2);
pauseCommand = new Command("Pause", Command.SCREEN, 3);
stopCommand = new Command("Stop", Command.SCREEN, 4);
snapshotCommand = new Command("Snapshot", Command.SCREEN, 5);
gauge =new Gauge("Volume (0-50)", true, 50, 50);
fmMain = new Form("HelloSupcom"); //Form
Msg = new StringItem("", " ...Hello Sup'Com! ");
gaugeLabel = new StringItem("Volume : 50", "");
//private Command volCommand = new Command("Volume", Command.ITEM, 2);

fmMain.append(gauge);
fmMain.append(gaugeLabel);
fmMain.addCommand(cmExit);
fmMain.addCommand(playCommand);
fmMain.addCommand(pauseCommand);
fmMain.addCommand(stopCommand);
fmMain.addCommand(snapshotCommand);
fmMain.setCommandListener(this);
fmMain.setItemStateListener(this);

fmMain.append(Msg);
fmMain.setCommandListener(this);

}


public void startApp()
{

;

try {
p = Manager.createPlayer("http://localhost:80/sas/shark.mpg");
p.realize();
vc = (VideoControl)p.getControl("VideoControl");
if (vc != null) {
fmMain.append((Item)vc.initDisplayMode(vc.USE_GUI_PRIMITIVE, null));
Display.getDisplay(this).setCurrent(fmMain);
}
p.prefetch();
}
catch (IOException ioe) { System.out.println(ioe.toString());}
catch (MediaException me) {System.out.println(me.toString());}


}

public void pauseApp()
{
}

public void destroyApp(boolean unconditional)
{
try {
p.stop();
}
catch(MediaException me) {
}
p=null;
}

public void commandAction(Command c, Displayable s)
{
if (c == cmExit)
{
destroyApp(false);
notifyDestroyed();
}


if (c == playCommand)
{

try {
if (a == 1 )
{ p = Manager.createPlayer("http://localhost:80/sas/shark.mpg");
p.realize();
vc = (VideoControl)p.getControl("VideoControl");
p.prefetch();
}



if ( b==0){

p.start();
b=1;
}
}
catch (IOException ioe) { System.out.println(ioe.toString());}
catch (MediaException me) {System.out.println(me.toString());}
}


if (c ==pauseCommand)
{
a=0;
b=0;
try {

p.stop();
}
//catch (IOException ioe) { System.out.println(ioe.toString());}
catch (MediaException me) {System.out.println(me.toString());}
}
if (c ==stopCommand)
{
a=1;

b=0;

p.deallocate();

}


}



public void itemStateChanged(Item item) {
// if an item changes – it gets sent here!
System.out.println("State changed on item " + item.toString());
if (item!=null) {
if (item == gauge) {
VolumeControl vcc = getVolumeControl();
if (vcc != null) {
vcc.setLevel(gauge.getValue());
updateVolume(vcc);
}
}
}
}

private VolumeControl getVolumeControl() {
VolumeControl volcont=null;
try {

if (p != null) {
volcont=(VolumeControl) p.getControl("VolumeControl");

}


} catch (IllegalStateException ise) {
// thrown when player is closed
}

return volcont;

}
private void updateVolume(VolumeControl c) {
if (c==null) {
c = getVolumeControl();
}
if (c != null) {
//int l = gauge.getValue();
//c.setLevel(l);
int l =c.getLevel();
String disp = "Volume: "+String.valueOf(l);
if (gauge != null ) {
gauge.setValue(l);
gaugeLabel.setLabel(disp);
}

}
}
}


j'attends votre aide.
merci d'avance.

1 réponse

amounadaknou Messages postés 1 Date d'inscription mercredi 21 septembre 2011 Statut Membre Dernière intervention 21 septembre 2011
21 sept. 2011 à 13:51
amounadaknou
0
Rejoignez-nous