?? threadpostvideo.java
字號(hào):
/**
//VideoIM文檔生成日期:2005.10.12
//
//(1)概述:
//類名稱:ThreadPostVideo
//類說(shuō)明:
// 提供抓拍照片并發(fā)送的功能
*
//所在子系統(tǒng):VideoIM
//
//系統(tǒng)總描述:
我們提供的VideoIM手機(jī)自動(dòng)拍照上傳器J2ME版本[開(kāi)源]是
一個(gè)可以下載到手機(jī)(例如Nokia7610已經(jīng)確實(shí)可以下載安裝并正常運(yùn)行)的應(yīng)用程序,
用來(lái)自動(dòng)驅(qū)動(dòng)手機(jī)攝像頭定時(shí)拍攝,并后臺(tái)將JPEG圖像(很小,大約幾KB)上傳到服務(wù)器上,
這樣就可以幫助其他系統(tǒng)工作,比如PC機(jī)上的MSN Messenger可以和你的移動(dòng)MSN Messenger
通過(guò)這種方式視頻聊天,對(duì)方可以每隔十幾秒鐘看到你的手機(jī)所看到的畫面了。
子系統(tǒng)描述:
VideoIM的功能列表:
1:我要MobileWebCam
啟動(dòng)MobileWebCam
停止MobileWebCam
2:MobileWebCam設(shè)置
3:關(guān)于我
4:退出
//(2)歷史記錄:
//創(chuàng)建人: 鄭昀(2005.10.12)
//聯(lián)系我: Google Talk >> zhengyun@gmail.com
//Blogs: http://blog.csdn.net/zhengyun_ustc/以及http://www.cnblogs.com/zhengyun_ustc
//(3)版權(quán)聲明:
//由于我這個(gè)版本的VideoIM手機(jī)自動(dòng)拍照上傳器也是基于Mowecam的設(shè)計(jì)理念基礎(chǔ)上改編而來(lái)的,
//所以決定遵照GPL協(xié)議的大意開(kāi)放源代碼,您可以自由傳播和修改,在遵照GPL協(xié)議的約束條件的前提下。
//(4)相關(guān)資源:
1:《[J2ME]VideoIM手機(jī)自動(dòng)拍照上傳器開(kāi)源說(shuō)明》
2:《[J2ME]VideoIM手機(jī)自動(dòng)拍照上傳器設(shè)計(jì)說(shuō)明》
3:下載源代碼:
////////////////////////////////////////////////////////////////////*/
package com.ultrapower.model;
import javax.microedition.media.MediaException;
import javax.microedition.media.control.VideoControl;
import com.ultrapower.common.CommandResources;
import com.ultrapower.control.GUIController;
import com.ultrapower.tools.HttpUploadCapturedBuffer;
import com.ultrapower.view.FormPostProgress;
import com.ultrapower.view.WaitFlash;
/**********************************************************
//ThreadPostVideo
//
//Class Description:
// 提供抓拍照片并發(fā)送的功能
//
//Author:
// zhengyun@ultrapower 2005.10.12
//
**********************************************************/
public class ThreadPostVideo
implements Runnable {
private GUIController m_controller = null;
private VideoControl m_video = null;
public boolean m_bCaptureVideo;
private VideoSettings m_Settings = VideoSettings.getInstance();
public ThreadPostVideo(GUIController controll,
VideoControl videocontrol)
{
System.out.println("/** Enter ThreadPostVideo Constractor!");
m_controller = controll;
m_bCaptureVideo = true;
m_video = videocontrol;
}
public final void run()
{
String sProgressWAITTITLE = String.valueOf(
CommandResources.getChars(CommandResources.TXT_WAITTITLE));
while(m_bCaptureVideo)
try
{
System.out.println("/** 開(kāi)始啟動(dòng)攝像頭的捕獲!");
// getSnapshot(null) => creates an byte[] of the new image. The default encoding is png. The default size is 160x120 Pixel.
// getSnapshot("encoding=bmp") The encoding is bmp. The size is per default 160x120
// getSnapshot("encoding=bmp&width=80&height=60") The enconding is bmp. The size is 80x60
// gif, jpeg, png, bmp images can be created
// the size of the images depends on the memory. No matter of the size the relationship must be 4:3
byte abImageData[];
if((abImageData = m_video.getSnapshot(
"encoding=" +
String.valueOf(m_Settings.getSnapshotImageType())
+ "&width=" +
m_Settings.getSnapshotImageWidth() +
"&height=" +
m_Settings.getSnapshotImageHeight())) != null)
/*byte abImageData[] = m_video.getSnapshot(null);
System.out.println("/** 抓拍一張!");
if(abImageData != null)*/
{
String strDataLength = String.valueOf(abImageData.length);
System.out.println("/** 顯示要上傳的字節(jié)數(shù)!" + strDataLength);
/*
* 在這個(gè)線程中New出來(lái)一個(gè)FormPostProgress,
* 這是被逼出來(lái)的
*/
/*WaitFlash waitFlash = WaitFlash.getInstance(m_controller);
waitFlash.setTitle(
sProgressWAITTITLE
+ strDataLength);
m_controller.setCurrent(waitFlash);*/
//m_controller.setProgressForm(progressForm);
//////////////////////////////////////////
// 告訴控制器,需要顯示進(jìn)度條Form了,而且要告知總的字節(jié)數(shù)
m_controller.setPostDataTotalLength(strDataLength);
m_controller.handleEventNoThrows(GUIController.EventID.EVENT_POSTDATA,
null);
////////////////////////////////////////////
String strServerResponse;
if((strServerResponse =
UploadCapturedBuffer(abImageData)).startsWith("ERROR="))
{
strServerResponse =
strServerResponse.substring(
strServerResponse.indexOf("ERROR=") + "ERROR=".length());
////////////////////////////////////////////
// 告訴控制器,出錯(cuò)了
m_controller.setRemoteServerResponse(strServerResponse);
m_controller.handleEventNoThrows(GUIController.EventID.EVENT_POSTDATA_ERROR,
null);
////////////////////////////////////////////
}
else
{
////////////////////////////////////////////
// 告訴控制器,成功了
m_controller.handleEventNoThrows(GUIController.EventID.EVENT_POSTDATA_SUCC,
null);
////////////////////////////////////////////
}
Thread.currentThread();
// 隔規(guī)定的時(shí)間后,再讓線程抓拍照片
Thread.sleep(
m_Settings.getTimerSnapshot() * 1000);
}
else
{
System.out.println("/** 停止攝像頭的捕獲!");
m_bCaptureVideo = false;
////////////////////////////////////////////
// 告訴控制器,不能夠捕獲圖像
m_controller.setSnapshotException("getSnapShot函數(shù)調(diào)用失敗!");
m_controller.handleEventNoThrows(GUIController.EventID.EVENT_CANNOT_SNAPSHOT,
null);
////////////////////////////////////////////
}
}
catch(MediaException mediaexception)
{
m_bCaptureVideo = false;
////////////////////////////////////////////
// 告訴控制器,不能夠捕獲圖像
m_controller.setSnapshotException(mediaexception.getMessage());
m_controller.handleEventNoThrows(GUIController.EventID.EVENT_CANNOT_SNAPSHOT,
null);
////////////////////////////////////////////
}
catch(InterruptedException interruptedexception)
{
m_bCaptureVideo = false;
////////////////////////////////////////////
// 告訴控制器,不能夠捕獲圖像
m_controller.setSnapshotException(interruptedexception.getMessage());
m_controller.handleEventNoThrows(GUIController.EventID.EVENT_CANNOT_SNAPSHOT,
null);
////////////////////////////////////////////
}
catch(SecurityException securityexception)
{
m_bCaptureVideo = false;
////////////////////////////////////////////
// 告訴控制器,不能夠捕獲圖像
m_controller.setSnapshotException(securityexception.getMessage());
m_controller.handleEventNoThrows(GUIController.EventID.EVENT_CANNOT_SNAPSHOT,
null);
////////////////////////////////////////////
}
}
private String UploadCapturedBuffer(byte abyteImageData[])
{
System.out.println("/** Enter UploadCapturedBuffer!");
HttpUploadCapturedBuffer upload;
return (upload = new HttpUploadCapturedBuffer(abyteImageData,
m_controller)).upload();
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -