Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

problem with mmapi...urgent  RSS feed

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, i'm new to mmapi and i have some problem playing audio and video
The audio went well but when i add the code for the video it didn't worked and ruin the audio as well.
Should i play audio and video using separate thread?
Any feedbacks will be fully appreciated

Here is the code

//////*Canvas class for the audio/video lists

code:

import javax.microedition.lcdui.*;
import java.lang.*;

public class opScreen extends Canvas implements Runnable,CommandListener
{

static final String[] mainMenu={"Vertigo","shiver","video1"}
static int menuIdx;
private animasiPlay wallpaper;
animasiMidlet midlet;

public opScreen(animasiMidlet midlet){
width=getWidth();
height=getHeight();
this.midlet=midlet;
wallpaper=new animasiPlay(midlet);
menuIdx=0;
addCommand(new Command("Back",Command.OK,1));
addCommand(new Command("Stop",Command.OK,2));
setCommandListener(midlet);
new Thread(this).start();

}


protected void keyPressed(int code){
if(getGameAction(code)==Canvas.UP){
menuIdx--;
}else if(getGameAction(code)==Canvas.DOWN&&menuIdx+1<mainMenu.length){
menuIdx++;
}else if(code==-5){
switch(menuIdx){
case 0: midlet.choosePlayer("/musik/vertigo.wav","audio/x-wav");
midlet.playSong(); break;
case 1: midlet.choosePlayer("/musik/shiver.wav","audio/x-wav");
midlet.playSong(); break;
case 2: midlet.choosePlayer("/musik/video1.mpg","audio/mpeg");
midlet.playSong();break;
case 3:
break;
}
}
}
}



///////* The midlet class which play the contents

code:

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.Item;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import javax.microedition.media.PlayerListener;
import java.io.*;

public class animasiMidlet extends MIDlet implements CommandListener , Runnable{


private animasiPlay play;
private Display d;
private InputStream in;
private Player p;
private VolumeControl volc;
public static String loc;
public static String ctype;
private Thread dThread;
private boolean interrupted,dmtime;
Form f;
VideoControl vc;

public animasiMidlet(){
d=Display.getDisplay(this);
play=new animasiPlay(this);
dThread=null;


}

public void startApp(){
d.setCurrent(new contentScreen(this));
}

public void createThread(){
dThread=new Thread(this);
interrupted=false;
dmtime=true;

dThread.start();
}

public void createPlayer(){

try{

in=getClass().getResourceAsStream(loc);
p=Manager.createPlayer(in ,ctype);

vc=(VideoControl)p.getControl("VideoControl");

if(vc!=null){
Item video=(Item)vc.initDisplayMode(vc.USE_GUI_PRIMITIVE,null);
f=new Form("Playing video");
StringItem sitem=new StringItem("playing","....");
f.append(video);
f.append(sitem);
d.setCurrent(f);
}
p.setLoopCount(1);
}
catch(Exception ex){
if(p!=null){
p.close();
p=null;
}
System.out.println("problem creating player"+ex.toString());
}
}

public void run(){
if(p==null){
try{
createPlayer();
p.realize();
volc=(VolumeControl)p.getControl("VolumeControl");
if(volc!=null){
volc.setLevel(100);
}
p.prefetch();
p.start();
}catch(Exception ex){
System.out.println("problem running player"+ex.toString());
}//catch

}//end if

}

public void choosePlayer(String location,String type){
this.loc=location;
this.ctype=type;
}

public void pauseApp(){}

public void destroyApp(boolean unconditional){
notifyDestroyed();
}

public void commandAction(Command c,Displayable d){
if(c.getLabel().equals("Back")){
this.displayContent();
}
else if(c.getLabel().equals("Exit")){
this.destroyApp(false);
}
else if(c.getLabel().equals("Stop")){
this.stopSong();
}
}

public void playSong(){
if(dThread==null){
createThread();
}
else if(p==null){
try{
p.start();
}catch(Exception ex){
System.out.println("problem starting player"+ex.toString());
}

}

}

public void stopSong()
{
try
{
interrupted=true;
dmtime=false;
dThread=null;

Thread.sleep(100);

if(p!=null){
p.stop();
in.close();
p = null;
//in = null;
//System.gc();
}

}
catch(Exception ex){
System.out.println("problem closing player"+ex.toString());
}

}
}
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!