[prev in list] [next in list] [prev in thread] [next in thread] 

List:       helix-datatype-cvs
Subject:    [Datatype-cvs] flash/flashhost/flash flvplayback.as, NONE,
From:       cdunn () helixcommunity ! org
Date:       2007-09-28 21:15:13
Message-ID: 200709282115.l8SLFdVt015581 () mailer ! progressive-comp ! com
[Download RAW message or body]

Update of /cvsroot/datatype/flash/flashhost/flash
In directory cvs01.internal.helixcommunity.org:/tmp/cvs-serv12066/flash

Modified Files:
      Tag: hxclient_3_1_0_atlas
	flv_player_wrapper.fla flvwrapper.as flvwrapper.swf 
Added Files:
      Tag: hxclient_3_1_0_atlas
	flvplayback.as flvplayback.fla flvplayback.swf 
Log Message:
FLVPlayback fixes.

Index: flvwrapper.as
===================================================================
RCS file: /cvsroot/datatype/flash/flashhost/flash/flvwrapper.as,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -d -r1.1.2.2 -r1.1.2.3
--- flvwrapper.as	4 Sep 2007 23:51:41 -0000	1.1.2.2
+++ flvwrapper.as	28 Sep 2007 21:15:11 -0000	1.1.2.3
@@ -50,26 +50,22 @@
 import flash.external.ExternalInterface;
 
 var FLVURL:String = _level0.sourceURL;
-//var FLVURL:String = "http://172.23.142.202/spinaltap.flv";
-//var FLVURL:String = "file://C:/content/flash/flv/spinaltap.flv";
 
+var bDebug:Boolean = false;		// Make sure this is false before check in
+var bHXDebugMessages:Boolean=true;	// Sends HXDebug messages
+
+statusText._visible = bDebug;
+
+if (bDebug) {
 // Sample URLs
-//var FLVURL:String = "http://172.23.142.202/lateshow.flv";
-//FLVURL = "http://www.videospark.com/mixalot/putemontheglass.flv";
-//var FLVURL:String = _level0.sourceURL; //_level0.sourceURL; // \
                "file:///Users/milko/Flash/VideoShell/lateshow.flv"
-// 28 weeks after
-//FLVURL="file://C:/Documents and Settings/user/My Documents/My Videos/RealPlayer \
                Downloads/ROTTEN TOMATOES  28 Weeks Later Video2.flv"
-// Mac
-//FLVURL="file://C:/Documents and Settings/user/My Documents/My Videos/RealPlayer \
                Downloads/Trust a Mac - Google Video.flv"
-// Frog
-//FLVURL="file://C:/Documents and Settings/user/My Documents/My Videos/RealPlayer \
Downloads/YouTube - Crazy Frog - Axel F.flv" +    FLVURL = \
"http://172.23.142.202/spinaltap.flv"; +    //FLVURL = \
"http://172.23.142.202/lateshow.flv"; +    //FLVURL = \
"http://www.videospark.com/mixalot/putemontheglass.flv"; +}
 
 var hxArgDelim:String = ",";
 var hxDelim:String = ";";
 
-var netConn:NetConnection;
-var netStream:NetStream;
-
 // State
 var FLVState:String = "stoppedAtTheEnd";
 var FLVPosition:Number = 0;
@@ -91,8 +87,6 @@
 var _FLVWidth:Number = 0;
 var FLVHeight:Number = 0;
 var _FLVHeight:Number = 0;
-var FLVFrameRate:Number = 0;
-var FLVCodecId:Number = -1;
 
 // Container class access following variables to run the functions.
 //XXX This does not work in IE, so make sure the names match for \
SetVariable("HelixCommand", ...) @@ -122,196 +116,160 @@
 soundObj = new Sound();
 soundObj.setVolume(FLVVolume);
 
-netConn = new NetConnection();
-netConn.connect(null); 
-netStream = new NetStream(netConn); 
-myVideo.attachVideo(netStream); 
-myVideo.smoothing = true;
+// Create the NetConnection and NetStream objects
+var server_nc:NetConnection = new NetConnection();
+server_nc.connect(null); 
+var video_ns:NetStream = new NetStream(server_nc); 
+
+// Attach the video
+myVideo.attachVideo(video_ns); 
 
 intID = setInterval(UpdateFLV, 100);
-netStream.onMetaData = MetaData;
-netStream.onStatus = Status;
+video_ns.onMetaData = OnMetaDataEvent;
+video_ns.onStatus = OnStatusEvent;
 
 Stage.align = "TL";
 Stage.scaleMode = "noScale";
 
-// Create an object to receive the screen events
+// Resize listenter
 stageListener = new Object();
