使用索爱V800开发流媒体应用程序
| 天极软件专题专区精选 | ||
| Google专区 | POPO专区 | QQ专区 |
| Flash MX 视频教程 | Photoshop视频教程 | 网页设计视频教程 |
| PowerPoint动画演示教程 | Excel动画教程集 | Word动画演示教程 |
| 特洛伊木马专区 | 黑客知识教程专区 | 注册表应用专区 |
| Windows API开发专区 | 网络编程专区 | VB数据库编程专区 |
| 图像与多媒体编程 | Windows Vista应用专区 | 防火墙应用专区 |
索尼爱立信的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();
}
}
}
- · 微软迫于压力 被迫放弃验证程序上报计划
- · 微软向美国政府低头 被迫支持开放文档格式
- · 欧盟即将公布最终裁决 微软难逃巨额罚款
- · 微软发布私人文件夹组件 数据可密码保护
- · 微软将提供Vista与Net Framework 3.0指导
- · 24日精选 QQ又爆新功能:Q宠伴侣
- · 25日精选 几种常见浏览器的综合评价
- · 28日精选 轻松制作音乐视频相册
- · 29日精选 突破网站限制 让你随心下载
- · 9日精选 Windows常用文件扩展名精解
- · 10日精选 KMPlayer也能“复制”加密VCD
- · 11日精选 2006世界杯桌面欣赏与下载
- · 15日精选 Adobe发布全新Flash Player 9
- · 16日精选 网络操作系统Web OS尝鲜
- · 17日精选 全面认识你的网络端口
- · 18日精选 WMP11播放器中文版多图体验
- · 19日精选 与QQ陌生人交谈的最简单方法
- · 22日精选 Google 20项服务访问量大曝光
- · 23日精选 正确卸载与重装IE的方法
- · 24日精选 伪造Cookies,收费电影免费看
- · ESB日渐火爆 微软推出更好的技术
- · 分析:Google再走微软路 欲拉拢开发者
- · 给员工自由时间 Google的聪明之道
- · Google巧夺微软技巧 不做系统也挣大钱
- · Google要求宣布李开复与微软合同无效
- · 美版权局预注册系统只支持IE和网景
- · IBM将推出实时数据备份软件
- · Google在网络搜索市场领先优势缩小
- · 阿里巴巴瞄准IM软件 马云明年底灭掉MSN
- · 网络世界:CRM能管什么
- · 雅虎扩展本地搜索 与Google和AOL竞争
- · 搜索市场渐饱和 Google业务单一危险
- · 评论:客观看待博客
- · 美大兵博客泄军机 总参谋长下令堵漏
- · 博客,越“俗”越有吸引力?
- · Gartner称软件开发经历重大转变
- · 微软让步 虚拟服务器SP1将支持Linux
- · 微软信赖Windows承诺:尚未实现的梦
