J2ME实现RTSP(只有在支持的手机才能用)

本文介绍了一个使用J2ME MMAPI实现的简单RTSP视频流播放示例,适用于Sony Ericsson V800手机。代码展示了如何初始化和播放RTSP流,并提供了异常处理方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近在研究J2ME实现RTSP协议,在索爱开发网站中看到一个类,但只能用于支持RTSP协议的手机,大部分手机需利用J2ME MMAPI实现,而对于自己实现的RTSP,虽然做了一些测试,调通了一点,但还没能真正运行,不知播放的效果如何,会不会像HTTP连接那么烂!

 

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


/**
 * A simple example of the MMAPI (JSR 135) support for Streaming Video
 * with the Sony Ericsson V800.
 * 
 * This code is part of the Tips & Tricks section at 
 * www.SonyEricsson.com/developer
 *
 * COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2005.
 * The software is the copyrighted work of Sony Ericsson Mobile Communications AB.
 * The use of the software is subject to the terms of the end-user license 
 * agreement which accompanies or is included with the software. The software is 
 * provided "as is" and Sony Ericsson specifically disclaim any warranty or 
 * condition whatsoever regarding merchantability or fitness for a specific 
 * purpose, title or non-infringement. No warranty of any kind is made in 
 * relation to the condition, suitability, availability, accuracy, reliability, 
 * merchantability and/or non-infringement of the software provided herein.
 *
 */
public class StreamingVideo extends MIDlet implements CommandListener, PlayerListener, Runnable{
    
    
    private Display myDisplay; 
    private Form myForm;
 
    private Thread streamingThread;
    private Player myPlayer;
    private VideoControl vc;
    private boolean running=false;
    
    public StreamingVideo() {
        myDisplay = Display.getDisplay(this);
        myForm=new Form ("Streaming Test");
        myForm.addCommand(new Command("Exit", Command.EXIT,0));
        myForm.addCommand(new Command("Start", Command.OK,0));
        myForm.setCommandListener(this); 
    }
   

    protected void startApp() throws MIDletStateChangeException {
        myDisplay.setCurrent(myForm);  
        streamingThread = new Thread(this);
    }

    protected void pauseApp() {}

    protected void destroyApp(boolean unconditional) {
        try {
            myPlayer.stop();
            myPlayer.close();
        }
        catch( Exception e ) {
            log("Exception: " + e.toString());        
        }
    }
    
   /**
    * Inits and starts the Player for Video Streaming
    */
    private void startStreaming(){
        try{
             myPlayer = Manager.createPlayer("rtsp://yourServer/mobile/realmp3.3gp");
             myPlayer.addPlayerListener(this);
             myPlayer.realize();
              // Grab the video control and set it to the current display.
              vc = (VideoControl)myPlayer.getControl("VideoControl");
              if (vc != null) {
                myForm.append((Item)vc.initDisplayMode(vc.USE_GUI_PRIMITIVE, null));
                // sets the display size of the video.
                vc.setDisplaySize(120,160);  
              }          
              myPlayer.start(); 

         }catch(Exception e){
                log("Exception: " + e.toString());
                myForm.append("Exception: " + e.toString());
         }

    } 
   
    public void commandAction(Command c, Displayable s){
        if(c.getCommandType()==Command.EXIT){
            running=false;
            notifyDestroyed();
        }else{
            streamingThread.start();
        }
    }
    
    
     /**
      * PlayerListener Interface method, logs all player event.
      */
     public void playerUpdate(Player player, String event, Object eventData){
        log(" ** playerUpdate: " + event + " **");
       
     }

     public void log(String msg){
        System.out.println(msg);
     }
     
     public void run() {
         running=true;
         startStreaming();
         while(running){
             Thread.yield();
         }
     }     
}

 

开发RTSP的相关资料:

Experiments in Streaming Content in Java ME(1) http://fonter.iteye.com/blog/425372
Experiments in Streaming Content in Java ME(2) http://fonter.iteye.com/blog/425392
Experiments in Streaming Content in Java ME(3) http://fonter.iteye.com/blog/425427

 

 

keyRepeated和keyPressed处理 http://fonter.iteye.com/blog/433408 

少用System.out.println()吗?http://fonter.iteye.com/blog/423871
读取流最快方式 http://fonter.iteye.com/blog/422412
java简单解析docx、pptx、xlsx文档 http://fonter.iteye.com/blog/420319
Log4j在Java WebApp的配置 http://fonter.iteye.com/blog/418570
J2ME to android之学习笔记 http://fonter.iteye.com/blog/416112
安装Jar提示“jar文件无效”的另一个奇怪原因 http://fonter.iteye.com/blog/414188
J2ME代码认证证书的支持情况 http://fonter.iteye.com/blog/413357
S40平台播放多媒体时内存优化 http://fonter.iteye.com/blog/413022
SUN的J2ME源代码下载 http://fonter.iteye.com/blog/412094

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值