×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    13

    Question LINKING OF 2 MIDLET FILES

    HELLO!
    I AM NEW TO J2ME AND I AM CREATING A MEDIAPLAYER FOR MY FINAL YEAR PROJECT CAN ANY ONE HELP ME IN EXPLAINING HOW TO LINK TO MIDLET FILES WHERE ONE IS THE AUDO AND THE OTHER IS VIDEO ONE???
    THANKS IN ADVANCE

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,085

    Re: LINKING OF 2 MIDLET FILES

    We can create a Midlet suit, which contains both the midlets and use can selected one he wants to use in the runtime.

    thanks,
    ~Amitabh

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    13

    Question LINKING OF 2 MIDLET FILES

    Thanks Amit for replying!!

    my problem is that i have got three seperate midlet files one is the menu into which i have to merge the other two audio n video files.
    Its like in the menu on the click of play audio or video thier respective files should get executed
    but i am not able to do so cause all the three files extends the midlet class!
    pleas can you help me with an example i am new to j2me an have a project in j2me mediaplayer with streaming.


    Thanks thanks alot for replying!!!
    your help would be highly appreciated

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: LINKING OF 2 MIDLET FILES

    You need to have a single class that extends MIDlet. Your other classes might extend some subclasses of Displayable. The MIDlet will look something like:

    Code:
    public class MyMIDlet extends MIDlet {
        private boolean initialized;
    
        public void startApp() {
            if (!initialized) {
                initialized = true;
                Displayable menu = new MyMenu(this);
                Display.getDisplay(this).setCurrent(menu);
            }
        }
    
        // and pauseApp() and destroyApp()
    }
    Your menu class code will look like:

    Code:
    // or, might extend Canvas, or some other Displayable
    public class MyMenu extends List implements CommandListener {
        private MIDlet midlet;
    
        public MyMenu(MIDlet m) {
            midlet = m;
    
            // put items in menu, create commands, etc.
        }
    
        public void commandAction(Command c, Displayable d) {
            if (c.getCommandType() == Command.EXIT) {
                // this is why we needed the MIDlet object
                midlet.notifyDestroyed();
            } else if (optionOneIsSelected) {
                Displayable optionOne = new OptionOne(midlet, this);
                // and we need the MIDlet again
                Display.getDisplay(midlet).setCurrent(optionOne);
            } // repeat for each option
        }
    }
    Then, for each screen accessible from the menu.

    Code:
    // or whatever Displayable type
    public class OptionOne extends Canvas {
        private MIDlet midlet;
        private Displayable menuToReturn;
    
        public OptionOne(MIDlet m, Displayable menu) {
            // need this, so we can put the menu back later
            midlet = m;
            menuToReturn = menu;
        }
    
        // etc.
    }
    Hope that helps.

    Graham.

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    13

    Question Re: LINKING OF 2 MIDLET FILES

    Thanks a LOT!!!Graham'

    I immediately tried out your way but since i have the codes already written by extending midlet class i am fimding it difficult to edit them.

    As i mentioned it earlier also i am naive to j2me.
    Sir could you please help me with the codings???


    on the onclick of the first file i want to display the audio on click of audio n video on click of video files

    Thanks a Tons in Advance!!

    Quote Originally Posted by grahamhughes View Post
    You need to have a single class that extends MIDlet. Your other classes might extend some subclasses of Displayable. The MIDlet will look something like:

    Code:
    public class MyMIDlet extends MIDlet {
        private boolean initialized;
    
        public void startApp() {
            if (!initialized) {
                initialized = true;
                Displayable menu = new MyMenu(this);
                Display.getDisplay(this).setCurrent(menu);
            }
        }
    
        // and pauseApp() and destroyApp()
    }
    Your menu class code will look like:

    Code:
    // or, might extend Canvas, or some other Displayable
    public class MyMenu extends List implements CommandListener {
        private MIDlet midlet;
    
        public MyMenu(MIDlet m) {
            midlet = m;
    
            // put items in menu, create commands, etc.
        }
    
        public void commandAction(Command c, Displayable d) {
            if (c.getCommandType() == Command.EXIT) {
                // this is why we needed the MIDlet object
                midlet.notifyDestroyed();
            } else if (optionOneIsSelected) {
                Displayable optionOne = new OptionOne(midlet, this);
                // and we need the MIDlet again
                Display.getDisplay(midlet).setCurrent(optionOne);
            } // repeat for each option
        }
    }
    Then, for each screen accessible from the menu.

    Code:
    // or whatever Displayable type
    public class OptionOne extends Canvas {
        private MIDlet midlet;
        private Displayable menuToReturn;
    
        public OptionOne(MIDlet m, Displayable menu) {
            // need this, so we can put the menu back later
            midlet = m;
            menuToReturn = menu;
        }
    
        // etc.
    }
    Hope that helps.

    Graham.

  6. #6
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: LINKING OF 2 MIDLET FILES

    Hello Jibrael,

    What Grahm is saying is that you can take one midlet, as you already one, and in that midlet you can create a list and can have various commands. Draw the menu items as the list and process the list using the commands.That's all you have to do.

    If you are unable to do this code then either you can write the fresh code, in case you have time else you can put your code here so that we can help you to edit the code.

    However the im2amit's idea is also good you can make a midlet suite.
    you can choose the better option.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  7. #7
    Registered User
    Join Date
    Mar 2010
    Posts
    13

    Question Re: LINKING OF 2 MIDLET FILES

    Helo Raj,

    Thanks for replying,I am very Naive to j2me. i do not know how to create midlet suits n how will it work???

    Following are the codings i would realy appreciate it you could rectify it.
    I have also mailed you the codings

    the main menu coding r as follows:

    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;

    public class CommandExample extends MIDlet implements CommandListener{
    private Form form;
    private Display display;
    private Command ok, back, cancel, exit, help, item, screen, stop;
    private SimpleSlidingCanvas canvas;

    public CommandExample(){
    form = new Form("Command Form");
    screen = new Command("SCREEN", Command.SCREEN, 1);
    back = new Command("BACK", Command.BACK, 2);
    cancel = new Command("CANCEL", Command.CANCEL, 3);
    ok = new Command("OK", Command.OK, 4);
    help = new Command("HELP", Command.HELP, 5);
    stop = new Command("STOP", Command.STOP, 6);
    exit = new Command("EXIT", Command.EXIT, 7);
    item = new Command("ITEM", Command.ITEM, 8);
    }

    public void startApp(){
    display = Display.getDisplay(this);
    form.addCommand(screen);
    form.addCommand(back);
    form.addCommand(cancel);
    form.addCommand(ok);
    form.addCommand(help);
    form.addCommand(stop);
    form.addCommand(exit);
    form.addCommand(item);
    form.setCommandListener(this);
    display.setCurrent(form);
    }

    public void pauseApp(){}

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

    public void backCom(){
    Alert back = new Alert("BACK Command",
    "Back Command Executed!", null, AlertType.INFO);
    back.setTimeout(5000);
    display.setCurrent(back, form);
    }
    public void okCom()
    {
    canvas = new SimpleSlidingCanvas();
    display.setCurrent(canvas);
    }
    public void cancelCom(){
    Alert cancel = new Alert("CANCEL Command",
    "Cancel Command Executed!", null, AlertType.INFO);

    cancel.setTimeout(5000);
    display.setCurrent(cancel, form);
    }
    public void exitCom()
    {
    destroyApp(true);
    }

    public void commandAction(Command c, Displayable d) {
    String label = c.getLabel();
    if(label.equals("BACK")){
    backCom();
    } else if(label.equals("OK")){
    okCom();
    } else if(label.equals("CANCEL")){
    cancelCom();
    } else if(label.equals("EXIT")){
    exitCom();
    }
    }

    }


    the audio n video codings r as follows:



    import java.util.Hashtable;
    import java.util.Enumeration;

    import javax.microedition.lcdui.Item;
    import javax.microedition.lcdui.List;
    import javax.microedition.lcdui.Form;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.CommandListener;

    import javax.microedition.media.Player;
    import javax.microedition.media.Control;
    import javax.microedition.media.Manager;
    import javax.microedition.media.PlayerListener;
    import javax.microedition.media.control.VideoControl;

    public class MediaMIDlet extends MIDlet
    implements CommandListener, PlayerListener {

    private Display display;
    private List itemList;
    private Form form;

    private Command stopCommand;
    private Command pauseCommand;
    private Command startCommand;

    private Hashtable items;
    private Hashtable itemsInfo;

    private Player player;

    public MediaMIDlet() {
    display = Display.getDisplay(this);
    // creates an item list to let you select multimedia files to play
    itemList = new List("Select an item to play", List.IMPLICIT);

    // stop, pause and restart commands
    stopCommand = new Command("Stop", Command.STOP, 1);
    pauseCommand = new Command("Pause", Command.ITEM, 1);
    startCommand = new Command("Start", Command.ITEM, 1);

    // a form to display when items are being played
    form = new Form("Playing media");

    // the form acts as the interface to stop and pause the media
    form.addCommand(stopCommand);
    form.addCommand(pauseCommand);
    form.setCommandListener(this);

    // create a hashtable of items
    items = new Hashtable();

    // and a hashtable to hold information about them
    itemsInfo = new Hashtable();

    // and populate both of them
    items.put("Siren from jar", "file://music.wav");
    itemsInfo.put("Siren from jar", "audio/x-wav");
    items.put("Neo", "file://bubbles.wav");
    itemsInfo.put("Neo", "audio/x-wav");
    items.put("cOCK", "file://cock.wav");
    itemsInfo.put("cock", "audio/x-wav");
    items.put("Promo Video from jar", "file://promo.mpg");
    itemsInfo.put("Promo Video from jar", "video/mpeg");
    }

    public void startApp() {

    // when MIDlet is started, use the item list to display elements
    for(Enumeration en = items.keys(); en.hasMoreElements() {
    itemList.append((String)en.nextElement(), null);
    }

    itemList.setCommandListener(this);

    // show the list when MIDlet is started
    display.setCurrent(itemList);
    }

    public void pauseApp() {
    // pause the player
    try {
    if(player != null) player.stop();
    } catch(Exception e) {}
    }

    public void destroyApp(boolean unconditional) {
    if(player != null) player.close(); // close the player
    }

    public void commandAction(Command command, Displayable disp) {

    // generic command handler

    // if list is displayed, the user wants to play the item
    if(disp instanceof List) {
    List list = ((List)disp);

    String key = list.getString(list.getSelectedIndex());

    // try and play the selected file
    try {
    playMedia((String)items.get(key), key);
    } catch (Exception e) {
    System.err.println("Unable to play: " + e);
    e.printStackTrace();
    }
    } else if(disp instanceof Form) {

    // if showing form, means the media is being played
    // and the user is trying to stop or pause the player
    try {

    if(command == stopCommand) { // if stopping the media play

    player.close(); // close the player
    display.setCurrent(itemList); // redisplay the list of media
    form.removeCommand(startCommand); // remove the start command
    form.addCommand(pauseCommand); // add the pause command

    } else if(command == pauseCommand) { // if pausing

    player.stop(); // pauses the media, note that it is called stop
    form.removeCommand(pauseCommand); // remove the pause command
    form.addCommand(startCommand); // add the start (restart) command
    } else if(command == startCommand) { // if restarting

    player.start(); // starts from where the last pause was called
    form.removeCommand(startCommand);
    form.addCommand(pauseCommand);
    }
    } catch(Exception e) {
    System.err.println(e);
    }
    }

    }

    /* Creates Player and plays media for the first time */
    private void playMedia(String locator, String key) throws Exception {

    // locate the actual file, we are only dealing
    // with file based media here
    String file = locator.substring(
    locator.indexOf("file://") + 6,
    locator.length());

    // create the player
    // loading it as a resource and using information about it
    // from the itemsInfo hashtable
    player = Manager.createPlayer(
    getClass().getResourceAsStream(file), (String)itemsInfo.get(key));

    // a listener to handle player events like starting, closing etc
    player.addPlayerListener(this);

    player.setLoopCount(-1); // play indefinitely
    player.prefetch(); // prefetch
    player.realize(); // realize

    player.start(); // and start
    }

    /* Handle player events */
    public void playerUpdate(Player player, String event, Object eventData) {

    // if the event is that the player has started, show the form
    // but only if the event data indicates that the event relates to newly
    // stated player, as the STARTED event is fired even if a player is
    // restarted. Note that eventData indicates the time at which the start
    // event is fired.
    if(event.equals(PlayerListener.STARTED) &&
    new Long(0L).equals((Long)eventData)) {

    //see if we can show a video control,depending on whether the media
    //is a vedio or not
    VideoControl vc = null;
    if((vc = (VideoControl)player.getControl("Video Control")) != null)
    {
    Item videoDisp =
    (Item)vc.initDisplayMode(vc.USE_GUI_PRIMITIVE, null);
    form.append(videoDisp);
    }

    display.setCurrent(form);
    } else if(event.equals(PlayerListener.CLOSED)) {

    form.deleteAll(); // clears the form of any previous controls
    }
    }
    }

Similar Threads

  1. Replies: 6
    Last Post: 2010-01-22, 09:36
  2. j2me Midlet Verification/Validation Problem
    By Nikolaos in forum Mobile Java Networking & Messaging & Security
    Replies: 5
    Last Post: 2008-06-16, 16:31
  3. linking error
    By dakosurf in forum Open C/C++
    Replies: 0
    Last Post: 2008-03-27, 09:20
  4. Replies: 2
    Last Post: 2007-02-06, 15:16
  5. Linking to J2me midlet from Symbian C++
    By Larry101 in forum Symbian
    Replies: 10
    Last Post: 2006-04-13, 19:04

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×