-// Create a function for the event you want to listen for
-stageListener.onResize = function ()
-{	
+stageListener.onResize = function () {	
 	LayoutVideo();
 }
-
-// Assign a listener for the Stage object
 Stage.addListener(stageListener);
-		
-//XXXctd DEBUG response
-//ExternalInterface.call("HXDebug", "init:"+FLVURL);
 
+		
 // Start playing immediately if the URL is set.
-if (FLVURL != undefined) 
-{
+if (FLVURL != undefined) {
     PlayFLV();
 }
 
 // Callback function from timer
-function UpdateFLV():Void
-{
-	if (FLVEnded == 0)
-	{
-		if (FLVInSeeking == 0)
-		{
-			FLVPosition = netStream.time * 1000;
+function UpdateFLV():Void {
+
+	if (FLVEnded == 0) {
+		statusText.text = "Time: "+video_ns.time;
+		if (FLVInSeeking == 0) {
+			FLVPosition = video_ns.time * 1000;
 		}
 	
+		if (ExternalInterface.available) {
+			ExternalInterface.call("HXPosition", FLVPosition);
+		}
+
 		//trace("FLVPosition = " + FLVPosition);
+	/*
+		trace(
+		  "\n BufferLength is "+video_ns.bufferLength + 
+		  "\n BufferTime is "+video_ns.bufferTime+ 
+		  "\n currentFps is "+video_ns.currentFps + 
+		  "\n bytes loaded "+video_ns.bytesLoaded+ "/"+ video_ns.bytesTotal + 
+		  "\n time is "+video_ns.time
+		);
+*/
 	
-		if (FLVPercentLoaded <> 100)
-		{
-			var bl:Number = netStream.bytesLoaded;
-			var bt:Number = netStream.bytesTotal;
-			if (bt > 0)
-			{
-				FLVPercentLoaded = Math.round(bl / bt) * 100;
+	
+		if (FLVPercentLoaded <> 100) {
+			var bl:Number = video_ns.bytesLoaded;
+			var bt:Number = video_ns.bytesTotal;
+			if (bt > 0) {
+				FLVPercentLoaded = Math.round((bl / bt) * 100);
 			}
-			else
-			{
+			else {
 				FLVPercentLoaded = 0;
 			}
 		}
 	
 		// If we haven't established the FLV width and height yet
 		// try to do so now.
-		if (FLVWidth == 0)
-		{
+		if (FLVWidth == 0) {
 			MetaNotify();
 		}
-	
-		// Seek test
-		/***
-		if (FLVPosition > 10000)
-		{
-			SeekFLV("1000");
-		}
-		***/
 	}
 }    
 
-function PlayFLV():Void
-{
-	if ( FLVState == "stopped" )
-	{
-		trace("PlayFLV is called");
+function PlayFLV():Void {
+	HXDebug("PlayFLV called: "+FLVState);
+	if ( FLVState == "stopped" ) {
 		FLVState = "playing";
 		SeekFLV("0");
-		netStream.pause();
-//		Alert.show("PlayFLV again")
-	}
-	else if ( FLVState == "stoppedAtTheEnd" )
-	{
-		trace("PlayFLV After Playing to the End is called");
-		//ExternalInterface.call("HXDebug", "Playing:"+FLVURL);
+		video_ns.pause();
+	} else if ( FLVState == "stoppedAtTheEnd" ) {
 		FLVEnded = 0;
 		FLVInBuffering = 0;
 		FLVEndOfPackets = 0;
 		FLVState = "playing";
-		netStream.play(FLVURL);
-//		Alert.show("PlayFLV After Playing to the End is called again")
-	}
-	else if ( FLVState == "paused" )
-	{
-		trace("PlayFLV is called");
+		video_ns.play(FLVURL);
+	} else if ( FLVState == "paused" ) {
 		FLVState = "playing";
-		netStream.pause();
-//		Alert.show("pause again for play");
-	}
-	else
-	{
-//		Alert.show("PlayFLV clip is called when current status is :" + FLVState);
+		video_ns.pause();
+	} else {
+		HXDebug("PlayFLV clip is called when current status is :" + FLVState);
 	}
 }		
 
-function PauseFLV():Void
-{
-	if ( FLVState == "playing" )
-	{
-		netStream.pause();
+function PauseFLV():Void {
+	HXDebug("PauseFLV : "+FLVState);
+	if ( FLVState == "playing" ) {
+		video_ns.pause();
 		FLVState = "paused";
-		trace("PauseFLV is called");
-//		Alert.show("pause in PauseFLV");
 	}
 }
 
-function StopFLV():Void
-{	
-	if ( FLVState == "playing" )
-	{
-		netStream.pause();
+function StopFLV():Void {	
+
+	if ( FLVState == "playing" ) {
+		video_ns.pause();
 		FLVState = "stopped";
-		trace("StopFLV is called");
-//		Alert.show("pause in StopFLV");
+		HXDebug("StopFLV is called");
 	}
 }
 
-function SetFLVURL(videoURL:String):Void 
-{
+function SetFLVURL(videoURL:String):Void {
     FLVURL = videoURL;
-    
-    //ExternalInterface.call("HXDebug", "Set:"+FLVURL);
 }
 
-function SeekFLV(seekTime:String):Void
-{	
-	var nPosMs = parseInt(seekTime);
+function SeekFLV(seekTime:String):Void {	
+	var nPosMs = Number(seekTime);
 	
-	if (nPosMs >= 0)
-	{
+	if (nPosMs >= 0 && video_ns.bufferLength > 0) {
 		var nPos:Number = nPosMs / 1000.0;
+
+		HXDebug("SeekFLV " + nPos);
+
 		FLVInSeeking = 1;
-		FLVPosition = nPosMs;
+		//FLVPosition = nPosMs;
 		FLVEndOfPackets = 0;
 		FLVInBuffering = 0;
 		
-		netStream.seek(nPos);
-		
-		trace("SeekFLV " + nPos);
+		video_ns.seek(nPos);
 	}
 }
 
-function SetVolume(volumeLevel:String):Void
-{	
+function SetVolume(volumeLevel:String):Void {	
 	var nVolume = parseInt(volumeLevel);
 	
-	if (nVolume < 0)
-	{
+	if (nVolume < 0) {
 		nVolume = 0;
-	}
-	else if (nVolume > 100)
-	{
+	} else if (nVolume > 100) {
 		nVolume = 100;
 	}
 	
 	FLVVolume = nVolume;
 	soundObj.setVolume(FLVVolume);
 				
-	trace("SetVolume " + nVolume);
+	HXDebug("SetVolume " + nVolume);
 }
 
-function LayoutVideo():Void
-{
+function LayoutVideo():Void {
 	// Compute scaled video size within stage
-	if (FLVWidth != 0)
-	{
+	if (FLVWidth != 0) {
 		var sWidth:Number = Stage.width;
 		var sHeight:Number = Stage.height;
 
-		if ((FLVHeight / FLVWidth) < (sHeight / sWidth))
-		{
+		if ((FLVHeight / FLVWidth) < (sHeight / sWidth)) {
 			sHeight = sWidth * FLVHeight / FLVWidth;		
-		}
-		else
-		{
+		} else {
 			sWidth = sHeight * FLVWidth / FLVHeight;		
 		}
 		
@@ -321,8 +279,6 @@
 		myVideo._x = (Stage.width - sWidth) / 2;
 		myVideo._y = (Stage.height - sHeight) / 2;
 		trace("LayoutVideo \
                "+myVideo._x+","+myVideo._y+","+myVideo._width+","+myVideo._height);
-		// ExternalInterface.call("HXDebug", "LayoutVideo \
                "+myVideo._x+","+myVideo._y+","+myVideo._width+","+myVideo._height);
-		// ExternalInterface.call("HXDebug", "Stage "+Stage.width+","+Stage.height);
 	}
 }
 
@@ -331,15 +287,14 @@
 	if ((_FLVWidth == 0) ||
 		(_FLVHeight == 0))
 	{
-		trace("myVideo.width="+myVideo.width);
-		_FLVWidth = myVideo.width;
-		_FLVHeight = myVideo.height;
+		_FLVWidth = myVideo._width;
+		_FLVHeight = myVideo._height;
 	}
 	
 	if ((FLVWidth != _FLVWidth) ||
 		(FLVHeight != _FLVHeight) ||
-		(FLVDuration != _FLVDuration))
-	{
+		(FLVDuration != _FLVDuration)) {
+
 		FLVWidth = _FLVWidth;
 		FLVHeight = _FLVHeight;
 		FLVDuration = _FLVDuration;
@@ -363,96 +318,91 @@
 		callString += String(FLVDuration);
 		callString += hxDelim;
 
-		//trace("MetaNotify w="+FLVWidth+" h="+FLVHeight+" d="+FLVDuration);
 		trace("MetaNotify "+ callString);
 		
-		if (ExternalInterface.available)
-		{
+		if (ExternalInterface.available) {
 			ExternalInterface.call("HXMetaChanged", callString);
 		}
 		
 	}
 }
 
-function BufferingNotify(inBuffering:Number):Void
-{	
-	if (inBuffering != FLVInBuffering)
-	{
-		if ((FLVEndOfPackets == 0) || (inBuffering == 0))
-		{
+function BufferingNotify(inBuffering:Number):Void {	
+
+	if (inBuffering != FLVInBuffering) {
+		if ((FLVEndOfPackets == 0) || (inBuffering == 0)) {
 			FLVInBuffering = inBuffering;
 		
 			trace("BufferingNotify inBuffering="+FLVInBuffering);
 		
-			if (ExternalInterface.available)
-			{
+			if (ExternalInterface.available) {
 				ExternalInterface.call("HXBufferingChanged", FLVinBuffering);
 			}
 		}
 	}
 }
 
-function Status( evt:Object):Void
+function OnStatusEvent( evt:Object):Void
 {
-	trace("Status event triggerered");
+/*
+OnStatusEvent event: details = 129.563
+OnStatusEvent event: level = error
+OnStatusEvent event: code = NetStream.Seek.InvalidTime
+*/
+    var code:String = evt["code"];
+    var level:String = evt["level"];
+    var details:String = evt["details"];
+
+    HXDebug("Status: "+ code+ " time="+video_ns.time);
+    if (details != undefined) {
+    	HXDebug("    details - "+ details);
+    }
 	
-    for (var i in evt)
-	{
-		trace("Status event: " + i + " = " + evt[i]);
-		
-		if ( evt[i] == "NetStream.Play.Stop")
-		{
-			trace("stopped At The End");
-			BufferingNotify(0);
-			if (FLVPosition < FLVDuration)
-			{
-				FLVPosition = FLVDuration;
-			}
-			FLVEnded = 1;
-			FLVState = "stoppedAtTheEnd"
-			netStream.close();
-//			Alert.show("Stop Event Fired")
-		}
-		else if (evt[i] == "NetStream.Buffer.Full")
-		{
-			trace("Buffer Full");
-			FLVInSeeking = 0;
-			FLVEndOfPackets = 0;
-			FLVEnded = 0;
-			MetaNotify();
-			BufferingNotify(0);
-		}
-		else if (evt[i] == "NetStream.Buffer.Empty")
-		{
-			trace("Buffer Empty");
-			BufferingNotify(1);
-		}
-		else if (evt[i] == "NetStream.Seek.Notify")
-		{
-			trace("Seek Done Notify");
+	if (code == "NetStream.Seek.InvalidTime") {
+		if (ExternalInterface.available) {
+			ExternalInterface.call("HXDebug", "Invalid seek:"+details);
+			// Recover from invalid seek
+			video_ns.stop();
+			video_ns.play(FLVURL);
 		}
-		else if (evt[i] == "NetStream.Buffer.Flush")
+		
+	} else if ( code == "NetStream.Play.Stop") {
+		FLVState = "stoppedAtTheEnd";
+		BufferingNotify(0);
+		if (FLVPosition < FLVDuration)
 		{
-			trace("End of packets");
-			FLVEndOfPackets = 1;
-			if (ExternalInterface.available)
-			{
-				ExternalInterface.call("HXEndOfPackets");
-			}
+			FLVPosition = FLVDuration;
 		}
-		else if ( evt[i] == "NetStream.Play.Start")
+		FLVEnded = 1;
+		video_ns.close();
+	} else if (code == "NetStream.Buffer.Full") {
+		trace("Buffer Full");
+		FLVInSeeking = 0;
+		FLVEndOfPackets = 0;
+		FLVEnded = 0;
+		MetaNotify();
+		BufferingNotify(0);
+	} else if (code == "NetStream.Buffer.Empty") {
+		trace("Buffer Empty time"+video_ns.time);
+		trace("Buffer Empty Total"+video_ns.bytesTotal);
+		BufferingNotify(1);
+	} else if (code == "NetStream.Seek.Notify") {
+		trace("Seek complete: "+video_ns.time);
+	} else if (code == "NetStream.Buffer.Flush") {
+		trace("End of packets");
+		FLVEndOfPackets = 1;
+		if (ExternalInterface.available)
 		{
-			trace("Started");
-			FLVState = "playing"
-			MetaNotify();
-			
-//			Alert.show("Start Event Fired")
+			ExternalInterface.call("HXEndOfPackets");
 		}
+	} else if ( code == "NetStream.Play.Start") {
+		trace("Started");
+		FLVState = "playing"
+		MetaNotify();
 	}
 }
 
-function MetaData( evt:Object):Void
-{
+function OnMetaDataEvent( evt:Object):Void {
 	trace("metadata event triggerered");
 	
 	_FLVDuration = parseFloat(evt["duration"]) * 1000;
@@ -460,65 +410,50 @@
 	var widthEvt:String = evt["width"];
 	var heightEvt:String = evt["height"];
 		
-	if ((widthEvt != undefined) && (heightEvt != undefined))
-	{
+	if ((widthEvt != undefined) && (heightEvt != undefined)) {
 		_FLVWidth  = parseInt(evt["width"]);
 		_FLVHeight = parseInt(evt["height"]);
 	}
 	
-	for ( var i in evt)
-	{
+	for ( var i in evt) {
 		trace("metadata event: " + i + " = " + evt[i]);
 	}
 
-	trace(
-	  " BufferLength is "+netStream.bufferLength + 
-	  " BufferTime is "+netStream.bufferTime+ 
-	  " currentFps is "+netStream.currentFps + 
-	  " byteloaded is "+netStream.bytesLoaded+ 
-	  " bytetotal is "+netStream.bytesTotal+ 
-	  " currentFps is "+netStream.currentFps+
-	  " time is "+netStream.time
-	);
-	
 	MetaNotify();
 }
-//hide the standard menu-items for right click menu
-my_cm = new ContextMenu();
-my_cm.hideBuiltInItems();
-/*
-menuItem_play = new ContextMenuItem("Play Movie", PlayFLV);
-menuItem_pause = new ContextMenuItem("Pause Movie", PauseFLV);
-menuItem_stop = new ContextMenuItem("Stop Movie", StopFLV);
-menuItem_skip20 = new ContextMenuItem("Skip to 20", SetNum20);
-menuItem_skip0 = new ContextMenuItem("Skip to 0", SetNum0);
-my_cm.customItems.push(menuItem_play);
-my_cm.customItems.push(menuItem_pause);
-my_cm.customItems.push(menuItem_stop);
-my_cm.customItems.push(menuItem_skip20);
-my_cm.customItems.push(menuItem_skip0);
 
-function SetNum20():Void
-{
-	seekToCmd = "20";
-}
-function SetNum0():Void
-{
-	seekToCmd = "0";
+function HXDebug(msg:String):Void {
+	if (bHXDebugMessages) {
+		ExternalInterface.call("HXDebug", msg);
+	}
+	trace(msg);
 }
-function SetStopFLV():Void
-{
-	NewStatus = "stopFLV";
+
+
+if (bDebug) {
+	//hide the standard menu-items for right click menu
+	my_cm = new ContextMenu();
+	my_cm.hideBuiltInItems();
+
+	menuItem_play = new ContextMenuItem("Play Movie", PlayFLV);
+	menuItem_pause = new ContextMenuItem("Pause Movie", PauseFLV);
+	menuItem_stop = new ContextMenuItem("Stop Movie", StopFLV);
+	menuItem_skip20 = new ContextMenuItem("Seek to end", SeekToEnd);
+	menuItem_skip0 = new ContextMenuItem("Seek to 0", SeekToZero);
+	my_cm.customItems.push(menuItem_play);
+	my_cm.customItems.push(menuItem_pause);
+	my_cm.customItems.push(menuItem_stop);
+	my_cm.customItems.push(menuItem_skip20);
+	my_cm.customItems.push(menuItem_skip0);
+	_root.menu = my_cm;
 }
-function SetPauseFLV():Void
+
+function SeekToEnd():Void
 {
-	NewStatus = "pauseFLV";
+	SeekFLV(String(FLVDuration - 10000));
 }
-function SetPlayFLV():Void
+function SeekToZero():Void
 {
-	NewStatus = "playFLV";
+	SeekFLV("0");
 }
-*/
-_root.menu = my_cm;
-
 

Index: flvwrapper.swf
===================================================================
RCS file: /cvsroot/datatype/flash/flashhost/flash/flvwrapper.swf,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -d -r1.1.2.2 -r1.1.2.3
Binary files /tmp/cvs4nouyW and /tmp/cvs3lBiQY differ

--- NEW FILE: flvplayback.swf ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: flvplayback.as ---
/* ***** BEGIN LICENSE BLOCK *****
 * Source last modified: $Id: flvplayback.as,v 1.1.2.2 2007/09/28 21:15:11 cdunn Exp \
                $
 * 
 * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
 * 
 * The contents of this file, and the files included with this file,
 * are subject to the current version of the RealNetworks Public
 * Source License (the "RPSL") available at
 * http://www.helixcommunity.org/content/rpsl unless you have licensed
 * the file under the current version of the RealNetworks Community
 * Source License (the "RCSL") available at
 * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
 * will apply. You may also obtain the license terms directly from
 * RealNetworks.  You may not use this file except in compliance with
 * the RPSL or, if you have a valid RCSL with RealNetworks applicable
 * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
 * the rights, obligations and limitations governing use of the
 * contents of the file.
 * 
 * Alternatively, the contents of this file may be used under the
 * terms of the GNU General Public License Version 2 or later (the
 * "GPL") in which case the provisions of the GPL are applicable
 * instead of those above. If you wish to allow use of your version of
 * this file only under the terms of the GPL, and not to allow others
 * to use your version of this file under the terms of either the RPSL
 * or RCSL, indicate your decision by deleting the provisions above
 * and replace them with the notice and other provisions required by
 * the GPL. If you do not delete the provisions above, a recipient may
 * use your version of this file under the terms of any one of the
 * RPSL, the RCSL or the GPL.
 * 
 * This file is part of the Helix DNA Technology. RealNetworks is the
 * developer of the Original Code and owns the copyrights in the
 * portions it created.
 * 
 * This file, and the files included with this file, is distributed
 * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
 * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
 * ENJOYMENT OR NON-INFRINGEMENT.
 * 
 * Technology Compatibility Kit Test Suite(s) Location:
 *    http://www.helixcommunity.org/content/tck
 * 
 * Contributor(s):
 * 
 * ***** END LICENSE BLOCK ***** */

//////////////
// NOTE:
// Do not add a skin to the FLVPlayback instance, 
// otherwise the video will get a "connectionError"
// in the Flash Guest Player NS. (ActiveX versions works)
//////////////
 
import flash.external.ExternalInterface;
import mx.video.*;

var FLVURL:String = _level0.sourceURL;

var bDebug:Boolean = false;		// Make sure this is false before check in
var bHXDebugMessages:Boolean=true;	// Sends HXDebug messages

statusText._visible = bDebug;

if (bDebug) {
// Sample URLs
    //FLVURL = "http://172.23.142.202/spinaltap.flv";
    FLVURL = "http://172.23.142.202/lateshow.flv";
    //FLVURL = "http://www.videospark.com/mixalot/putemontheglass.flv";
}


var hxArgDelim:String = ",";
var hxDelim:String = ";";


// State
var FLVState:String = myflv.state; // disconnected
var FLVPosition:Number = 0;
var FLVSeekPosition:Number = 0;
var FLVPercentLoaded:Number = 0;
var FLVInBuffering:Number = 0;
var FLVEndOfPackets:Number = 0;
var FLVVolume:Number = _level0.startVolume;
if (FLVVolume == undefined)
{
	FLVVolume = 100;
}

// Initialized when meta data is available
var FLVDuration:Number = 0;
var FLVWidth:Number = 0;
var FLVHeight:Number = 0;

// Container class access following variables to run the functions.
//XXX This does not work in IE, so make sure the names match for \
SetVariable("HelixCommand", ...) ExternalInterface.addCallback("PlayFLV", null, \
PlayFLV); ExternalInterface.addCallback("PauseFLV", null, PauseFLV);
ExternalInterface.addCallback("SeekFLV", null, SeekFLV);
ExternalInterface.addCallback("StopFLV", null, StopFLV);
ExternalInterface.addCallback("UpdateFLV", null, UpdateFLV);
ExternalInterface.addCallback("SetVolume", null, SetVolume);
ExternalInterface.addCallback("SetFLVURL", null, SetFLVURL);

//
// Workaround for CallFunction not working in IE, use SetVariable
//  with 'HelixCommand' to execute the AS function.
//
this.HelixCommand = "";
this.catchFuncCall = function(prop, oldVal, newVal) {
	prop = newVal;
	var arr = newVal.split(",");
	var method = arr.shift();
	this[method].apply(this, arr);
};
this.watch("HelixCommand", this.catchFuncCall);


/////////////////////////////////////////////////////////////////
soundObj = new Sound();
soundObj.setVolume(FLVVolume);

Stage.align = "TL";
Stage.scaleMode = "noScale";

////////////////////////
// Resize listenter
stageListener = new Object();
stageListener.onResize = function () {	
	LayoutVideo();
}
Stage.addListener(stageListener);

////////////////////////
// Video ready listener
var readyListener:Object = new Object();
readyListener.ready = function(eventObject:Object):Void {
	HXDebug("READY! totalTime: " + myflv.totalTime);
	if (myflv.totalTime == 0) {
		trace("isLive: "+myflv.isLive);
	}
	MetaNotify();
	LayoutVideo();
};
myflv.addEventListener("ready", readyListener);

////////////////////////
// FLV player state listener
var stateListener:Object = new Object();
stateListener.stateChange = function(eventObject:Object):Void {
    OnStateChanged();
};
myflv.addEventListener("stateChange", stateListener);
		
////////////////////////
// Playhead listener
myflv.playheadUpdateInterval = 0.1;
var timelineListener:Object = new Object();
timelineListener.playheadUpdate = function(eventObject:Object):Void {
    //trace("time: "+myflv.playheadTime);
    UpdateFLV();
};
myflv.addEventListener("playheadUpdate", timelineListener);

////////////////////////
// Completion listener, triggered at the EOF of the FLV
var completeListener:Object = new Object();
completeListener.complete = function(eventObject:Object):Void {
    HXDebug("Elapsed play time at completion is: " + myflv.playheadTime);

    if (ExternalInterface.available) {
	ExternalInterface.call("HXStop");
    }

    if (FLVDuration > 0) {
	FLVPosition = FLVDuration;
    }

    if (ExternalInterface.available) {
	ExternalInterface.call("HXPosition", FLVPosition);
    }
    // Let Helix know the eof has been reached
};
myflv.addEventListener("complete", completeListener);

////////////////////////
// Seek listener
var seekListener:Object = new Object();
seekListener.seek = function(eventObject:Object) {
        trace("****Seek time :" + eventObject.playheadTime+" desired Seek: "+ \
FLVSeekPosition);  trace("****Seek state: " + eventObject.state);
	if (Math.abs(FLVSeekPosition - (myflv.playheadTime * 1000)) > 10000) {
		// Seek ERROR
	}
};
myflv.addEventListener("seek", seekListener);


////////////////////////
// Meta data listener
var metaDataListener:Object = new Object();
metaDataListener.metadataReceived = function(eventObject:Object):Void {
	trace("METADATA RECEIVED");
        trace("\tcanSeekToEnd is " + myflv.metadata.canSeekToEnd);
        trace("\tNumber of cue points is " + myflv.metadata.cuePoints.length);
        trace("\tFrame rate is " + myflv.metadata.framerate);
        trace("\tHeight is " + myflv.metadata.height);
        trace("\tWidth is " + myflv.metadata.width);
        trace("\tDuration is " + myflv.metadata.duration + " seconds");
	MetaNotify();
};
myflv.addEventListener("metadataReceived", metaDataListener);

////////////////////////
// progress listener
//loadingText._visible = false;
var progressListener:Object = new Object();
progressListener.progress = function(eventObject:Object):Void {
	var bl:Number = myflv.bytesLoaded;
	var bt:Number = myflv.bytesTotal;
	if (bt > 0) {
		FLVPercentLoaded = Math.round((bl / bt) * 100);
	}
	else {
		FLVPercentLoaded = 0;
	}

	/*
	if (FLVPercentLoaded < 100) {
		loadingText.text = "Loading . . . %"+FLVPercentLoaded;
		loadingText._visible = true;
	} else {
		loadingText._visible = false;
	}
	*/

     trace("Bytes loaded: "+myflv.bytesLoaded+"/"+myflv.bytesTotal);
     HXDebug("Percent loaded %"+FLVPercentLoaded);
}
myflv.addEventListener("progress", progressListener);


////////////////////////////////////////
// Start playing immediately if the URL is set.
if (FLVURL != undefined) {
    myflv.contentPath = FLVURL;
    PlayFLV();
}

function PlayFLV():Void {

	myflv.contentPath = FLVURL;

	HXDebug("PlayFLV called: state="+myflv.state+ " time="+myflv.playheadTime+ " \
url="+myflv.contentPath);

	myflv.play();
}

function PauseFLV():Void {
	HXDebug("PauseFLV called: state="+myflv.state+
		" time="+myflv.totalTime+
		" url="+myflv.contentPath);

	myflv.pause();
}

function StopFLV():Void {	
	HXDebug("StopFLV : "+FLVState+" time="+FLVPosition);
	myflv.stop();
}

function SetFLVURL(videoURL:String):Void {
	HXDebug("SetFLVURL : "+videoURL);
	FLVURL = videoURL;
}

function SeekFLV(seekTime:String):Void {	
 	HXDebug("SeekFLV " + seekTime);

	var nPosMs = Number(seekTime);
	if (nPosMs >= 0) {
		var nPos:Number = nPosMs / 1000.0;
		FLVSeekPosition = nPosMs;
		myflv.seek(nPos);
	}
}

function SetVolume(volumeLevel:String):Void {	
	var nVolume = parseInt(volumeLevel);
	
	if (nVolume < 0) {
		nVolume = 0;
	} else if (nVolume > 100) {
		nVolume = 100;
	}
	
	FLVVolume = nVolume;
	soundObj.setVolume(FLVVolume);
				
	trace("SetVolume " + nVolume);
}

function LayoutVideo():Void {
	// Compute scaled video size within stage
	if (FLVWidth != 0) {

		// Set the video size, it will adjust to maintain aspect ratio
		myflv.setSize(Stage.width, Stage.height);

		var sWidth:Number = Stage.width;
		var sHeight:Number = Stage.height;

		FLVWidth = myflv.width;
		FLVHeight = myflv.height;

		if ((FLVHeight / FLVWidth) < (sHeight / sWidth)) {
			sHeight = sWidth * FLVHeight / FLVWidth;		
		} else {
			sWidth = sHeight * FLVWidth / FLVHeight;		
		}
		
		myflv.x = (Stage.width - sWidth) / 2;
		myflv.y = (Stage.height - sHeight) / 2;

		//trace("LayoutVideo "+myflv.x+","+myflv.y+","+myflv.width+","+myflv.height);
		// ExternalInterface.call("HXDebug", "Stage "+Stage.width+","+Stage.height);
		if (statusText._visible) {
			statusText._y = myflv.height - statusText._height;
			statusText._width = myflv.width;
		}
	}
}

function MetaNotify():Void
{		

	// Let Helix know the duration

	FLVDuration = myflv.totalTime * 1000;
	FLVWidth = myflv.width;
	FLVHeight = myflv.height;
	
	var callString:String;

	callString = "width";
	callString += hxArgDelim;
	callString += String(myflv.width);
	callString += hxDelim;

	callString += "height";
	callString += hxArgDelim;
	callString += String(myflv.height);
	callString += hxDelim;

	callString += "duration";
	callString += hxArgDelim;
	callString += String(FLVDuration);
	callString += hxDelim;

	trace("MetaNotify "+ callString);
	
	if (ExternalInterface.available) {
		ExternalInterface.call("HXMetaChanged", callString);
	}
}

function BufferingNotify(inBuffering:Number):Void {	

	if (inBuffering != FLVInBuffering) {
		if ((FLVEndOfPackets == 0) || (inBuffering == 0)) {
			FLVInBuffering = inBuffering;
		
			trace("BufferingNotify inBuffering="+FLVInBuffering);
		
			if (ExternalInterface.available) {
				ExternalInterface.call("HXBufferingChanged", FLVinBuffering);
			}
		}
	}
}

function OnStateChanged():Void {
	
/*
   Possible states:
FLVPlayback.BUFFERING
FLVPlayback.CONNECTION_ERROR
FLVPlayback.DISCONNECTED
FLVPlayback.LOADING
FLVPlayback.PAUSED
FLVPlayback.PLAYING
FLVPlayback.REWINDING
FLVPlayback.SEEKING
FLVPlayback.STOPPED
*/
	HXDebug("State changed: "+myflv.state+ " time="+myflv.playheadTime);

        FLVState = myflv.state;

  	UpdateFLV();

	if (myflv.state == FLVPlayback.STOPPED ||
	    myflv.state == FLVPlayback.CONNECTION_ERROR ||
	    myflv.state == FLVPlayback.DISCONNECTED) {
		FLVEndOfPackets = 1;
	} else {
		FLVEndOfPackets = 0;
	}

	if (myflv.state == FLVPlayback.CONNECTION_ERROR) {
		StopFLV();
		if (ExternalInterface.available) {
			ExternalInterface.call("HXError", myflv.state);
		}
	}


	BufferingNotify(Number(myflv.state == FLVPlayback.BUFFERING));
}

//
// UpdateFLV: Updates the current position, and sends it Helix, HXPosition
//
function UpdateFLV():Void {

    statusText.text = myflv.playheadTime + " : playheadTime";
    statusText.text += "\nstate: "+myflv.state;
    
    FLVPosition = myflv.playheadTime * 1000;

    if (ExternalInterface.available) {
	ExternalInterface.call("HXPosition", FLVPosition);
    }

}    

function HXDebug(msg:String):Void {
	if (bHXDebugMessages) {
		ExternalInterface.call("HXDebug", msg);
	}
	trace(msg);
}


if (bDebug) {
	//hide the standard menu-items for right click menu
	my_cm = new ContextMenu();
	my_cm.hideBuiltInItems();

	menuItem_play = new ContextMenuItem("Play Movie", PlayFLV);
	menuItem_pause = new ContextMenuItem("Pause Movie", PauseFLV);
	menuItem_stop = new ContextMenuItem("Stop Movie", StopFLV);
	menuItem_skip20 = new ContextMenuItem("Seek to end", SeekToEnd);
	menuItem_skip0 = new ContextMenuItem("Seek to 0", SeekToZero);
	my_cm.customItems.push(menuItem_play);
	my_cm.customItems.push(menuItem_pause);
	my_cm.customItems.push(menuItem_stop);
	my_cm.customItems.push(menuItem_skip20);
	my_cm.customItems.push(menuItem_skip0);
	_root.menu = my_cm;
}

function SeekToEnd():Void
{
	SeekFLV(String(FLVDuration - 10000));
}
function SeekToZero():Void
{
	SeekFLV("0");
}


--- NEW FILE: flvplayback.fla ---
(This appears to be a binary file; contents omitted.)

Index: flv_player_wrapper.fla
===================================================================
RCS file: /cvsroot/datatype/flash/flashhost/flash/flv_player_wrapper.fla,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -d -r1.1.2.2 -r1.1.2.3
Binary files /tmp/cvsuUqCHV and /tmp/cvs4gHV5X differ


_______________________________________________
Datatype-cvs mailing list
Datatype-cvs@helixcommunity.org
http://lists.helixcommunity.org/mailman/listinfo/datatype-cvs


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic