?? threadgetvideo.java
字號(hào):
/**
//VideoIM文檔生成日期:2005.10.12
//
//(1)概述:
//類名稱:ThreadPostVideo
//類說明:
// 提供抓拍照片并發(fā)送的功能
*
//所在子系統(tǒng):VideoIM
//
//系統(tǒng)總描述:
我們提供的VideoIM手機(jī)自動(dòng)拍照上傳器J2ME版本[開源]是
一個(gè)可以下載到手機(jī)(例如Nokia7610已經(jīng)確實(shí)可以下載安裝并正常運(yùn)行)的應(yīng)用程序,
用來自動(dòng)驅(qū)動(dòng)手機(jī)攝像頭定時(shí)拍攝,并后臺(tái)將JPEG圖像(很小,大約幾KB)上傳到服務(wù)器上,
這樣就可以幫助其他系統(tǒng)工作,比如PC機(jī)上的MSN Messenger可以和你的移動(dòng)MSN Messenger
通過這種方式視頻聊天,對(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ǔ)上改編而來的,
//所以決定遵照GPL協(xié)議的大意開放源代碼,您可以自由傳播和修改,在遵照GPL協(xié)議的約束條件的前提下。
//(4)相關(guān)資源:
1:《[J2ME]VideoIM手機(jī)自動(dòng)拍照上傳器開源說明》
2:《[J2ME]VideoIM手機(jī)自動(dòng)拍照上傳器設(shè)計(jì)說明》
3:下載源代碼:
////////////////////////////////////////////////////////////////////*/
package com.ultrapower.model;
import java.io.InputStream;
import java.util.Hashtable;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.Item;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.VideoControl;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransport;
import com.ultrapower.common.CommandResources;
import com.ultrapower.control.GUIController;
/**********************************************************
//ThreadPostVideo
//
//Class Description:
// 提供抓拍照片并發(fā)送的功能
//
//Author:
// zhengyun@ultrapower 2005.10.12
//
**********************************************************/
public class ThreadGetVideo
implements Runnable {
private GUIController m_controller = null;
private VideoControl m_video = null;
private Player m_player = null;
private boolean m_bDownloadVideo;
private VideoSettings m_Settings = VideoSettings.getInstance();
private InputStream m_isInputMedia;
public ThreadGetVideo(GUIController controll)
{
System.out.println("/** Enter ThreadPostVideo Constractor!");
m_controller = controll;
m_bDownloadVideo = false;
}
public synchronized void setDownloadVideo(boolean value)
{
m_bDownloadVideo = value;
}
public final void run()
{
/* Use networking if necessary */
long lngStart;
long lngTimeTaken;
String sProgressWAITTITLE = String.valueOf(
CommandResources.getChars(CommandResources.TXT_WAITTITLE));
while(true)
{
try
{
// 我們是依靠m_bDownloadVideo來判斷是否去得到3gp并下載的.
// 如果當(dāng)前m_bDownloadVideo是false,那么本線程就只能先睡眠一段時(shí)間了.
if( m_bDownloadVideo )
{
System.out.println("/* StartWebcamDownload::開始下載實(shí)況錄像!");
/*
* Change to run locally on developer machine
*/
String serviceNamespace =
String.valueOf(m_controller.getSettings().getMyConvertServerURL());
//String.valueOf(
// CommandResources.getChars(
// CommandResources.TXT_MY_3GP_SERVER_URL));
String methodName =
String.valueOf(
CommandResources.getChars(
CommandResources.TXT_MY_3GP_SERVER_METHOD));
String methodReturnName =
String.valueOf(
CommandResources.getChars(
CommandResources.TXT_MY_3GP_SERVER_METHOD_RETURN));
String methodResponseName =
String.valueOf(
CommandResources.getChars(
CommandResources.TXT_MY_3GP_SERVER_METHOD_RESPONSE));
String downloadSiteURL =
String.valueOf(m_controller.getSettings().getDownload3gpFileSiteURL());
//String.valueOf(
// CommandResources.getChars(
// CommandResources.TXT_DOWNLOAD3GPFILE_SERVER_URL));
String serviceUrl =
serviceNamespace + "?wsdl";
System.out.println("Try add ClassMap.....");
//ClassMap classMap = new ClassMap(Soap.VER11);
//classMap.prefixMap = Soap.prefixMap[2];
System.out.println("/* Try new SoapObject */\n" +
" serviceNamespace:" + serviceNamespace);
SoapObject request = new SoapObject(serviceNamespace, methodName );
SoapSerializationEnvelope envelope =
new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut = request;
/*envelope.addMapping(serviceNamespace,
methodResponseName,
PropertyInfo.VECTOR_CLASS);*/
//(new MarshalBase64()).register(envelope);
/*envelope.addMapping(
"http://xml.apache.org/xml-soap",
"Vector",
PropertyInfo.VECTOR_CLASS);
envelope.addMapping(
"http://schemas.xmlsoap.org/soap/encoding/",
"string",
PropertyInfo.STRING_CLASS);
envelope.addMapping(
"http://schemas.xmlsoap.org/soap/encoding/",
"int",
PropertyInfo.INTEGER_CLASS);*/
/*
* 添加 web service的輸入?yún)?shù)
*/
String strMMSURL =
String.valueOf(m_controller.getSettings().getMyConvertServerURL());
//String.valueOf(
// CommandResources.getChars(
// CommandResources.TXT_URL_MMS_SERVER_1));
request.addProperty("url",
strMMSURL);
System.out.println("/* 流媒體服務(wù)器:" + strMMSURL);
String strTimeLimit =
String.valueOf(m_controller.getSettings().getLiveMediaTimeLimit());
//String.valueOf(VideoSettings.getInstance().getLiveMediaTimeLimit());
request.addProperty("timeVideo",
strTimeLimit);
System.out.println("/* 時(shí)間秒數(shù):" + strTimeLimit);
String str3gpFileName =
String.valueOf(
BuildLongFromString(
GetCID() + "thisisasalt1234")) + ".3gp";
request.addProperty("FileName",
str3gpFileName);
System.out.println("/* 文件名:" + str3gpFileName);
System.out.println("/* Try new HttpTransport \n" +
" serviceUrl:" + serviceUrl + " ;method:" + methodName);
//HttpTransport tx = new HttpTransport(serviceUrl, methodName);
//tx.setClassMap( classMap );
HttpTransport tx =
new HttpTransport(serviceUrl);
tx.debug = true;
System.out.println("Try call Streaming web service");
tx.call(serviceNamespace + "#" + methodName,
envelope);
//Object Response = (Object)tx.call(request);
System.out.println("End call Streaming web service");
KvmSerializable o3gpResponse = (KvmSerializable)envelope.bodyIn;
if(o3gpResponse != null)
{
PropertyInfo info = new PropertyInfo();
Hashtable properties = new Hashtable();
//String str3gpResponse;
int cnt = o3gpResponse.getPropertyCount();
for (int i = 0; i < cnt; i++) {
o3gpResponse.getPropertyInfo(i, properties, info);
System.out.println("info name:" + info.name);
if(methodReturnName.equalsIgnoreCase(info.name))
{
System.out.println("這正是我們要找的返回值!" );
//str3gpResponse = (String)o3gpResponse.getProperty(i);
//System.out.println("服務(wù)器告訴的URL為:" + str3gpResponse.getStringAt(0));
}
}
downloadSiteURL = downloadSiteURL + str3gpFileName;
System.out.println("服務(wù)器告訴的URL為:" + downloadSiteURL);
HttpConnection conn =
(HttpConnection)Connector.open(downloadSiteURL);
conn.setRequestMethod(HttpConnection.GET);
conn.setRequestProperty("Content-Length", "0");
conn.setRequestProperty("Accept-Language", "zh-cn");
conn.setRequestProperty("Accept-Encoding", "gzip, deflate");
conn.setRequestProperty("Connection", "close");
System.out.println("1");
m_isInputMedia =
(InputStream)conn.openInputStream();
System.out.println("2");
m_player = (Player)Manager.createPlayer(m_isInputMedia, "video/3gpp");
m_player.realize();
System.out.println("3");
m_video = (VideoControl)m_player.getControl("VideoControl");
System.out.println("4");
if(m_video != null)
{
// the player can start with the smallest latency
m_player.prefetch();
System.out.println("/** 已經(jīng)得到了VideoControl!");
// Display Video as a Form item
//
Item itemVideoWindow;
// 在USE_GUI_PRIMITIVE模式下,默認(rèn)是可見的,而在USE_DIRECT_VIDEO模式下,
// 默認(rèn)是不可見的,需要通過方法setVisible(boolean visible)來設(shè)置
(itemVideoWindow = (Item)m_video.initDisplayMode
(VideoControl.USE_GUI_PRIMITIVE, null)).setLayout(3);
m_controller.m_camForm.append(itemVideoWindow);
m_player.start();
System.out.println("/** 啟動(dòng)Player!");
}
}
m_bDownloadVideo = false;
}
lngStart = System.currentTimeMillis();
lngTimeTaken = System.currentTimeMillis() - lngStart;
if(lngTimeTaken < 100)
Thread.sleep(75 - lngTimeTaken);
}
catch(Exception exc)
{
System.out.println("/** 下載實(shí)況錄像時(shí)發(fā)生異常!");
m_bDownloadVideo = false;
exc.printStackTrace();
////////////////////////////////////////////
// 告訴控制器,不能夠下載錄像并播放
m_controller.setPlayerException(exc.getMessage()
+ "/" + exc.getClass());
m_controller.handleEventNoThrows(GUIController.EventID.EVENT_DOWNLOADDATA_ERROR,
null);
////////////////////////////////////////////
}
}
}
private String GetCID()
{
return "cid" + System.currentTimeMillis();
}
private long BuildLongFromString(String strMagic)
{
int j = 0;
for(int k = 0; k < strMagic.length(); k++)
if((k & 0x1) == 0)
j ^= j << 7 ^ strMagic.charAt(k) ^ j >> 3;
else
j ^= ~(j << 11 ^ strMagic.charAt(k) ^ j >> 5);
return (long)(j & 0x7fffffff);
}
public synchronized void PlayAgain()
{
System.out.println("/** PlayAgain!");
try
{
if(m_player != null)
{
//if(m_player.getState() == m_player.CLOSED)
{
m_player.start();
}
}
}
catch(Exception exc)
{
}
finally
{
}
}
public synchronized void StopPlayer()
{
System.out.println("/** StopPlayer!");
try
{
if(m_player != null)
{
//if(m_player.getState() == m_player.STARTED)
{
m_player.stop();
}
}
}
catch(Exception exc)
{
}
finally
{
}
}
public synchronized void DeleteVideoControl()
{
System.out.println("/** DeleteVideoControl!");
try
{
if(m_player != null)
{
//if(m_player.getState() == m_player.STARTED)
{
m_player.stop();
}
m_player.deallocate();
m_player = null;
}
}
catch(Exception exc)
{
}
finally
{
if(m_video != null)
{
m_video.setVisible(false);
m_video = null;
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -