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

📄 mediaplayer.as

📁 flash as3 视频点播代码 支持FMS3.5
💻 AS
字号:
/*
 * (C) Copyright 2008 Adobe Systems Incorporated. All Rights Reserved.
 *
 * NOTICE:  Adobe permits you to use, modify, and distribute this file in accordance with the 
 * terms of the Adobe license agreement accompanying it.  If you have received this file from a 
 * source other than Adobe, then your use, modification, or distribution of it requires the prior 
 * written permission of Adobe. 
 * THIS CODE AND INFORMATION IS PROVIDED "AS-IS" WITHOUT WARRANTY OF
 * ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 *
 *  THIS CODE IS NOT SUPPORTED BY Adobe Systems Incorporated.
 *
 */

package {
	import flash.display.Sprite;
	import flash.net.NetConnection;
	import flash.events.NetStatusEvent;
	import flash.events.AsyncErrorEvent;
	import flash.net.NetStream;
	import flash.media.SoundTransform;
	//import flash.net.;
	import flash.media.Video;
	//import flash.media.VideoPlayer;
	import flash.events.MouseEvent;
	import fl.events.SliderEvent;
	import flash.events.TimerEvent;
	// import flash.media.Video;
	import flash.utils.Timer;
	import fl.video.FLVPlayback;
	import fl.video.VideoPlayer;

	import flash.display.StageDisplayState;
	import flash.events.FullScreenEvent;
	import flash.geom.Rectangle;
	public class MediaPlayer extends Sprite {
		var nc:NetConnection;
		var ns:NetStream;
		var video:VideoPlayer;
		var tflag:String;
		var fflag:String;
		var tmpvmv:String;
		var myVideo:FLVPlayback;
		private var customClient:Object;
		private var videoLength:Number;
		private var timer:Timer;
		var tnowtime:String;
		var tltime:String;
		public function MediaPlayer() {
			initCon();
			initMP();
			//testPback();
		}


		public function initMP() {

			initCon();
			addAllLis();

			tflag="f";
			fflag="f";

			tmpvmv=loaderInfo.parameters["vmv"];
			if (tmpvmv==null) {
				tmpvmv="1/1";

			}
			//edt_put.text=tmpvmv;


			timer=new Timer(10);

			timer.addEventListener(TimerEvent.TIMER,timerHandler);

			seekBar1.addEventListener(SliderEvent.CHANGE,sliderChangeHandler);

			seekBar1.addEventListener(SliderEvent.THUMB_PRESS,sliderPressHandler);
			

		}

		public function initCon() {
			nc=new NetConnection  ;

			nc.connect("rtmp://192.168.180.76:1935/mediaplayer");
		}
		private function timerHandler(event:TimerEvent):void {

			seekBar1.value=ns.time;
			getTmStr(ns.time);
			//timeInfo.text=Math.round(ns.time).toString()+"/"+videoLength.toString();
			timeInfo.text=tnowtime+"/"+tltime;

		}

		private function getTmStr(ttt:Number) {
			var tt1:int=ttt;
			var tt2:int=videoLength;
			var tt11:int=tt1/3600;
			var tt12:int=(tt1-tt11*3600)/60;
			var tt13:int=tt1-tt11*3600-tt12*60;
			var tt21:int=tt2/3600;
			var tt22:int=(tt2-tt21*3600)/60;
			var tt23:int=tt2-tt21*3600-tt22*60;
			tnowtime=tt11+":"+tt12+":"+tt13;
			tltime=tt21+":"+tt22+":"+tt23;

		}

		public function addAllLis() {
			nc.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler);
           vvVol.addEventListener(SliderEvent.CHANGE,vvVolUp);
			btFull.addEventListener(MouseEvent.CLICK,btFullHandler);
			vv_pl.addEventListener(MouseEvent.CLICK,vvplHandler);
			vv_stop.addEventListener(MouseEvent.CLICK,vvstopHandler);
			vv_pause.addEventListener(MouseEvent.CLICK,vvpauseHandler);
		}

		public function vvVolUp(event:SliderEvent):void {
			var tvol:Number;
			var tvol1:Number=vvVol.value;
			tvol=tvol1/10;
			var st:SoundTransform=new SoundTransform(tvol,0);
			trace(tvol);
			ns.soundTransform=st;

		}



		public function btFullHandler(event:MouseEvent):void {
			if (fflag=="f") {
				fflag="t";
				stage.displayState=StageDisplayState.FULL_SCREEN;
				video.x=0;
				
			} else {
				stage.displayState=StageDisplayState.NORMAL;
				fflag="f";
			}
		}

		public function vvplHandler(event:MouseEvent):void {
			ns.resume();
		}
		public function vvstopHandler(event:MouseEvent):void {
			ns.close();
		}
		public function vvpauseHandler(event:MouseEvent):void {
			ns.pause();
		}

		private function netStatusHandler(event:NetStatusEvent):void {
			//lb_show1.text="event.info.level: " + event.info.level + "\n", "event.info.code: " + event.info.code;

			switch (event.info.code) {
				case "NetConnection.Connect.Success" :
					// Call doPlaylist() or doVideo() here.
					//   doPlaylist(nc);
					if (tflag=="f") {
						tflag="t";
						doVideo(nc);

					}
					break;
				case "NetConnection.Connect.Failed" :
					// Handle this case here.
					break;
				case "NetConnection.Connect.Rejected" :
					// Handle this case here.
					break;
				case "NetStream.Play.Stop" :
					// Handle this case here.
					break;
				case "NetStream.Play.StreamNotFound" :
					// Handle this case here.
					break;
				case "NetStream.Publish.BadName" :
					trace("The stream name is already used");
					// Handle this case here.
					break;
			}
		}


		// play a recorded stream on the server
		private function doVideo(nc:NetConnection):void {
			//tmpvmv=edt_put.text;
			//lb_show1.text=tmpvmv;

			if (ns!=null) {
				ns.close();
			}
			ns=new NetStream(nc);
			ns.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler);
			customClient=new Object  ;

			customClient.onMetaData=metaDataHandler;
			ns.client=customClient;

			var video:VideoPlayer=new VideoPlayer  ;
			video.width=680;
			video.height=480;
			video.attachNetStream(ns);
			//video.
			ns.bufferTime=10;
			ns.play(tmpvmv,0,-1,true);

			//trace(video.totalTime);
			// ns.pause();
			addChild(video);
			//vvVol.scaleX=0.3;
			//var screenRectangle:Rectangle = new Rectangle(video.x, video.y, video.width, video.height); 
			//  stage.fullScreenSourceRect = screenRectangle; 
			//stage.displayState = StageDisplayState.FULL_SCREEN;
			//stage.displayState = StageDisplayState.NORMAL;
			timer.start();

		}


		private function metaDataHandler(infoObject:Object):void {



			videoLength=Math.round(Number(infoObject.duration));
			seekBar1.maximum=videoLength;
			vvVol.maximum=10;
			vvVol.value=5;
			var st:SoundTransform=new SoundTransform(0.5,0);
            ns.soundTransform=st;
		}

		private function sliderChangeHandler(event:SliderEvent):void {

			ns.seek(event.currentTarget.value);
			ns.resume();

			timer.start();

		}

		private function sliderPressHandler(event:SliderEvent):void {

			ns.pause();

			timer.stop();

		}

	}
}

⌨️ 快捷键说明

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