132 changes: 66 additions & 66 deletions mythflash/MythFlash/MFPlayer/MFPlayer.as
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/**
* MFPlayer.as
*
*
* Copyright (C) 2007 Jean-Philippe Steinmetz
*
* This file is part of MythFlash.
*
*
* MythFlash is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*
* MythFlash is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with MythFlash; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Expand All @@ -23,13 +23,13 @@
package MythFlash.MFPlayer
{
import mx.core.UIComponent;

import flash.display.Stage;
import flash.display.StageDisplayState;

import mx.controls.VideoDisplay;
import MythFlash.MFPlayer.MFPlayerControl;

import flash.events.Event;
import flash.events.FullScreenEvent;
import flash.events.MouseEvent;
Expand All @@ -39,7 +39,7 @@ package MythFlash.MFPlayer
import mx.styles.StyleManager;
import flash.ui.Mouse;
import mx.effects.Fade;

/**
* The MFPlayer component allows you to play an FLV file or stream in a Flex/Flash application. This component allows you to reassign the controls and supports full screen mode.
**/
Expand All @@ -54,93 +54,93 @@ package MythFlash.MFPlayer
private var fullscreen:Boolean;
private var controllerTimer:Timer;
private var _styles:String;

// UI Components
protected var video:VideoDisplay;

protected var videoController:MFPlayerControl;
private var vcOrigAlpha:Number;

// Animation Effects


/**
* Default constructor
**/
function MFPlayer()
{
}

/**
* Initializes the internal structure of the component
**/
override public function initialize():void
{
super.initialize();

controllerTimer = new Timer(3000,1);
controllerTimer.addEventListener("timer",hideController);

//StyleManager.loadStyleDeclarations("MFPlayer_styles.swf");

addEventListener("addedToStage",addedToStage);
}

/**
* Creates all child objects required for the component
**/
override protected function createChildren():void
{
super.createChildren();

if(!video)
{
video = new VideoDisplay();
video.autoPlay = false;
video.maintainAspectRatio = true;
addChild(video);

video.addEventListener(MouseEvent.CLICK,togglePlayPause);
}

if(!videoController)
{
videoController = new MFPlayerControl(video);
videoController.addEventListener("toggleFullscreen",toggleFullScreen);
vcOrigAlpha = videoController.alpha;
addChild(videoController);
}

invalidateDisplayList();
}

/**
* Calculates the default size as well as the minimum size required for the component.
**/
override protected function measure():void
{
super.measure();

measuredWidth = 320;
measuredHeight = 260;
measuredMinWidth = 320;
measuredMinHeight = 260;

measuredMinWidth = 240;
measuredMinHeight = 180;
}

/**
* Draws the objects and/or sizes and positions its children.
**/
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);

if(fullscreen && stage != null)
{
{
video.x = video.y = 0;
video.width = this.width;
video.height = this.height;

videoController.width = video.width;
videoController.height = 20;
videoController.x = video.x;
Expand All @@ -151,16 +151,16 @@ package MythFlash.MFPlayer
video.x = video.y = 0;
video.width = this.width;
video.height = this.height-videoController.height;

videoController.width = video.width;
videoController.height = 20;
videoController.x = video.x;
videoController.y = video.y+video.height;
}

videoController.invalidateDisplayList();
}

/**
* This function is called when an addedToStage event is dispatched from the stage object.
* @param event The event object corresponding to the dispatcher
Expand All @@ -171,26 +171,26 @@ package MythFlash.MFPlayer
if(origY == 0) origY = y;
if(origWidth == 0) origWidth = width;
if(origHeight == 0) origHeight = height;

stage.addEventListener(FullScreenEvent.FULL_SCREEN, fullScreenRedraw);
}

/**
* Gets or sets the path of the FLV or stream to be played
**/
public function get source():String
{
return video.source;
}

/**
* Gets or sets the path of the FLV or stream to be played
**/
public function set source(value:String):void
{
if(value != null && value != "") video.source = value;
}

