使用索爱V800开发流媒体应用程序
2008-01-05 09:01:34 来源:WEB开发网索尼爱立信的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);
}
- ››使用脚本恢复WinXP系统的用户登录密码
- ››开发学院教你用SQL 语句最快速清空MySQL 数据表的...
- ››使用phpMyadmin创建数据库及独立数据库帐号
- ››使用Zend Framework框架中的Zend_Mail模块发送邮件...
- ››使用cout标准输出如何控制小数点后位数
- ››使用nofollow标签做SEO的技巧
- ››使用 WebSphere Message Broker 的 WebSphere Tra...
- ››使用SQL Server事件探查器做应用程序的性能分析
- ››使用SQL Server事件探查器分析死锁原因
- ››使用纯文本文件打造WCF服务
- ››使用 Dojo 开发定制 Business Space 小部件,第 4...
- ››使用 ADDRESS 与 INDIRECT函数查询信息
赞助商链接