J2ME實現RTSP(只有在支援的手機才能用)

來源:互聯網
上載者:User
  1. import javax.microedition.lcdui.*;   
  2. import javax.microedition.midlet.*;   
  3. import javax.microedition.media.*;   
  4. import javax.microedition.media.control.*;   
  5.   
  6.   
  7. /**  
  8.  * A simple example of the MMAPI (JSR 135) support for Streaming Video  
  9.  * with the Sony Ericsson V800.  
  10.  *   
  11.  * This code is part of the Tips & Tricks section at   
  12.  * www.SonyEricsson.com/developer  
  13.  *  
  14.  * COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2005.  
  15.  * The software is the copyrighted work of Sony Ericsson Mobile Communications AB.  
  16.  * The use of the software is subject to the terms of the end-user license   
  17.  * agreement which accompanies or is included with the software. The software is   
  18.  * provided "as is" and Sony Ericsson specifically disclaim any warranty or   
  19.  * condition whatsoever regarding merchantability or fitness for a specific   
  20.  * purpose, title or non-infringement. No warranty of any kind is made in   
  21.  * relation to the condition, suitability, availability, accuracy, reliability,   
  22.  * merchantability and/or non-infringement of the software provided herein.  
  23.  *  
  24.  */  
  25. public class StreamingVideo extends MIDlet implements CommandListener, PlayerListener, Runnable{   
  26.        
  27.        
  28.     private Display myDisplay;    
  29.     private Form myForm;   
  30.     
  31.     private Thread streamingThread;   
  32.     private Player myPlayer;   
  33.     private VideoControl vc;   
  34.     private boolean running=false;   
  35.        
  36.     public StreamingVideo() {   
  37.         myDisplay = Display.getDisplay(this);   
  38.         myForm=new Form ("Streaming Test");   
  39.         myForm.addCommand(new Command("Exit", Command.EXIT,0));   
  40.         myForm.addCommand(new Command("Start", Command.OK,0));   
  41.         myForm.setCommandListener(this);    
  42.     }   
  43.       
  44.   
  45.     protected void startApp() throws MIDletStateChangeException {   
  46.         myDisplay.setCurrent(myForm);     
  47.         streamingThread = new Thread(this);   
  48.     }   
  49.   
  50.     protected void pauseApp() {}   
  51.   
  52.     protected void destroyApp(boolean unconditional) {   
  53.         try {   
  54.             myPlayer.stop();   
  55.             myPlayer.close();   
  56.         }   
  57.         catch( Exception e ) {   
  58.             log("Exception: " + e.toString());           
  59.         }   
  60.     }   
  61.        
  62.    /**  
  63.     * Inits and starts the Player for Video Streaming  
  64.     */  
  65.     private void startStreaming(){   
  66.         try{   
  67.              myPlayer = Manager.createPlayer("rtsp://yourServer/mobile/realmp3.3gp");   
  68.              myPlayer.addPlayerListener(this);   
  69.              myPlayer.realize();   
  70.               // Grab the video control and set it to the current display.   
  71.               vc = (VideoControl)myPlayer.getControl("VideoControl");   
  72.               if (vc != null) {   
  73.                 myForm.append((Item)vc.initDisplayMode(vc.USE_GUI_PRIMITIVE, null));   
  74.                 // sets the display size of the video.   
  75.                 vc.setDisplaySize(120,160);     
  76.               }             
  77.               myPlayer.start();    
  78.   
  79.          }catch(Exception e){   
  80.                 log("Exception: " + e.toString());   
  81.                 myForm.append("Exception: " + e.toString());   
  82.          }   
  83.   
  84.     }    
  85.       
  86.     public void commandAction(Command c, Displayable s){   
  87.         if(c.getCommandType()==Command.EXIT){   
  88.             running=false;   
  89.             notifyDestroyed();   
  90.         }else{   
  91.             streamingThread.start();   
  92.         }   
  93.     }   
  94.        
  95.        
  96.      /**  
  97.       * PlayerListener Interface method, logs all player event.  
  98.       */  
  99.      public void playerUpdate(Player player, String event, Object eventData){   
  100.         log(" ** playerUpdate: " + event + " **");   
  101.           
  102.      }   
  103.   
  104.      public void log(String msg){   
  105.         System.out.println(msg);   
  106.      }   
  107.         
  108.      public void run() {   
  109.          running=true;   
  110.          startStreaming();   
  111.          while(running){   
  112.              Thread.yield();   
  113.          }   
  114.      }        
  115. }  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.