/**
* Gets or sets the total time for the FLV. This is used when the FLV file does not contain
* its own length information.
Expand All @@ -199,7 +199,7 @@ package MythFlash.MFPlayer
{
return videoController.totalTime;
}

/**
* Gets or sets the total time for the FLV. This is used when the FLV file does not contain
* its own length information.
Expand All @@ -208,87 +208,87 @@ package MythFlash.MFPlayer
{
videoController.totalTime = value;
}

/**
* Gets or sets the flag that determines if the video should automatically play when loaded
**/
public function get autoPlay():Boolean
{
return video.autoPlay;
}

/**
* Gets or sets the flag that determines if the video should automatically play when loaded
**/
public function set autoPlay(value:Boolean):void
{
video.autoPlay = value;
}

/**
* Gets or sets the flag that tells the component if the source is a stream or a file
**/
public function get isLive():Boolean
{
return video.live;
}

/**
* Gets or sets the flag that tells the component if the source is a stream or a file
**/
public function set isLive(value:Boolean):void
{
video.live = value;
}

/**
* Gets or sets the location of the CSS styling file for the component
**/
public function get styles():String
{
return _styles;
}

/**
* Gets or sets the location of the CSS styling file for the component
**/
public function set styles(value:String):void
{
if(value == null || value == "") return;

_styles = value;

StyleManager.loadStyleDeclarations(value);

dispatchEvent(new Event(MFPlayerEvent.STYLES_LOADED));

invalidateDisplayList();
}

/**
* Begins playing the video source
**/
public function play():void
{
video.play();
}

/**
* Pauses the video source at the current playing position
**/
public function pause():void
{
video.pause();
}

/**
* Stops the video source from playing and returns to the beginning
**/
public function stop():void
{
video.stop();
}

/**
* This is called when the VideoDisplay is clicked and will pause
* or play the current video.
Expand All @@ -299,15 +299,15 @@ package MythFlash.MFPlayer
if(video.playing) pause();
else play();
}

/**
* This is called when the FullScreen button is pressed on the
* controller and switches the component to full screen mode
* @param event The event object sent by the dispatcher
**/
private function toggleFullScreen(event:Event):void
{

if(stage.displayState == StageDisplayState.NORMAL)
{
this.stage.displayState = StageDisplayState.FULL_SCREEN;
Expand All @@ -317,7 +317,7 @@ package MythFlash.MFPlayer
this.stage.displayState = StageDisplayState.NORMAL;
}
}

/**
* This is called when the application enters full screen mode. The
* function performs calculations to redraw the video and controls to
Expand All @@ -332,11 +332,11 @@ package MythFlash.MFPlayer
this.x = this.y = 0;
this.width = stage.width;
this.height = stage.height;

controllerTimer.reset();
controllerTimer.start();
addEventListener(MouseEvent.MOUSE_MOVE, showController);

fullscreen = true;
}
else
Expand All @@ -345,37 +345,37 @@ package MythFlash.MFPlayer
this.y = origY;
this.width = origWidth;
this.height = origHeight;

removeEventListener(MouseEvent.MOUSE_MOVE, showController);
controllerTimer.stop();

fullscreen = false;
}

invalidateSize();
invalidateDisplayList();
}

/**
* This function is called when in full screen mode to show the controller
**/
private function showController(event:Event):void
{
Mouse.show();

videoController.visible = true;
videoController.alpha = vcOrigAlpha;

controllerTimer.reset();
controllerTimer.start();
}

/**
* This function is called when in full screen mode and the user has been idle for
* a period of time.
**/
private function hideController(event:Event):void
{
{
var hideAnim:Fade = new Fade();
hideAnim.target = videoController;
hideAnim.alphaFrom = vcOrigAlpha;
Expand Down
9 changes: 5 additions & 4 deletions mythflash/MythFlash/MFPlayer/MFPlayer_styles.css
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/**
* MFPlayer_styles.css
*
*
* Copyright (C) 2007 Jean-Philippe Steinmetz
*
* This file is part of MythFlash.
*
*
* MythFlash is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*
* MythFlash is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with MythFlash; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Expand Down Expand Up @@ -176,6 +176,7 @@ VSlider
{
borderStyle: solid;
borderColor: #666666;
color: #33ff33;
}

/*
Expand Down