j2me video streaming

hi all,
i am looking for an example/source code or a link about video streaming in j2me. although i have searched in google, not found a useful sample.

thanks in advance.

komputerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

keyurkarnikCommented:
You should use the MMAPI of J2ME for this purpose. Its very simple to use.
0
keyurkarnikCommented:
Try this piece of code :

It works just fine.
Compile it using Eclipse and MTJ (Mobile Tools for JAVA) or whichever tools you are comfortable with.
import java.util.Enumeration;
import java.util.Hashtable;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.List;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.PlayerListener;
import javax.microedition.media.control.VideoControl;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class MMMidlet extends MIDlet implements CommandListener
{

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

   private Hashtable items;

   public MMMidlet()
   {

      display = Display.getDisplay(this);

     
      itemList = new List("Select an item to play", List.IMPLICIT);


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

     
      items = new Hashtable();

      
      items.put("Sample Video from Web", "http://home.in.tum.de/~paula/mpeg/wg_gdo_1.mpg");
      //items.put("Video 2", "http://link.to.video2"); //add more items here
   }

   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()
   {
   }

   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));
         }
         catch (Exception e)
         {
            System.err.println("Unable to play: " + e);
            e.printStackTrace();
         }
      }

   }


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

      PlayerManager manager = new PlayerManager(form, itemList, locator, display);
      form.setCommandListener(manager);
      Thread runner = new Thread(manager);
      runner.start();
   }

   /* 
    * @see javax.microedition.midlet.MIDlet#destroyApp(boolean)
    * 
    * destroyApp
    * @param unconditional
    * @throws MIDletStateChangeException
    */
   protected void destroyApp(boolean unconditional) throws MIDletStateChangeException
   {
   }
}

class PlayerManager implements Runnable, CommandListener, PlayerListener
{

   Form form;
   List list;
   Player player;
   String locator;
   Display display;

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

   public PlayerManager(Form form, List list, String locator, Display display)
   {
      this.form = form;
      this.list = list;
      this.locator = locator;
      this.display = display;

      
      stopCommand = new Command("Stop", Command.STOP, 1);
      pauseCommand = new Command("Pause", Command.ITEM, 1);
      startCommand = new Command("Start", Command.ITEM, 1);

     
      form.addCommand(stopCommand);
      form.addCommand(pauseCommand);
   }

   public void run()
   {

      try
      {
         
         Alert alert = new Alert("Loading. Please wait ....");
         alert.setTimeout(Alert.FOREVER);
         display.setCurrent(alert);

         player = Manager.createPlayer(locator);

        
         player.addPlayerListener(this);

         player.setLoopCount(-1);
         player.prefetch();
         player.realize(); 

         player.start(); 
      }
      catch (Exception e)
      {
         System.err.println(e);
         e.printStackTrace();
      }
   }

   public void commandAction(Command command, Displayable disp)
   {
      if (disp instanceof Form)
      {
         
         try
         {
            if (command == stopCommand)
            { 
               player.close(); // close the player
               display.setCurrent(list); // redisplay the list of media
               form.removeCommand(startCommand); // remove the start command
               form.removeCommand(pauseCommand); // remove the pause command
               form.removeCommand(stopCommand); // and the stop command
            }
            else if (command == pauseCommand)
            { 
               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)
            { 
               player.start(); // starts from where the last pause was called
               form.removeCommand(startCommand);
               form.addCommand(pauseCommand);
            }
         }
         catch (Exception e)
         {
            System.err.println(e);
         }
      }
   }

  
   public void playerUpdate(Player player, String event, Object eventData)
   {

     
      if (event.equals(PlayerListener.STARTED) && new Long(0L).equals((Long) eventData))
      {

        
         VideoControl vc = null;
         if ((vc = (VideoControl) player.getControl("VideoControl")) != 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
      }
   }

}

Open in new window

0
keyurkarnikCommented:
And here is a link for you to learn some more :

http://developers.sun.com/mobility/midp/articles/mmapioverview/
0
komputerAuthor Commented:
hi keyurkarnik,
in fact i had found familar examples on
http://today.java.net/pub/a/today/2005/09/27/j2me4.html
and other sides. they work well on wtk emulator but when i deploy in nokia n73 video plays  but voice is not played and fullscreen is failed either. i tried a lot examples but not works.

do you have any iade about this problems?

thanks.
0
komputerAuthor Commented:
i fixed voice problem, the only thing left is fullscreen problem.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.