⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formtrafficcam.java

📁 从另外角度来实现基于J2ME流媒体技术的无线视频传输
💻 JAVA
字号:
/*////////////////////////////////////////////////////////////////////
//MobileTrafficCamViewer文档生成日期:2005.10.24
//
//(1)概述:
//类名称:FormWebcam
//类说明:
//     MVC中的View部分,负责启动/停止自动拍照和上传照片的主力Form。
//
//所在子系统:MobileTrafficCamViewer
//
//系统总描述:
	    我们提供的Mobile TrafficCam Viewer J2ME版本 就是这么一种概念:
		一个可以下载到手机(例如Nokia7610已经确实可以下载安装并运行)的Java应用程序。
		每次选择它的“Download&Play”命令,它就会向我们的服务器发起请求(通过GPRS),
		然后下载服务器准备好的3gp格式数据,并播放它。你还可以选择Replay刚才下载的交通路况录像。


	 子系统描述:
		下面介绍Mobile TrafficCam Viewer的功能列表:
			TrafficView
				Download&Play
				StopDownload&Play
	        Settings 
	        About
	        Exit



//(2)历史记录:
//创建人: 郑昀(2005.10.24)
//联系我: Google Talk >> zhengyun@gmail.com
//Blogs:    http://blog.csdn.net/zhengyun_ustc/以及http://www.cnblogs.com/zhengyun_ustc

//(3)版权声明:
//我这个版本的Mobile TrafficCam Viewer,代码您可以借鉴,但不得用于商业用途,除非得到本人的授权。

//(4)相关资源:
1:《[J2ME]手机看交通监视器实时录像 实现说明》
3:下载源代码:

////////////////////////////////////////////////////////////////////*/
package com.ultrapower.view;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Hashtable;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
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.Player;
import javax.microedition.media.control.VideoControl;

import com.ultrapower.common.CommandResources;
import com.ultrapower.control.GUIController;
import com.ultrapower.model.ThreadGetVideo;
import com.ultrapower.model.VideoSettings;

/**********************************************************
//FormTrafficcam
//
//Class Description:
//	MVC中的View部分,负责启动/停止生成交通录像和播放的主力Form。
//
//Author:
//zhengyun@ultrapower 2005.10.24
//
**********************************************************/
public class FormTrafficCam extends Form
{
	private GUIController 	 controller;
    private static final Command m_cmdBack = new Command("BackMainMenu", 3, 0);
    private static final Command m_cmdStart = new Command("Start", "Download&Play", 4, 1);
    private static final Command m_cmdStop = new Command("Stop", "StopDownload&Play", 6, 2);
	private static final Command m_cmdPlayAgain
		= new Command("Replay", "ReplayCurrent", 6, 2);
	
    private ThreadGetVideo m_threadStreaming;
    public static FormTrafficCam m_formWebcam;
	//private WaitFlash 		 m_WaitFlash;
	private Display     	 m_display;          // The display for this MIDlet
	
	// 保留当前Tips的提示资源的ID号:
	private int m_nItemTipsAppendId = -1;

    public FormTrafficCam(String title, GUIController control)
    {
        super(title);
		controller = control;

        addCommand(m_cmdBack);
        addCommand(m_cmdStart);
		//addCommand(m_cmdPlayDemo);
        setCommandListener(new FormTrafficCamListener());
		m_formWebcam = this;
		
		m_display = controller.m_trafficcamMidlet.getCurrentDisplay();
    }

	/*
     * 内部监听器,监听器监听所有Command事件,并把事件响应推出来让控制器处理
     */
    private class FormTrafficCamListener implements CommandListener{ 
		public void commandAction(Command command, Displayable disp){
			if(command == m_cmdBack){
				controller.handleEvent(GUIController.EventID.EVENT_WEBCAM_BACK, null);
	        }
			else if(command == m_cmdStart){
				controller.handleEvent(GUIController.EventID.EVENT_STARTWEBCAM, null);    	                    	            
			}
			else if(command == m_cmdStop){
				controller.handleEvent(GUIController.EventID.EVENT_STOPWEBCAM, null);    	                    	            
			}
			else if(command == m_cmdPlayAgain){
				controller.handleEvent(GUIController.EventID.EVENT_PLAYAGAIN, null);    	                    	            
			}
			//end else
		}
    }//end inner class

    public final void StopWebcamDownload()
    {
		System.out.println("/** Enter StopWebcamDownload!");
		m_threadStreaming.setDownloadVideo(false);
		m_threadStreaming.StopPlayer();
        removeCommand(m_cmdStop);
        addCommand(m_cmdPlayAgain);
        setTitle(String.valueOf(CommandResources.getChars(
				CommandResources.TXT_T_STOPWEBCAM)));
    }
	
	public final void ShowWebcamDownload()
    {		
		System.out.println("/** Enter ShowWebcamDownload!");
		removeCommand(m_cmdStop);
	    addCommand(m_cmdStart);
		m_threadStreaming = new ThreadGetVideo(controller);
	    Thread thread;
	    (thread = new Thread(m_threadStreaming)).start();
	    setTitle(String.valueOf(CommandResources.getChars(
				CommandResources.TXT_T_STOPWEBCAM)));
		
		setProgress(String.valueOf(CommandResources.getChars(
				CommandResources.TXT_WEBCAMTIPS)), "");
    }
	
    public final void StartWebcamDownload()
    {	
		System.out.println("/** Enter StartWebcamDownload!");
		
        removeCommand(m_cmdPlayAgain);
        addCommand(m_cmdStop);
        setTitle(String.valueOf(CommandResources.getChars(
				CommandResources.TXT_T_STARTWEBCAM)));
		
		/*if(m_WaitFlash == null)
		{
			// 当前没有等候动画时,我们需要创建一个
			m_WaitFlash = new WaitFlash(controller);
			m_WaitFlash.setMessage("下载中",
					"正在下载媒体文件,请稍等...");
			m_display.setCurrent(m_WaitFlash);			
		}
		else
		{
			m_display.setCurrent(m_WaitFlash);
		}
		System.out.println("设置了等待画面!");
		*/
		
		m_threadStreaming.DeleteVideoControl();
		m_threadStreaming.setDownloadVideo(true);		
    }
	
	public void DeleteVideoControl()
	{
		m_threadStreaming.DeleteVideoControl();
	}
	
	public void PlayAgain()
	{
		removeCommand(m_cmdPlayAgain);
        addCommand(m_cmdStop);
		m_threadStreaming.PlayAgain();
	}
	
	public final synchronized void deleteTips()
	{
		if(m_nItemTipsAppendId > -1)
			delete(m_nItemTipsAppendId);
	}
			
	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));
		}
    }
	
	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);
    }
	
	/* Nokia S60 Exception
	 * Exception in thread "JMF thread: com.sun.media.ProcessEngine@11d2572[ com.sun.media.ProcessEngine@11d2572 ] 
	 * ( configureThread)" java.lang.Error: Invalid media file: File Type Box not found
	at com.nokia.phone.sdk.concept.util.mmedia.video.v3gpp.ISOMedia.readStream(ISOMedia.java)
	at com.nokia.phone.sdk.concept.util.mmedia.video.v3gpp.ISOMedia.<init>(ISOMedia.java)
	at com.nokia.phone.sdk.concept.util.mmedia.video.v3gpp.ThreeGPDeMux.getTracks(ThreeGPDeMux.java)
	at com.sun.media.BasicSourceModule.doRealize(BasicSourceModule.java:180)
	 */
}


/*
IOException: SymbianOS error = -28
?

*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -