You Are Here:

Community: Developer Discussion Boards

#1 Old plz help me with this code of a simpleplayer - 2006-12-06, 18:40

Join Date: Jan 2006
Posts: 16
toonaughty85
Offline
Registered User
hello,
The following code given in the MMAPI article @sun.com(http://developers.sun.com/techtopics...mmapioverview/) isn't working fine for me when i m running it on the default colour phone of WKT2.2.

Code:
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import javax.microedition.midlet.*;

public class PlayerMIDlet extends MIDlet implements 
  CommandListener, PlayerListener, Runnable {
   private Display display;
   private Form form;
   private TextField url;
   private Command start = new Command("Play", 
     Command.SCREEN, 1);
   private Command stop = new Command("Stop", 
     Command.SCREEN, 2);
   private Player player;
      
   public PlayerMIDlet() {
      display = Display.getDisplay(this);
      form = new Form("Demo Player");
      url = new TextField("Enter URL:", "", 100, 
	    TextField.URL);
      form.append(url);
      form.addCommand(start);
      form.addCommand(stop);
      form.setCommandListener(this);
      display.setCurrent(form);
   }

   protected void startApp() {
      try {
         if(player != null && player.getState() == 
		   Player.PREFETCHED) {
            player.start();
         } else {
            defplayer();
            display.setCurrent(form);
         }
      } 
      catch(MediaException me) {
         reset();
      }
   }

   protected void pauseApp() {
      try {
         if(player != null && player.getState() == 
		   Player.STARTED) {
            player.stop();
         } else {
            defplayer();
         }
      } 
      catch(MediaException me) {
         reset();
      }
   }

   protected void destroyApp(
      boolean unconditional) {
      form = null;
      try {
         defplayer();
      } 
      catch(MediaException me) {
      }
   }

   public void playerUpdate(Player player, 
     String event, Object data) {
      if(event == PlayerListener.END_OF_MEDIA) {
         try {
            defplayer();
         } 
         catch(MediaException me) {
         }
         reset();
      }
   }

   public void commandAction(Command c, Displayable d) {
      if(c == start) {       
         start();
      } else if(c == stop) {
         stopPlayer();
      }
   }

   public void start() {
      Thread t = new Thread(this);
      t.start();
   }

   // to prevent blocking, all communication should 
   // be in a thread
   // and not in commandAction
   public void run() {
      play(getURL());
   }

   String getURL() { 
     return url.getString();
   }

   void play(String url) {
      try {
         VideoControl vc;
         defplayer();
         // create a player instance
         player = Manager.createPlayer(url);
         player.addPlayerListener(this);
         // realize the player
         player.realize();
         vc = (VideoControl)player.getControl(
		   "VideoControl");
         if(vc != null) {
            Item video = (Item)vc.initDisplayMode(
			  vc.USE_GUI_PRIMITIVE, null);
            Form v = new Form("Playing Video...");
            StringItem si = new StringItem("Status: ", 
			  "Playing...");
            v.append(si);
            v.append(video);
            display.setCurrent(v);
         }
         player.prefetch();
         player.start();
      }
      catch(Throwable t) {
         reset();
      }
   }

   void defplayer() throws MediaException {
      if (player != null) {
         if(player.getState() == Player.STARTED) {
            player.stop();
         }
         if(player.getState() == Player.PREFETCHED) {
            player.deallocate();
         }
         if(player.getState() == Player.REALIZED || 
		    player.getState() == Player.UNREALIZED) {
            player.close();
         }
      }
      player = null;
   }

   void reset() {
      player = null;
   }

   void stopPlayer() {
      try {
         defplayer();
      } 
      catch(MediaException me) {
      }
      reset();
   }
}
When i try to run it with the URLs specified in thr,its asking whether to use airtime and does nothing after pressing YES.
(The URLs are
http://java.sun.com/products/java-me...a/test-wav.wav
http://java.sun.com/products/java-me.../test-mpeg.mpg )



Also ,wat all changes am i supposed to make in the above code, if i want to play the files in my JAR??

Thanx
Reply With Quote

#2 Old Re: plz help me with this code of a simpleplayer - 2006-12-13, 11:50

Join Date: Feb 2006
Posts: 689
soku123
Offline
Super Contributor
Hi,
where r u calling the play()method.from the code u posted i didnt see where u called the play method.
Thanks
Soku
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

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

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
stupid error! bojkar General Symbian C++ 1 2006-12-14 06:47
plz check this code. chishti.hameed General Symbian C++ 1 2005-08-03 11:58
How to handle a response with HTTP status code 100 (Continue)? danieldkim Mobile Java General 5 2004-01-19 11:54
Why is client code to CSocketEngine hanging at Access Point dialogue? nawkboy Symbian Networking & Messaging 2 2003-03-11 12:16
Why is client code to CSocketEngine hanging at Access Point dialogue? nawkboy General Symbian C++ 0 2003-02-24 05:00

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d134434X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtopicQUqfnTopicZmediaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