频道直达 - 专题 - 新闻 - 技巧 - 组网 - 开发 - 安全 - web编程 - 图像 - 操作系统 - 数据库 - 教育 - 旅游 - 健康 - 时尚 - 驱动 - 软件 - 游戏 - 多媒体 - ERP - 讨论组

使用索爱V800开发流媒体应用程序

来源:developer.sonyericsson.com 作者:mingjava 出处:巧巧读书 2006-10-10 进入讨论组

        索尼爱立信的V800手机可以支持流媒体的播放,使用非常简单。如果你曾经使用MMAPI播放过声音或者做过照相应用的话,那么上手非常快。

        你要做的就是根据指定的URL来创建一个Player,然后启动这个Player。URL的格式如下:rtsp://MyServer/myVideo.3gp。下面的代码例子演示了如何使用:
private void startStreaming(){
        try{
             myPlayer = Manager.createPlayer("rtsp://MyServer/MyFile.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());
         }

    }
        我们需要注意的是进行连接服务器的时候必须在单独线程中处理,而不能在主线程。因为这样会堵塞系统。接下来你要做的就是构建一个支持RTSP的流媒体服务器,放置一个3gp格式的文件在服务器上。下面的代码演示了如何使用V800开发流媒体应用。
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import java.io.*;
import javax.microedition.lcdui.game.*;


/**
 * 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.
 *
 * Written by Jöns Weimarck, January 2005
 */
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://MyServer/MyFile.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());
         }

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

原文请参考:go streaming with v800

   巧巧读书:http://www.qqread.com/java/2006/10/u221013.html

更多文章 更多内容请看网吧流媒体服务器流媒体专题Wlan组网----家庭专题专题,或进入讨论组讨论。
收藏此文】【 】【打印】【关闭
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
巧巧读书宗旨
相关专题
最新论坛文章
站内各频道最新更新文档
站内最新制作专题
热门关键字导读
Photoshop教 程照片处理 照片制作 PS快捷键 抠图
计 算 机 故 障XP系统修复
艺 术 与 设 计设计 流媒体 设计欣赏 边框
计 算 机 安 全ARP
站内频道文章精选
巧巧电脑频道编辑信箱  告诉我们您想看的专题或文章