📄 formwebcam.java
字号:
/*////////////////////////////////////////////////////////////////////
//文档生成日期:2005.10.12
//
//(1)概述:
//类名称:FormWebcam
//类说明:
// MVC中的View部分,负责启动/停止自动拍照和上传照片的主力Form。
//
//所在子系统:VideoIM
//
//系统总描述:
我们提供的VideoIM手机自动拍照上传器J2ME版本[开源]是
一个可以下载到手机(例如Nokia7610已经确实可以下载安装并正常运行)的应用程序,
用来自动驱动手机摄像头定时拍摄,并后台将JPEG图像(很小,大约几KB)上传到服务器上,
这样就可以帮助其他系统工作,比如PC机上的MSN Messenger可以和你的移动MSN Messenger
通过这种方式视频聊天,对方可以每隔十几秒钟看到你的手机所看到的画面了。
子系统描述:
VideoIM的功能列表:
1:我要MobileWebCam
启动MobileWebCam
停止MobileWebCam
2:MobileWebCam设置
3:关于我
4:退出
//(2)历史记录:
//创建人: 郑昀(2005.10.07)
//联系我: Google Talk >> zhengyun@gmail.com
//Blogs: http://blog.csdn.net/zhengyun_ustc/以及http://www.cnblogs.com/zhengyun_ustc
//(3)版权声明:
//由于我这个版本的VideoIM手机自动拍照上传器也是基于Mowecam的设计理念基础上改编而来的,
//所以决定遵照GPL协议的大意开放源代码,您可以自由传播和修改,在遵照GPL协议的约束条件的前提下。
//(4)相关资源:
1:《[J2ME]VideoIM手机自动拍照上传器开源说明》
2:《[J2ME]VideoIM手机自动拍照上传器设计说明》
3:下载源代码:
////////////////////////////////////////////////////////////////////*/
package com.ultrapower.view;
import java.io.IOException;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.StringItem;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.control.VideoControl;
import com.ultrapower.common.CommandResources;
import com.ultrapower.control.GUIController;
import com.ultrapower.model.ThreadPostVideo;
/**********************************************************
//FormWebcam
//
//Class Description:
// MVC中的View部分,负责启动/停止自动拍照和上传照片的主力Form。
//
//Author:
//zhengyun@ultrapower 2005.10.12
//
**********************************************************/
public class FormWebcam extends Form
{
private GUIController controller;
private static final Command cmdBack = new Command("返回", 3, 0);
private static final Command cmdStart = new Command("启动", "启动Webcam", 4, 1);
private static final Command cmdStop = new Command("停止", "停止webcam", 6, 2);
private VideoControl video;
private Player player;
private ThreadPostVideo threadPost;
public static FormWebcam formWebcam;
// 保留当前Tips的提示资源的ID号:
private int m_nItemTipsAppendId = -1;
public FormWebcam(String title, GUIController control)
{
super(title);
controller = control;
addCommand(cmdBack);
addCommand(cmdStart);
setCommandListener(new FormWebcamListener());
formWebcam = this;
}
/*
* 内部监听器,监听器监听所有Command事件,并把事件响应推出来让控制器处理
*/
private class FormWebcamListener implements CommandListener{
public void commandAction(Command command, Displayable disp){
if(command == cmdBack){
controller.handleEvent(GUIController.EventID.EVENT_WEBCAM_BACK, null);
}
else if(command == cmdStart){
controller.handleEvent(GUIController.EventID.EVENT_STARTWEBCAM, null);
}
else if(command == cmdStop){
controller.handleEvent(GUIController.EventID.EVENT_STOPWEBCAM, null);
}
//end else
}
}//end inner class
public final void StopWebcamSnapshot()
{
threadPost.m_bCaptureVideo = false;
removeCommand(cmdStop);
addCommand(cmdStart);
setTitle(String.valueOf(CommandResources.getChars(
CommandResources.TXT_T_STOPWEBCAM)));
}
public final void StartWebcamSnapshot()
{
System.out.println("/** Enter FormWebcam::StartWebcamSnapshot!");
removeCommand(cmdStart);
addCommand(cmdStop);
threadPost = new ThreadPostVideo(controller, video);
Thread thread;
(thread = new Thread(threadPost)).start();
setTitle(String.valueOf(CommandResources.getChars(
CommandResources.TXT_T_STARTWEBCAM)));
}
public void StartCapture()
throws MediaException, IOException, SecurityException
{
System.out.println("/** Enter FormWebcam::StartCapture!");
player = Manager.createPlayer("capture://video");
player.realize();
video = (VideoControl)player.getControl("VideoControl");
if(video != null)
{
System.out.println("/** 已经得到了VideoControl!");
Item itemVideoWindow;
// 在USE_GUI_PRIMITIVE模式下,默认是可见的,而在USE_DIRECT_VIDEO模式下,
// 默认是不可见的,需要通过方法setVisible(boolean visible)来设置
(itemVideoWindow = (Item)video.initDisplayMode(
0, null)).setLayout(3);
append(itemVideoWindow);
StringItem siSelect;
(siSelect = new StringItem("",
String.valueOf(CommandResources.getChars(
CommandResources.TXT_WEBCAMTIPS)))).setLayout(3);
m_nItemTipsAppendId = append(siSelect);
System.out.println("/** 启动Player!");
player.start();
}
video.setVisible(true);
}
public final synchronized void setProgress(
String strProgressTitle,
String strMessage)
{
if(m_nItemTipsAppendId < 0)
{
m_nItemTipsAppendId = append(new StringItem(strProgressTitle, strMessage));
}
else
{
set(m_nItemTipsAppendId, new StringItem(strProgressTitle, strMessage));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -