first commit
This commit is contained in:
681
com/yahoo/astra/fl/controls/mediaPlayerClasses/AudioClip.as
Executable file
681
com/yahoo/astra/fl/controls/mediaPlayerClasses/AudioClip.as
Executable file
@@ -0,0 +1,681 @@
|
||||
/*
|
||||
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
|
||||
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
|
||||
*/
|
||||
package com.yahoo.astra.fl.controls.mediaPlayerClasses
|
||||
{
|
||||
import flash.events.*;
|
||||
import flash.media.Sound;
|
||||
import flash.media.SoundChannel;
|
||||
import flash.media.SoundTransform;
|
||||
import flash.media.SoundLoaderContext;
|
||||
import com.yahoo.astra.fl.controls.mediaPlayerClasses.IMediaClip;
|
||||
import flash.net.URLRequest;
|
||||
import fl.core.UIComponent;
|
||||
import com.yahoo.astra.fl.events.MediaEvent;
|
||||
import flash.utils.Timer;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
|
||||
//--------------------------------------
|
||||
// Events
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* Dispatched when on an interval while the clip is playing.
|
||||
*
|
||||
* @eventType com.yahoo.astra.fl.events.MediaEvent.MEDIA_POSITION
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Event(name="mediaPosition", type="com.yahoo.astra.fl.events.MediaEvent")]
|
||||
|
||||
/**
|
||||
* Dispatched when the clip is paused or played.
|
||||
*
|
||||
* @eventType com.yahoo.astra.fl.events.MediaEvent.MEDIA_PLAY_PAUSE
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Event(name="mediaPlayPause", type="com.yahoo.astra.fl.events.MediaEvent")]
|
||||
|
||||
/**
|
||||
* Dispatched when the volume level is changed.
|
||||
*
|
||||
* @eventType com.yahoo.astra.fl.events.MediaEvent.VOLUME_CHANGE
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Event(name="volumeChange", type="com.yahoo.astra.fl.events.MediaEvent")]
|
||||
|
||||
/**
|
||||
* Dispatched when the id3 event is received.
|
||||
*
|
||||
* @eventType com.yahoo.astra.fl.events.MediaEvent.INFO_CHANGE
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Event(name="infoChange", type="com.yahoo.astra.fl.events.MediaEvent")]
|
||||
|
||||
/**
|
||||
* Dispatched when a clip has completely loaded.
|
||||
*
|
||||
* @eventType com.yahoo.astra.fl.events.MediaEvent.MEDIA_LOADED
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Event(name="mediaLoaded", type="com.yahoo.astra.fl.events.MediaEvent")]
|
||||
|
||||
/**
|
||||
* Dispatched when a clip reaches its end point.
|
||||
*
|
||||
* @eventType com.yahoo.astra.fl.events.MediaEvent.MEDIA_ENDED
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Event(name="mediaEnded", type="com.yahoo.astra.fl.events.MediaEvent")]
|
||||
|
||||
//--------------------------------------
|
||||
// Class description
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* The AudioClip class extends the EventDispatcher class and wraps the
|
||||
* Sound, SoundChannel, SoundLoaderContext and SoundTransform classes.
|
||||
*
|
||||
* @see flash.media.Sound
|
||||
* @see flash.media.SoundChannel
|
||||
* @see flash.media.SoundTransform
|
||||
* @see flash.media.SoundLoaderContext
|
||||
* @see flash.events.EventDispatcher
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public class AudioClip extends EventDispatcher implements IMediaClip
|
||||
{
|
||||
|
||||
//--------------------------------------
|
||||
// Constructor
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public function AudioClip():void
|
||||
{
|
||||
super();
|
||||
_soundTransform = new SoundTransform(_volume, _panning);
|
||||
_positionTimer = new Timer(50);
|
||||
_positionTimer.addEventListener(TimerEvent.TIMER, positionUpdateHandler);
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Properties
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _mediaAvailable:Boolean = false;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _length:Number = 0;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _artist:String;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _title:String;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* The Sound object
|
||||
*/
|
||||
protected var _clip:Sound;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* The SoundChannel
|
||||
*/
|
||||
protected var _channel:SoundChannel;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* Timer used to dispatch "mediaPosition" events.
|
||||
*/
|
||||
protected var _positionTimer:Timer;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* place holder for position.
|
||||
*/
|
||||
protected var _position:Number;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* indicates whether the state of the clip is paused
|
||||
*/
|
||||
protected var _playing:Boolean = true;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* indicates whether the sound is muted
|
||||
*/
|
||||
protected var _mute:Boolean = false;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _volume:Number = 1;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _panning:Number = 0;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _soundTransform:SoundTransform;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _autoStart:Boolean = false;
|
||||
|
||||
/**
|
||||
* Gets the url to be used for an AudioClip (read-only)
|
||||
*/
|
||||
public function get url():String
|
||||
{
|
||||
return _clip.url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets or sets the position of the playhead
|
||||
*/
|
||||
public function get position():Number
|
||||
{
|
||||
return _channel.position;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (setter)
|
||||
* sets the position for a clip (cues and rewinds)
|
||||
* if the clip is paused, the _position property is set to the received value
|
||||
* otherwise the clip is played from that position
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public function set position(value:Number):void
|
||||
{
|
||||
if(_mediaAvailable)
|
||||
{
|
||||
_position = Math.min(value, _length);
|
||||
_channel.removeEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
|
||||
_channel = _clip.play(_position);
|
||||
_channel.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
|
||||
_channel.soundTransform = _soundTransform;
|
||||
if(!_playing) pause();
|
||||
dispatchEvent(new MediaEvent(MediaEvent.MEDIA_POSITION, false, false, _playing?Number(_channel.position.toFixed(2)):_position, _length, _soundTransform.volume, _mute));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Length of the Audio (read-only)
|
||||
*/
|
||||
public function get length():Number
|
||||
{
|
||||
return _length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Boolean indicating if the audio is playing. (read-only) us pause() and play() methods to change playing
|
||||
*/
|
||||
public function get playing():Boolean
|
||||
{
|
||||
return _playing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets or sets the volume, ranging from 0 (silent) to 1 (full volume).
|
||||
*/
|
||||
public function get volume():Number
|
||||
{
|
||||
return _soundTransform.volume;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (setter)
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public function set volume(value:Number):void
|
||||
{
|
||||
//sets the volume property of the _soundTransform object
|
||||
//sets the _soundTransform object to the _channel
|
||||
//dispatches a VOLUME_CHANGE MediaEvent
|
||||
_soundTransform.volume = _volume = Math.max(0, Math.min(value, 1));
|
||||
_mute = false;
|
||||
if(_mediaAvailable)
|
||||
{
|
||||
_channel.soundTransform = _soundTransform;
|
||||
dispatchEvent(new MediaEvent(MediaEvent.VOLUME_CHANGE, false, false, Number(_channel.position.toFixed(2)), _length, Number(_channel.soundTransform.volume), _mute));
|
||||
}
|
||||
else
|
||||
{
|
||||
dispatchEvent(new MediaEvent(MediaEvent.VOLUME_CHANGE, false, false, _position, 0, _soundTransform.volume, _mute));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets or sets the mute property of the AudioClip
|
||||
*/
|
||||
public function get mute():Boolean
|
||||
{
|
||||
return _mute;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (setter)
|
||||
* Sets the mute property of the audio
|
||||
*/
|
||||
public function set mute(value:Boolean):void
|
||||
{
|
||||
//sets the value of _mute
|
||||
//sets the volume of the _soundTransform object to 0 if +_mute is true and to _volume if _mute is false
|
||||
//sets the _soundTransform object to the _channel
|
||||
//dispatches a VOLUME_CHANGE MediaEvent
|
||||
_mute = value;
|
||||
_soundTransform.volume = _mute?0:_volume;
|
||||
if(_mediaAvailable)
|
||||
{
|
||||
_channel.soundTransform = _soundTransform;
|
||||
dispatchEvent(new MediaEvent(MediaEvent.VOLUME_CHANGE, false, false, Number(_channel.position.toFixed(2)), _length, Number(_channel.soundTransform.volume), _mute));
|
||||
}
|
||||
else
|
||||
{
|
||||
dispatchEvent(new MediaEvent(MediaEvent.VOLUME_CHANGE, false, false, _position, 0, _soundTransform.volume, _mute));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the artist for the audio clip (read-only). This information is available:
|
||||
* <ul>
|
||||
* <li>If the SWF is in the same domain as the sound file.</li>
|
||||
* <li>If the <code>checkPolicyFile</code> property is true and there
|
||||
* is a cross-domain policy file on the server from which the sound is
|
||||
* loaded that permits the domain of the loading SWF file. </li>
|
||||
* </ul>
|
||||
*
|
||||
*/
|
||||
public function get artist():String
|
||||
{
|
||||
return _artist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the title of the clip (read-only). This information is available:
|
||||
* <ul>
|
||||
* <li>If the SWF is in the same domain as the sound file.</li>
|
||||
* <li>If the <code>checkPolicyFile</code> property is true and there is a cross-domain policy file on the
|
||||
* server from which the sound is loaded that permits the domain of the loading SWF file. </li>
|
||||
* </ul>
|
||||
*
|
||||
*/
|
||||
public function get title():String
|
||||
{
|
||||
return _title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets or sets the autoStart property of an AudioClip
|
||||
*/
|
||||
public function get autoStart():Boolean
|
||||
{
|
||||
return _autoStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (setter)
|
||||
*/
|
||||
public function set autoStart(value:Boolean):void
|
||||
{
|
||||
_autoStart = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _soundLoaderContext:SoundLoaderContext;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _bufferTime:Number = 1000;
|
||||
|
||||
/**
|
||||
* Gets or sets buffer time. (milliseconds)
|
||||
*/
|
||||
public function get bufferTime():Number
|
||||
{
|
||||
return _bufferTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (setter)
|
||||
*/
|
||||
public function set bufferTime(value:Number):void
|
||||
{
|
||||
_bufferTime = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _checkForPolicyFile:Boolean = true;
|
||||
|
||||
/**
|
||||
* Gets or sets checkForPolicyFile property of the SoundLoaderContext. Specifies whether Flash Player should check
|
||||
* for the existence of a cross-domain policy file upon loading the object (true) or not.
|
||||
*
|
||||
* @see flash.media.SoundLoaderContext;
|
||||
*
|
||||
*/
|
||||
public function get checkForPolicyFile():Boolean
|
||||
{
|
||||
return _checkForPolicyFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (setter)
|
||||
*/
|
||||
public function set checkForPolicyFile(value:Boolean):void
|
||||
{
|
||||
_checkForPolicyFile = value;
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Public Methods
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* Loads an audio clip
|
||||
*
|
||||
* @param urlValue string for the location of the clip
|
||||
* @param autoStart Boolean indicating whether the clip starts playing when it loads
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public function loadMedia(urlValue:String, autoStart:Boolean = true):void
|
||||
{
|
||||
_soundLoaderContext = new SoundLoaderContext(bufferTime, checkForPolicyFile);
|
||||
_length = 0;
|
||||
_playing = autoStart;
|
||||
_mediaAvailable = true;
|
||||
_position = 0;
|
||||
var request:URLRequest = new URLRequest(urlValue);
|
||||
if(_clip != null)
|
||||
{
|
||||
removeClipListeners(_clip);
|
||||
_positionTimer.reset();
|
||||
}
|
||||
if(_channel != null)
|
||||
{
|
||||
if(_channel.hasEventListener(Event.SOUND_COMPLETE)) _channel.removeEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
|
||||
_channel.stop();
|
||||
}
|
||||
|
||||
_clip = new Sound();
|
||||
addClipListeners(_clip);
|
||||
|
||||
_clip.load(request, _soundLoaderContext);
|
||||
|
||||
_channel = _clip.play();
|
||||
_channel.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
|
||||
_channel.soundTransform = _soundTransform;
|
||||
_positionTimer.start();
|
||||
dispatchEvent(new MediaEvent(MediaEvent.MEDIA_POSITION, false, false, _position, _length, _channel.soundTransform.volume, _mute));
|
||||
dispatchEvent(new MediaEvent(MediaEvent.MEDIA_PLAY_PAUSE, false, false, _position, _length, _channel.soundTransform.volume, _mute));
|
||||
dispatchEvent(new MediaEvent(MediaEvent.VOLUME_CHANGE, false, false, _position, _length, _channel.soundTransform.volume, _mute));
|
||||
if(!autoStart)
|
||||
{
|
||||
pause();
|
||||
_position = 0;
|
||||
}
|
||||
|
||||
//dispatchEvent(new MediaEvent(MediaEvent.MEDIA_READY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Pauses the audio
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public function pause():void
|
||||
{
|
||||
//sets pause to true
|
||||
//dispatches a MEDIA_PLAY_PAUSE event
|
||||
//calls the stop function
|
||||
if(_mediaAvailable)
|
||||
{
|
||||
_playing = false;
|
||||
dispatchEvent(new MediaEvent(MediaEvent.MEDIA_PLAY_PAUSE, false, false, Number(_channel.position.toFixed(2)), _length, Number(_channel.soundTransform.volume), _mute));
|
||||
stop();
|
||||
_positionTimer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays the audio
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public function play():void
|
||||
{
|
||||
//sets _playing to true
|
||||
//dispatches a MEDIA_PLAY_PAUSE event
|
||||
//set the SoundChannel object to the play method of the Sound object using the _position value
|
||||
if(_mediaAvailable)
|
||||
{
|
||||
_positionTimer.start();
|
||||
_playing = true;
|
||||
dispatchEvent(new MediaEvent(MediaEvent.MEDIA_PLAY_PAUSE, false, false, Number(_channel.position.toFixed(2)), _length, Number(_channel.soundTransform.volume), _mute));
|
||||
_channel.removeEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
|
||||
_channel = _clip.play(_position);
|
||||
_channel.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
|
||||
_channel.soundTransform = _soundTransform;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the audio
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public function stop():void
|
||||
{
|
||||
//sets _position to the current position of the sound object
|
||||
//calls the stop method on the SoundChannel object
|
||||
//used by pause method, to stop the playback when audio is in a paused state
|
||||
//used by the controller to stop the video while the MediaScrubber seeks
|
||||
if(_mediaAvailable)
|
||||
{
|
||||
_position = Number(_channel.position.toFixed(2));
|
||||
_channel.stop();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Protected Methods
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* Dispatches a MediaEvent.MEDIA_POSITION event with the _positionTimer event
|
||||
* @param event The TimerEvent
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
protected function positionUpdateHandler(event:TimerEvent):void
|
||||
{
|
||||
//if paused, update with the _position value. if not, update with the actual position of the sound channel
|
||||
dispatchEvent(new MediaEvent(MediaEvent.MEDIA_POSITION, false, false, _playing?Number(_channel.position.toFixed(2)):_position, _length, Number(_channel.soundTransform.volume), _mute));
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* Adds event listeners to a sound object when set clip is called.
|
||||
* @param soundDispatcher
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
protected function addClipListeners(soundDispatcher:Sound):void
|
||||
{
|
||||
|
||||
soundDispatcher.addEventListener(Event.COMPLETE, completeHandler);
|
||||
soundDispatcher.addEventListener(Event.ID3, id3Handler);
|
||||
soundDispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
|
||||
soundDispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* Removes listeners from the sound object before a new clip is set
|
||||
* @param soundDispatcher
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
protected function removeClipListeners(soundDispatcher:Sound):void
|
||||
{
|
||||
soundDispatcher.removeEventListener(Event.COMPLETE, completeHandler);
|
||||
soundDispatcher.removeEventListener(Event.ID3, id3Handler);
|
||||
soundDispatcher.removeEventListener(ProgressEvent.PROGRESS, progressHandler);
|
||||
soundDispatcher.removeEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* Resets a clip to the beginning and dispatches MediaEvent.MEDIA_POSITION and MediaEvent.MEDIA_ENDED events.
|
||||
* @param event soundComplete event
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
protected function soundCompleteHandler(event:Event):void
|
||||
{
|
||||
pause();
|
||||
position = 0;
|
||||
//does not always fire. may need to add a catch in the timer to force an end
|
||||
dispatchEvent(new MediaEvent(MediaEvent.MEDIA_POSITION, false, false, _playing?Number(_channel.position.toFixed(2)):_position, _length, _soundTransform.volume, _mute));
|
||||
dispatchEvent(new MediaEvent(MediaEvent.MEDIA_ENDED, false, false, _playing?Number(_channel.position.toFixed(2)):_position, _length, _soundTransform.volume, _mute));
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* Dispatches a MediaEvent.MEDIA_LOADED event when the media has loaded
|
||||
* @param event Event.COMPLETE event
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
protected function completeHandler(event:Event):void
|
||||
{
|
||||
_length = _clip.length;
|
||||
dispatchEvent(new MediaEvent(MediaEvent.MEDIA_LOADED));
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* Dispatches a MediaEvent.INFO_CHANGE event when the ID3 event is received from the Sound object
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
protected function id3Handler(event:Event):void
|
||||
{
|
||||
try
|
||||
{
|
||||
_title = _clip.id3.songName as String;
|
||||
_artist = _clip.id3.artist as String;
|
||||
}
|
||||
catch(e:SecurityError)
|
||||
{
|
||||
_artist = "Artist Unavailable";
|
||||
_title = "Title Unavailable";
|
||||
}
|
||||
dispatchEvent(new MediaEvent(MediaEvent.INFO_CHANGE, false, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* dispatches the ProgressEvent to registered listeners
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
protected function progressHandler(event:ProgressEvent):void
|
||||
{
|
||||
_length = _clip.length * (event.bytesTotal/event.bytesLoaded);
|
||||
dispatchEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
protected function ioErrorHandler(event:IOErrorEvent):void
|
||||
{
|
||||
//need to reset everything here.
|
||||
_mediaAvailable = false;
|
||||
_positionTimer.stop();
|
||||
_length = 0;
|
||||
_artist = "Artist Unavailable";
|
||||
_title = "Title Unavailable";
|
||||
dispatchEvent(new MediaEvent(MediaEvent.INFO_CHANGE, false, false));
|
||||
}
|
||||
|
||||
public function kill():void
|
||||
{
|
||||
if(_mediaAvailable)
|
||||
{
|
||||
pause();
|
||||
dispatchEvent(new MediaEvent(MediaEvent.MEDIA_POSITION, false, false, _playing?Number(_channel.position.toFixed(2)):_position, _length, _soundTransform.volume, _mute));
|
||||
dispatchEvent(new MediaEvent(MediaEvent.MEDIA_ENDED, false, false, _playing?Number(_channel.position.toFixed(2)):_position, _length, _soundTransform.volume, _mute));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
129
com/yahoo/astra/fl/controls/mediaPlayerClasses/IMediaClip.as
Executable file
129
com/yahoo/astra/fl/controls/mediaPlayerClasses/IMediaClip.as
Executable file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
|
||||
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
|
||||
*/
|
||||
package com.yahoo.astra.fl.controls.mediaPlayerClasses
|
||||
{
|
||||
import flash.events.IEventDispatcher;
|
||||
/**
|
||||
* The IMediaClip interface provides the methods and properties that a media clip requires.
|
||||
* All user defined media clips should implement this interface.
|
||||
*/
|
||||
|
||||
public interface IMediaClip extends IEventDispatcher
|
||||
{
|
||||
|
||||
//--------------------------------------
|
||||
// Properties
|
||||
//--------------------------------------
|
||||
/**
|
||||
* Gets the source url for the media clip (read-only)
|
||||
*/
|
||||
function get url():String;
|
||||
|
||||
/**
|
||||
* Gets or sets the position of the media clip
|
||||
*/
|
||||
function get position():Number;
|
||||
|
||||
/**
|
||||
* @private (setter)
|
||||
*/
|
||||
function set position(value:Number):void;
|
||||
|
||||
/**
|
||||
* Gets or sets the volume of the media clip
|
||||
*/
|
||||
function get volume():Number;
|
||||
|
||||
/**
|
||||
* @private (setter)
|
||||
*/
|
||||
function set volume(value:Number):void;
|
||||
|
||||
/**
|
||||
* Gets or sets the mute value of the media clip (read-only)
|
||||
*/
|
||||
function get mute():Boolean;
|
||||
|
||||
/**
|
||||
* @private (setter)
|
||||
*/
|
||||
function set mute(value:Boolean):void;
|
||||
|
||||
/**
|
||||
* Gets or sets the auto start property of the media clip
|
||||
*/
|
||||
function get autoStart():Boolean;
|
||||
/**
|
||||
* @private (setter)
|
||||
*/
|
||||
function set autoStart(value:Boolean):void;
|
||||
|
||||
/**
|
||||
* Gets the playing value of the media clip (read-only)
|
||||
*/
|
||||
function get playing():Boolean;
|
||||
|
||||
/**
|
||||
* Gets the length of the media clip (read-only)
|
||||
*/
|
||||
function get length():Number;
|
||||
|
||||
/**
|
||||
* Gets the artist for the media clip (read-only)
|
||||
*/
|
||||
function get artist():String;
|
||||
|
||||
/**
|
||||
* Gets the title of the media clip (read-only)
|
||||
*/
|
||||
function get title():String;
|
||||
|
||||
/**
|
||||
* Gets or sets the bufferTime of the clip
|
||||
*/
|
||||
function get bufferTime():Number;
|
||||
|
||||
/**
|
||||
* @private (setter)
|
||||
*/
|
||||
function set bufferTime(value:Number):void;
|
||||
|
||||
/**
|
||||
* Gets or sets the checkForPolicyFile boolean
|
||||
*/
|
||||
function get checkForPolicyFile():Boolean;
|
||||
|
||||
/**
|
||||
* @private (setter)
|
||||
*/
|
||||
function set checkForPolicyFile(value:Boolean):void;
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
// Public Methods
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* Loads a media clip from a url string
|
||||
*/
|
||||
function loadMedia(urlValue:String, autoStart:Boolean = true):void;
|
||||
|
||||
/**
|
||||
* Pauses the media clip
|
||||
*/
|
||||
function pause():void;
|
||||
|
||||
/**
|
||||
* Plays the media clip
|
||||
*/
|
||||
function play():void;
|
||||
|
||||
/**
|
||||
* Stops the media clip
|
||||
*/
|
||||
function stop():void;
|
||||
}
|
||||
|
||||
}
|
||||
62
com/yahoo/astra/fl/controls/mediaPlayerClasses/IMediaController.as
Executable file
62
com/yahoo/astra/fl/controls/mediaPlayerClasses/IMediaController.as
Executable file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
|
||||
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
|
||||
*/
|
||||
package com.yahoo.astra.fl.controls.mediaPlayerClasses
|
||||
{
|
||||
/**
|
||||
* The IMediaController interface provides the methods and properties that a media controller requires.
|
||||
* All user defined media controllers should implement this interface.
|
||||
*/
|
||||
|
||||
public interface IMediaController
|
||||
{
|
||||
/**
|
||||
* Gets or sets an IMediaClip
|
||||
*/
|
||||
function get media():IMediaClip;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
function set media(value:IMediaClip):void;
|
||||
|
||||
/**
|
||||
* Seeks to specified position on the media clip
|
||||
*
|
||||
* @param pct position to seek
|
||||
*/
|
||||
function seek(pct:Number):void
|
||||
|
||||
/**
|
||||
* Stops playback on a media clip
|
||||
*/
|
||||
function stop():void
|
||||
|
||||
/**
|
||||
* Handles pausing a media clip
|
||||
*
|
||||
* @param pause Boolean indicating whether or pause or play
|
||||
*/
|
||||
function setPause(pause:Boolean):void
|
||||
|
||||
/**
|
||||
* Handles the muting of media clip
|
||||
*
|
||||
* @param value Boolean indicating whether to mute or unmute
|
||||
*/
|
||||
function setMute(value:Boolean):void
|
||||
|
||||
/**
|
||||
* Sets the volume of a clip
|
||||
*
|
||||
* @param value the level to set the volume
|
||||
*/
|
||||
function setVolume(value:Number):void
|
||||
|
||||
/**
|
||||
* Gets the volume of a clip
|
||||
*/
|
||||
function getVolume():Number
|
||||
}
|
||||
}
|
||||
35
com/yahoo/astra/fl/controls/mediaPlayerClasses/IMediaView.as
Executable file
35
com/yahoo/astra/fl/controls/mediaPlayerClasses/IMediaView.as
Executable file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
|
||||
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
|
||||
*/
|
||||
package com.yahoo.astra.fl.controls.mediaPlayerClasses
|
||||
{
|
||||
|
||||
/**
|
||||
* The IMediaView interface provides the methods and properties that a media view requires.
|
||||
* All user defined media views should implement this interface.
|
||||
*/
|
||||
|
||||
public interface IMediaView
|
||||
{
|
||||
/**
|
||||
* Gets or sets the media clip
|
||||
*/
|
||||
function get model():IMediaClip;
|
||||
|
||||
/**
|
||||
* @private (setter)
|
||||
*/
|
||||
function set model(value:IMediaClip):void;
|
||||
|
||||
/**
|
||||
* Gets or sets the media controller
|
||||
*/
|
||||
function get controller():IMediaController;
|
||||
|
||||
/**
|
||||
* @private (setter)
|
||||
*/
|
||||
function set controller(value:IMediaController):void;
|
||||
}
|
||||
}
|
||||
142
com/yahoo/astra/fl/controls/mediaPlayerClasses/IconButton.as
Executable file
142
com/yahoo/astra/fl/controls/mediaPlayerClasses/IconButton.as
Executable file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
|
||||
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
|
||||
*/
|
||||
package com.yahoo.astra.fl.controls.mediaPlayerClasses
|
||||
{
|
||||
import flash.events.Event;
|
||||
import flash.events.MouseEvent;
|
||||
import fl.controls.LabelButton;
|
||||
import fl.controls.BaseButton;
|
||||
import flash.text.TextFieldAutoSize;
|
||||
import fl.events.ComponentEvent;
|
||||
import fl.core.InvalidationType;
|
||||
import com.yahoo.astra.fl.events.MediaEvent;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
|
||||
//--------------------------------------
|
||||
// Class description
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* The IconButton class extends Label button. Icons are sized
|
||||
* based on the dimensions of the button and the <code>verticalPadding</code>
|
||||
* and <code>horizontalPadding</code> properties
|
||||
*/
|
||||
public class IconButton extends LabelButton
|
||||
{
|
||||
|
||||
//--------------------------------------
|
||||
// Constructor
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public function IconButton()
|
||||
{
|
||||
//sets _toggle to true
|
||||
//set _label to an empty string
|
||||
//adds itself to the DisplayList
|
||||
//sets the model and controller
|
||||
//adds event listeners
|
||||
super();
|
||||
_toggle = true;
|
||||
_label = "";
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Properties
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* The amount vertical space between the icon and the top and bottom edges
|
||||
*/
|
||||
public var verticalPadding:Number = 4;
|
||||
|
||||
/**
|
||||
* The amount horizontal space between the icon and the top and bottom edges
|
||||
*/
|
||||
public var horizontalPadding:Number = 4;
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
private static var defaultStyles:Object = {
|
||||
upSkin:"IconButton_upSkin",
|
||||
downSkin:"IconButton_downSkin",
|
||||
overSkin:"IconButton_overSkin",
|
||||
disabledSkin:"IconButton_disabledSkin",
|
||||
selectedDisabledSkin:"IconButton_selectedDisabledSkin",
|
||||
selectedUpSkin:"IconButton_selectedUpSkin",
|
||||
selectedDownSkin:"IconButton_selectedDownSkin",
|
||||
selectedOverSkin:"IconButton_selectedOverSkin",
|
||||
focusRectSkin:null,
|
||||
focusRectPadding:null,
|
||||
repeatDelay:500,
|
||||
repeatInterval:35
|
||||
};
|
||||
|
||||
//--------------------------------------
|
||||
// Public Methods
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* Gets the styles for the component
|
||||
* @return Object created from defaultStyle and the BaseButton styles.
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public static function getStyleDefinition():Object
|
||||
{
|
||||
return defaultStyles;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
// Protected Methods
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
override protected function drawIcon():void {
|
||||
var oldIcon:DisplayObject = icon;
|
||||
|
||||
var styleName:String = (enabled) ? mouseState : "disabled";
|
||||
if (selected) {
|
||||
styleName = "selected"+styleName.substr(0,1).toUpperCase()+styleName.substr(1);
|
||||
}
|
||||
styleName += "Icon";
|
||||
|
||||
var iconStyle:Object = getStyleValue(styleName);
|
||||
if (iconStyle == null) {
|
||||
// try the default icon:
|
||||
iconStyle = getStyleValue("icon");
|
||||
}
|
||||
if (iconStyle != null) {
|
||||
icon = getDisplayObjectInstance(iconStyle);
|
||||
icon.width = _width - (horizontalPadding*2);
|
||||
icon.height = _height - (verticalPadding*2);
|
||||
}
|
||||
if (icon != null) {
|
||||
addChildAt(icon,1);
|
||||
}
|
||||
|
||||
if (oldIcon != null && oldIcon != icon) {
|
||||
removeChild(oldIcon);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
124
com/yahoo/astra/fl/controls/mediaPlayerClasses/MediaController.as
Executable file
124
com/yahoo/astra/fl/controls/mediaPlayerClasses/MediaController.as
Executable file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
|
||||
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
|
||||
*/
|
||||
package com.yahoo.astra.fl.controls.mediaPlayerClasses
|
||||
{
|
||||
import com.yahoo.astra.fl.events.MediaEvent;
|
||||
/**
|
||||
* Implements IMediaController. Controller for media clips
|
||||
*/
|
||||
|
||||
public class MediaController implements IMediaController
|
||||
{
|
||||
|
||||
//--------------------------------------
|
||||
// Constructor
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function MediaController(clip:IMediaClip = null)
|
||||
{
|
||||
if(clip != null) _media = clip;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
// Properties
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* media to act as _model
|
||||
*/
|
||||
protected var _media:IMediaClip;
|
||||
|
||||
/**
|
||||
* Gets or sets the media clip
|
||||
*/
|
||||
public function get media():IMediaClip
|
||||
{
|
||||
return _media;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (setter)
|
||||
*/
|
||||
public function set media(value:IMediaClip):void
|
||||
{
|
||||
_media = value;
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Public Methods
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* sets the _media's position property the the received percentage times the _media's length
|
||||
*
|
||||
* @param pct position to seek
|
||||
*/
|
||||
public function seek(pct:Number):void
|
||||
{
|
||||
_media.position = pct*_media.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* calls the pause method on the _media
|
||||
*/
|
||||
public function stop():void
|
||||
{
|
||||
_media.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* calls pause and resume on the model
|
||||
*
|
||||
* @param pause Boolean indicating whether to call <code>pause()</code> or
|
||||
* <code>play()</code> on the media clip
|
||||
*/
|
||||
public function setPause(pause:Boolean):void
|
||||
{
|
||||
if(pause)
|
||||
{
|
||||
_media.pause();
|
||||
}
|
||||
else
|
||||
{
|
||||
_media.play();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the mute property on the model
|
||||
*
|
||||
* @param value Boolean to set to the media clip's <code>mute</code> property
|
||||
*/
|
||||
public function setMute(value:Boolean):void
|
||||
{
|
||||
_media.mute = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the volume property of the model
|
||||
*
|
||||
* @param value Number to set the media clip's <code>volume</code> property
|
||||
*/
|
||||
public function setVolume(value:Number):void
|
||||
{
|
||||
_media.volume = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the volume property of the model
|
||||
*
|
||||
* @return The media clip's <code>volume</code> property
|
||||
*/
|
||||
public function getVolume():Number
|
||||
{
|
||||
return _media.volume;
|
||||
}
|
||||
}
|
||||
}
|
||||
440
com/yahoo/astra/fl/controls/mediaPlayerClasses/MediaControlsView.as
Executable file
440
com/yahoo/astra/fl/controls/mediaPlayerClasses/MediaControlsView.as
Executable file
@@ -0,0 +1,440 @@
|
||||
/*
|
||||
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
|
||||
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
|
||||
*/
|
||||
package com.yahoo.astra.fl.controls.mediaPlayerClasses
|
||||
{
|
||||
import com.yahoo.astra.fl.controls.mediaPlayerClasses.*;
|
||||
import fl.core.UIComponent;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import flash.display.Sprite;
|
||||
import flash.events.Event;
|
||||
|
||||
//--------------------------------------
|
||||
// Styles
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* Horizontal padding between the controls.
|
||||
*
|
||||
* @default 4
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="horizontalPadding", type="Number")]
|
||||
|
||||
/**
|
||||
* Vertical padding between the media scrubber and the other controls.
|
||||
*
|
||||
* @default 0
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="verticalPadding", type="Number")]
|
||||
|
||||
/**
|
||||
* padding on the bottom of the view
|
||||
*
|
||||
* @default 4
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="bottomPadding", type="Number")]
|
||||
|
||||
/**
|
||||
* height of the media scrubber
|
||||
*
|
||||
* @default 16
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="mediaScrubberHeight", type="Number")]
|
||||
|
||||
/**
|
||||
* width of the play pause toggle button
|
||||
*
|
||||
* @default 25
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="playPauseWidth", type="Number")]
|
||||
|
||||
/**
|
||||
* height of the play pause toggle button
|
||||
*
|
||||
* @default 15
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="playPauseHeight", type="Number")]
|
||||
|
||||
/**
|
||||
* width of the mute toggle button
|
||||
*
|
||||
* @default 15
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="muteToggleWidth", type="Number")]
|
||||
|
||||
/**
|
||||
* height of the mute toggle button
|
||||
*
|
||||
* @default 15
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="muteToggleHeight", type="Number")]
|
||||
|
||||
/**
|
||||
* width of the volume control
|
||||
*
|
||||
* @default 60
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="volumeControlWidth", type="Number")]
|
||||
|
||||
/**
|
||||
* height of the volume control
|
||||
*
|
||||
* @default 15
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="volumeControlHeight", type="Number")]
|
||||
|
||||
/**
|
||||
* horizontal padding for the icon in the play pause button
|
||||
*
|
||||
* @default 8
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="playPauseHorizontalPadding", type="Number")]
|
||||
|
||||
/**
|
||||
* vertical padding between the edges of the play pause button and its
|
||||
* icon
|
||||
*
|
||||
* @default 3
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="playPauseVerticalPadding", type="Number")]
|
||||
|
||||
/**
|
||||
* horizontal padding for the icon in the mute toggle button
|
||||
*
|
||||
* @default 1
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="muteToggleHorizontalPadding", type="Number")]
|
||||
/**
|
||||
* vertical padding for the icon in the mute toggle button
|
||||
*
|
||||
* @default 1
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="muteToggleVerticalPadding", type="Number")]
|
||||
|
||||
/**
|
||||
* height of the info view
|
||||
*
|
||||
* @default 15
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="infoViewHeight", type="Number")]
|
||||
|
||||
//--------------------------------------
|
||||
// Class Description
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* MediaControlsView extends UIComponent. Assembles different views for a MediaClip
|
||||
*
|
||||
* @see fl.core.UIComponent
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
* @author Dwight Bridges
|
||||
*/
|
||||
public class MediaControlsView extends UIComponent
|
||||
{
|
||||
|
||||
//--------------------------------------
|
||||
// Constructor
|
||||
//--------------------------------------
|
||||
/**
|
||||
* Constructor
|
||||
* @param container
|
||||
* @param model
|
||||
* @param controller
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public function MediaControlsView(container:DisplayObjectContainer, model:IMediaClip = null, controller:MediaController = null):void
|
||||
{
|
||||
_mediaClip = model;
|
||||
_mediaController = controller;
|
||||
if(container != null) container.addChild(this);
|
||||
_background = getDisplayObjectInstance(getStyleValue("background")) as Sprite;
|
||||
if(_background != null)
|
||||
{
|
||||
addChild(_background);
|
||||
_background.width = width;
|
||||
_background.height = height;
|
||||
}
|
||||
|
||||
var horizontalPadding:Number = Number(getStyleValue("horizontalPadding"));
|
||||
var verticalPadding:Number = Number(getStyleValue("verticalPadding"));
|
||||
var infoViewHeight:Number = Number(getStyleValue("infoViewHeight"));
|
||||
var volumeControlHeight:Number = Number(getStyleValue("volumeControlHeight"));
|
||||
var muteToggleButtonHeight:Number = Number(getStyleValue("muteToggleHeight"));
|
||||
var playPauseButtonHeight:Number = Number(getStyleValue("playPauseHeight"));
|
||||
|
||||
var controlsHeight:Number = Math.max(playPauseButtonHeight, muteToggleButtonHeight, volumeControlHeight, infoViewHeight);
|
||||
|
||||
_mediaScrubberView = new MediaScrubberView(this, _mediaClip, _mediaController);
|
||||
_mediaScrubberView.setSize(width - (horizontalPadding *2), Number(getStyleValue("mediaScrubberHeight")));
|
||||
|
||||
_playPauseButton = new PlayPauseToggleButton(this, _mediaClip, _mediaController);
|
||||
_playPauseButton.width = Number(getStyleValue("playPauseWidth"));
|
||||
_playPauseButton.height = Number(getStyleValue("playPauseHeight"));
|
||||
_playPauseButton.x = horizontalPadding;
|
||||
_playPauseButton.y = _playPauseButton.height < controlsHeight?_mediaScrubberView.bottom + verticalPadding + ((controlsHeight-_playPauseButton.height)/2):_mediaScrubberView.bottom + verticalPadding;
|
||||
_playPauseButton.verticalPadding = Number(getStyleValue("playPauseVerticalPadding"));
|
||||
_playPauseButton.horizontalPadding = Number(getStyleValue("playPauseHorizontalPadding"));
|
||||
|
||||
_infoView = new MediaInfoView(this, _mediaClip, _mediaController);
|
||||
|
||||
_muteToggleButton = new MuteToggleButton(this, _mediaClip, _mediaController);
|
||||
|
||||
_volumeControl = new VolumeSlider(this, _mediaClip, _mediaController);
|
||||
|
||||
_muteToggleButton.width = Number(getStyleValue("muteToggleWidth"));
|
||||
_muteToggleButton.height = Number(getStyleValue("muteToggleHeight"));
|
||||
_muteToggleButton.y = _muteToggleButton.height < controlsHeight?_mediaScrubberView.bottom + verticalPadding + ((controlsHeight-_muteToggleButton.height)/2):_mediaScrubberView.bottom + verticalPadding;
|
||||
_muteToggleButton.verticalPadding = Number(getStyleValue("muteToggleVerticalPadding"));
|
||||
_muteToggleButton.horizontalPadding = Number(getStyleValue("muteToggleHorizontalPadding"));
|
||||
_muteToggleButton.x = _volumeControl.x - _muteToggleButton.width - horizontalPadding;
|
||||
|
||||
_volumeControl.setSize(Number(getStyleValue("volumeControlWidth")), Number(getStyleValue("volumeControlHeight")));
|
||||
_volumeControl.x = width - (horizontalPadding + _volumeControl.width);
|
||||
_volumeControl.y = _volumeControl.height < controlsHeight?_mediaScrubberView.bottom + verticalPadding + ((controlsHeight-_volumeControl.height)/2):_mediaScrubberView.bottom + verticalPadding;
|
||||
|
||||
_infoView.x = _playPauseButton.right + horizontalPadding;
|
||||
_infoView.y = _infoView.height < controlsHeight?_mediaScrubberView.bottom + verticalPadding + ((controlsHeight-_infoView.height)/2):_mediaScrubberView.bottom + verticalPadding;
|
||||
_infoView.width = _muteToggleButton.x - (_infoView.x + horizontalPadding);
|
||||
_infoView.height = Number(getStyleValue("infoViewHeight"));
|
||||
|
||||
_background.height = height = _volumeControl.height + _mediaScrubberView.bottom + Number(getStyleValue("bottomPadding"));
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Properties
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
private static var defaultStyles:Object = {
|
||||
background:"background",
|
||||
playPauseWidth:25,
|
||||
playPauseHeight:15,
|
||||
muteToggleWidth:15,
|
||||
muteToggleHeight:15,
|
||||
mediaScrubberHeight:16,
|
||||
volumeControlHeight:15,
|
||||
volumeControlWidth:60,
|
||||
muteToggleVerticalPadding:1,
|
||||
muteToggleHorizontalPadding:1,
|
||||
playPauseVerticalPadding:3,
|
||||
verticalPadding:0,
|
||||
horizontalPadding:4,
|
||||
bottomPadding:4,
|
||||
infoViewHeight:15,
|
||||
playPauseHorizontalPadding:8
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _mediaClip:IMediaClip;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _mediaController:MediaController;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _playPauseButton:PlayPauseToggleButton;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _muteToggleButton:MuteToggleButton;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _volumeControl:VolumeSlider;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _mediaScrubberView:MediaScrubberView;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
public var _infoView:MediaInfoView;
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
private var _mediaTypeMap:Object =
|
||||
{
|
||||
audio:AudioClip
|
||||
};
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _background:Sprite;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
override public function set width(value:Number):void
|
||||
{
|
||||
super.width = (value > minimumWidth)?value:minimumWidth;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _minimumWidth:Number;
|
||||
|
||||
/**
|
||||
* Gets the minimum width for the MediaControlsView (read-only). The minimum width of the
|
||||
* MediaControlsView is determined by the sum of muteToggleWidth, playPauseWidth, volumeControlWidth
|
||||
* minimumInfoViewWidth and total horizontal padding.
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public function get minimumWidth():Number
|
||||
{
|
||||
_minimumWidth = Number(getStyleValue("muteToggleWidth")) + Number(getStyleValue("playPauseWidth")) + Number(getStyleValue("volumeControlWidth")) + 80 + (Number(getStyleValue("horizontalPadding"))*5);
|
||||
return _minimumWidth;
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Public Methods
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* getStyleDefinition - returns defaultStyles
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public static function getStyleDefinition():Object
|
||||
{
|
||||
return mergeStyles(defaultStyles, UIComponent.getStyleDefinition());
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Protected Methods
|
||||
//--------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
override protected function draw():void
|
||||
{
|
||||
super.draw();
|
||||
drawLayout();
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*
|
||||
* Sizes and positions all elements of the MediaControlsView.
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
protected function drawLayout():void
|
||||
{
|
||||
var horizontalPadding:Number = Number(getStyleValue("horizontalPadding"));
|
||||
var verticalPadding:Number = Number(getStyleValue("verticalPadding"));
|
||||
var infoViewHeight:Number = Number(getStyleValue("infoViewHeight"));
|
||||
var volumeControlHeight:Number = Number(getStyleValue("volumeControlHeight"));
|
||||
var muteToggleButtonHeight:Number = Number(getStyleValue("muteToggleHeight"));
|
||||
var playPauseButtonHeight:Number = Number(getStyleValue("playPauseHeight"));
|
||||
|
||||
var controlsHeight:Number = Math.max(playPauseButtonHeight, muteToggleButtonHeight, volumeControlHeight, infoViewHeight);
|
||||
|
||||
_mediaScrubberView.x = horizontalPadding;
|
||||
_mediaScrubberView.y = 0;
|
||||
_mediaScrubberView.setSize(width - (horizontalPadding *2), Number(getStyleValue("mediaScrubberHeight")))
|
||||
|
||||
_playPauseButton.width = Number(getStyleValue("playPauseWidth"));
|
||||
_playPauseButton.height = playPauseButtonHeight;
|
||||
_playPauseButton.x = horizontalPadding;
|
||||
_playPauseButton.y = _playPauseButton.height < controlsHeight?_mediaScrubberView.bottom + verticalPadding + ((controlsHeight-_playPauseButton.height)/2):_mediaScrubberView.bottom + verticalPadding;
|
||||
_playPauseButton.verticalPadding = Number(getStyleValue("playPauseVerticalPadding"));
|
||||
_playPauseButton.horizontalPadding = Number(getStyleValue("playPauseHorizontalPadding"));
|
||||
|
||||
_volumeControl.width = Number(getStyleValue("volumeControlWidth"));
|
||||
_volumeControl.height = volumeControlHeight;
|
||||
_volumeControl.x = width - (horizontalPadding + _volumeControl.width);
|
||||
_volumeControl.y = _volumeControl.height < controlsHeight?_mediaScrubberView.bottom + verticalPadding + ((controlsHeight-_volumeControl.height)/2):_mediaScrubberView.bottom + verticalPadding;
|
||||
|
||||
_muteToggleButton.width = Number(getStyleValue("muteToggleWidth"));
|
||||
_muteToggleButton.height = muteToggleButtonHeight;
|
||||
_muteToggleButton.y = _muteToggleButton.height < controlsHeight?_mediaScrubberView.bottom + verticalPadding + ((controlsHeight-_muteToggleButton.height)/2):_mediaScrubberView.bottom + verticalPadding;
|
||||
_muteToggleButton.verticalPadding = Number(getStyleValue("muteToggleVerticalPadding"));
|
||||
_muteToggleButton.horizontalPadding = Number(getStyleValue("muteToggleHorizontalPadding"));
|
||||
_muteToggleButton.x = _volumeControl.x - _muteToggleButton.width - horizontalPadding;
|
||||
|
||||
_infoView.x = _playPauseButton.right + horizontalPadding;
|
||||
_infoView.width = _muteToggleButton.x - (_infoView.x + horizontalPadding);
|
||||
_infoView.height = infoViewHeight;
|
||||
_infoView.y = _infoView.height < controlsHeight?_mediaScrubberView.bottom + verticalPadding + ((controlsHeight-_infoView.height)/2):_mediaScrubberView.bottom + verticalPadding;
|
||||
_background.height = height = verticalPadding + controlsHeight + _mediaScrubberView.bottom + Number(getStyleValue("bottomPadding"));
|
||||
_background.width = width;
|
||||
}
|
||||
}
|
||||
}
|
||||
306
com/yahoo/astra/fl/controls/mediaPlayerClasses/MediaInfoView.as
Executable file
306
com/yahoo/astra/fl/controls/mediaPlayerClasses/MediaInfoView.as
Executable file
@@ -0,0 +1,306 @@
|
||||
/*
|
||||
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
|
||||
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
|
||||
*/
|
||||
package com.yahoo.astra.fl.controls.mediaPlayerClasses
|
||||
{
|
||||
import com.yahoo.astra.fl.events.MediaEvent;
|
||||
|
||||
import fl.core.UIComponent;
|
||||
import fl.managers.IFocusManagerComponent;
|
||||
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import flash.display.Sprite;
|
||||
import flash.events.*;
|
||||
import flash.geom.Point;
|
||||
import flash.text.TextField;
|
||||
import flash.text.TextFieldAutoSize;
|
||||
import flash.text.TextFormat;
|
||||
import flash.utils.Timer;
|
||||
|
||||
//--------------------------------------
|
||||
// Class Description
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* MediaInfoView extends MediaView. Creates a text ticker displaying the artist and title of the media clip.
|
||||
*
|
||||
* @see com.yahoo.astra.fl.controls.mediaPlayerClasses.MediaView
|
||||
* @see com.yahoo.astra.fl.controls.mediaPlayerClasses.IMediaView
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
* @author Dwight Bridges
|
||||
*/
|
||||
public class MediaInfoView extends MediaView implements IFocusManagerComponent
|
||||
{
|
||||
|
||||
//--------------------------------------
|
||||
// Constructor
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param container
|
||||
* @param model
|
||||
* @param controller
|
||||
*
|
||||
* Sets the model and controller for the MediaInfoView
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public function MediaInfoView(container:DisplayObjectContainer = null, model:IMediaClip = null, controller:IMediaController = null)
|
||||
{
|
||||
super(container, model, controller);
|
||||
_background = getDisplayObjectInstance(getStyleValue("background")) as Sprite;
|
||||
if(_background != null)
|
||||
{
|
||||
addChild(_background);
|
||||
_background.width = width;
|
||||
_background.height = height;
|
||||
}
|
||||
_textHolder = new Sprite();
|
||||
_textHolder.cacheAsBitmap = true;
|
||||
addChild(_textHolder);
|
||||
_mask = getDisplayObjectInstance(getStyleValue("mask")) as Sprite;
|
||||
_mask.cacheAsBitmap = true;
|
||||
_mask.width = width;
|
||||
_mask.height = height;
|
||||
addChild(_mask);
|
||||
_textHolder.mask = _mask;
|
||||
_timer = new Timer(50);
|
||||
_timer.addEventListener(TimerEvent.TIMER, positionUpdateHandler);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Class mixins
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Placeholder for mixin by MediaInfoViewAccImpl.
|
||||
*/
|
||||
public static var createAccessibilityImplementation:Function;
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
// Properties
|
||||
//--------------------------------------
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _artist:String;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _title:String;
|
||||
|
||||
/**
|
||||
* The string to display in the scrolling text field
|
||||
*/
|
||||
public var text:String = "";
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _data:Array
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _timer:Timer;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _textHolder:Sprite;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _mask:Sprite;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _points:Array;
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* default styles for the MediaInfoView
|
||||
*/
|
||||
private static var defaultStyles:Object =
|
||||
{
|
||||
background:"InfoView_backgroundSkin",
|
||||
mask:"InfoView_mask",
|
||||
textFormat:new TextFormat("_sans", 9, 0xeeeeee)
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _background:Sprite;
|
||||
|
||||
/**
|
||||
* @private (override))
|
||||
*/
|
||||
override public function set width(value:Number):void
|
||||
{
|
||||
var tempWidth:Number = width;
|
||||
super.width = value;
|
||||
_width = value;
|
||||
if(_mask != null)
|
||||
{
|
||||
_mask.width = value;
|
||||
_background.width = value;
|
||||
if(_data != null && _data.length > 0) _data[0].x = (width/tempWidth) * _data[0].x;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (override)
|
||||
*/
|
||||
override public function set height(value:Number):void
|
||||
{
|
||||
var tempHeight:Number = height;
|
||||
super.height = value;
|
||||
_height = value;
|
||||
if(_mask != null)
|
||||
{
|
||||
_mask.height = value;
|
||||
_background.height = value;
|
||||
_mask.x = _background.x = 0;
|
||||
if(_data != null && _data.length > 0) _data[0].y = (height/tempHeight) * _data[0].y;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Public Methods
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* getStyleDefinition - returns defaultStyles
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public static function getStyleDefinition():Object
|
||||
{
|
||||
return mergeStyles(defaultStyles, UIComponent.getStyleDefinition());
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Protected Methods
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* attaches event listeners to the _model
|
||||
* <p>called after the _model is set</p>
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
override protected function addListeners():void
|
||||
{
|
||||
_model.addEventListener(MediaEvent.INFO_CHANGE, mediaInfoChangeHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* mediaInfoChangeHandler
|
||||
* <p>fired by the MediaEvent.INFO_CHANGE</p>
|
||||
* <p>checks the _artist and _title against the _model's<p>
|
||||
* <p>if different, remove any existing text fields, reset properties and start the timer</p>
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
private function mediaInfoChangeHandler(event:MediaEvent):void
|
||||
{
|
||||
if(_model.artist != _artist || _model.title != _title)
|
||||
{
|
||||
_artist = _model.artist;
|
||||
_title = _model.title;
|
||||
if(_data != null)
|
||||
{
|
||||
|
||||
var len:int = _data.length;
|
||||
for(var i:int = len-1;i > -1; i--)
|
||||
{
|
||||
_textHolder.removeChild(_data[i]);
|
||||
_data.pop();
|
||||
}
|
||||
}
|
||||
_data = [];
|
||||
_points = [];
|
||||
text = _artist + " - " + _title;
|
||||
_data[_data.length] = getTextField(text);
|
||||
_timer.stop();
|
||||
_timer.start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* adds a text field to the _textHolder
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
protected function getTextField(value:String):TextField
|
||||
{
|
||||
var tf:TextFormat = new TextFormat();
|
||||
tf.color = 0xeeeeee;
|
||||
tf.font = "_sans";
|
||||
tf.size = 9;
|
||||
var textField:TextField = new TextField();
|
||||
textField.multiline = false;
|
||||
textField.wordWrap = false;
|
||||
textField.autoSize = TextFieldAutoSize.LEFT;
|
||||
textField.selectable = false;
|
||||
textField.text = value;
|
||||
textField.setTextFormat(tf);
|
||||
var textX:Number = _textHolder.width;
|
||||
_textHolder.addChild(textField);
|
||||
textField.x = textX;
|
||||
return textField;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
protected function positionUpdateHandler(event:TimerEvent):void
|
||||
{
|
||||
for(var i:int = 0; i < _data.length; i++)
|
||||
{
|
||||
_points[i] = globalToLocal(_textHolder.localToGlobal(new Point(_data[i].x + _data[i].textWidth, _data[i].y))).x;
|
||||
|
||||
if(_points[i] < 0)
|
||||
{
|
||||
_data[i].x = _textHolder.globalToLocal(localToGlobal(new Point(width, 0))).x;
|
||||
}
|
||||
else
|
||||
{
|
||||
_data[i].x--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
override protected function initializeAccessibility():void
|
||||
{
|
||||
if (MediaInfoView.createAccessibilityImplementation != null)
|
||||
MediaInfoView.createAccessibilityImplementation(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
329
com/yahoo/astra/fl/controls/mediaPlayerClasses/MediaScrubberView.as
Executable file
329
com/yahoo/astra/fl/controls/mediaPlayerClasses/MediaScrubberView.as
Executable file
@@ -0,0 +1,329 @@
|
||||
/*
|
||||
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
|
||||
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
|
||||
*/
|
||||
package com.yahoo.astra.fl.controls.mediaPlayerClasses
|
||||
{
|
||||
import com.yahoo.astra.fl.events.MediaEvent;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import fl.core.UIComponent;
|
||||
import fl.controls.BaseButton;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.Sprite;
|
||||
import flash.events.MouseEvent;
|
||||
import flash.events.ProgressEvent;
|
||||
import fl.events.ComponentEvent;
|
||||
|
||||
//--------------------------------------
|
||||
// Class Description
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* MediaScrubber extends MediaView implements IMediaView and creates a slider to control
|
||||
* cueing and rewinding for a media clip.
|
||||
*
|
||||
* @see com.yahoo.astra.fl.controls.mediaPlayerClasses.MediaView
|
||||
* @see com.yahoo.astra.fl.controls.mediaPlayerClasses.IMediaView
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
* @author Dwight Bridges
|
||||
*/
|
||||
public class MediaScrubberView extends MediaView implements IMediaView
|
||||
{
|
||||
|
||||
//--------------------------------------
|
||||
// Constructor
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param container display object container that the MediaScrubberView will be added to
|
||||
* @param model media clip that the MediaScrubberView will observe
|
||||
* @param controller media controller that will handle user input from the MediaScrubberView
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public function MediaScrubberView(container:DisplayObjectContainer = null, model:IMediaClip = null, controller:IMediaController = null)
|
||||
{
|
||||
_scrubbing = false;
|
||||
super(container, model, controller);
|
||||
_durationIndicator = getDisplayObjectInstance(getStyleValue("durationIndicatorSkin")) as Sprite;
|
||||
_durationIndicator.width = width;
|
||||
addChild(_durationIndicator);
|
||||
_loadIndicator = getDisplayObjectInstance(getStyleValue("loadIndicator")) as Sprite;
|
||||
_loadIndicator.width = 0;
|
||||
addChild(_loadIndicator);
|
||||
_progressIndicator = getDisplayObjectInstance(getStyleValue("progressIndicator")) as Sprite;
|
||||
_progressIndicator.width = 0;
|
||||
addChild(_progressIndicator);
|
||||
_clickStrip = getDisplayObjectInstance(getStyleValue("progressIndicator")) as Sprite;
|
||||
_clickStrip.width = 0;
|
||||
_clickStrip.alpha = 0;
|
||||
_clickStrip.addEventListener(MouseEvent.MOUSE_DOWN, clickStripHandler);
|
||||
addChild(_clickStrip);
|
||||
_scrubButton = new BaseButton();
|
||||
setChildStyles(_scrubButton, defaultKnobStyles);
|
||||
_scrubButton.addEventListener(MouseEvent.MOUSE_DOWN, scrubButtonMouseDownHandler);
|
||||
addChild(_scrubButton);
|
||||
addEventListener(ComponentEvent.RESIZE, resizeEventHandler);
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Properties
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* background bar for the MediaScrubber
|
||||
*/
|
||||
protected var _durationIndicator:Sprite;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* bar indicating the percentage of the media that has loaded
|
||||
*/
|
||||
protected var _loadIndicator:Sprite;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* bar indicating the progress of the media's playback
|
||||
*/
|
||||
protected var _progressIndicator:Sprite;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* knob used to seek the media
|
||||
*/
|
||||
protected var _scrubButton:BaseButton;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* hot spot for clicking to seek the media
|
||||
*/
|
||||
protected var _clickStrip:Sprite;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* distance that the _scrubButton can travel
|
||||
* Equal to the _durationIndicator's width minus the _scrubButton
|
||||
*/
|
||||
protected var _range:Number;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* boolean indicating whether or not the user is scrubbing the media
|
||||
*/
|
||||
protected var _scrubbing:Boolean;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* indicates the x coordinate of the _scrubButton that user pressed
|
||||
*/
|
||||
protected var _mouseDownX:Number;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* indicates the amount of space to the right of the cursor on the _scrubButton
|
||||
*/
|
||||
protected var _mouseDownRightPadding:Number;
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
private static var defaultStyles:Object = {
|
||||
durationIndicatorSkin:"scrub_durationSkin",
|
||||
loadIndicator:"scrub_loadSkin",
|
||||
progressIndicator:"scrub_progressSkin"
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
protected static var defaultKnobStyles:Object = {
|
||||
upSkin:"scrubButton_upSkin",
|
||||
downSkin:"scrubButton_downSkin",
|
||||
overSkin:"scrubButton_overSkin",
|
||||
disabledSkin:"scrubButton_upSkin",
|
||||
selectedDisabledSkin:"scrubButton_upSkin",
|
||||
selectedUpSkin:"scrubButton_upSkin",
|
||||
selectedDownSkin:"scrubButton_downSkin",
|
||||
selectedOverSkin:"scrubButton_overSkin"
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _loaded:Boolean = false;
|
||||
|
||||
//--------------------------------------
|
||||
// Public Methods
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* Gets the styles for the component
|
||||
*
|
||||
* @return defaultStyles
|
||||
*/
|
||||
public static function getStyleDefinition():Object
|
||||
{
|
||||
return defaultStyles;
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Protected Methods
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*
|
||||
* Sizes and positions all elements of the MediaControlsView.
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
protected function resizeEventHandler(event:ComponentEvent):void
|
||||
{
|
||||
if(_loaded) _clickStrip.width = _loadIndicator.width = width;
|
||||
_durationIndicator.width = width;
|
||||
_range = width - _scrubButton.width;
|
||||
_progressIndicator.height = _durationIndicator.height = _loadIndicator.height = height/4;
|
||||
_progressIndicator.y = _durationIndicator.y = _loadIndicator.y = (height - _durationIndicator.height)/2;
|
||||
_clickStrip.height = height;
|
||||
_clickStrip.y = 0;
|
||||
_scrubButton.height = _scrubButton.width = height/2;
|
||||
_scrubButton.y = (height - _scrubButton.height)/2;
|
||||
_range = width - _scrubButton.width;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*
|
||||
* @param event MouseEvent
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
protected function clickStripHandler(event:MouseEvent):void
|
||||
{
|
||||
//move the _scrubButton to the area that was pressed
|
||||
//move the _progress indicator to the area that was pressed
|
||||
//pass event to the scrubButtonMouseHandler
|
||||
_scrubButton.x = Math.max(0, Math.min(_range, mouseX - (_scrubButton.width/2)));
|
||||
_progressIndicator.width = _scrubButton.x + _scrubButton.width/2;
|
||||
scrubButtonMouseDownHandler(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
override protected function addListeners():void
|
||||
{
|
||||
//attach event listeners to the after it has been set
|
||||
_model.addEventListener(ProgressEvent.PROGRESS , progressUpdateHandler);
|
||||
_model.addEventListener(MediaEvent.MEDIA_POSITION, mediaPositionUpdateHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
override protected function removeListeners():void
|
||||
{
|
||||
//remove event listeners from the _model before a new _model is set
|
||||
_model.removeEventListener(ProgressEvent.PROGRESS , progressUpdateHandler);
|
||||
_model.removeEventListener(MediaEvent.MEDIA_POSITION, mediaPositionUpdateHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*
|
||||
* @param event MediaEvent
|
||||
*/
|
||||
protected function mediaPositionUpdateHandler(event:MediaEvent):void
|
||||
{
|
||||
//moves the _scrubButton and _progressIndicator to represent the correct position of the media's playhead
|
||||
//attached to the MEDIA_POSITION event dispatched by the _model
|
||||
if(!_scrubbing)
|
||||
{
|
||||
if(!isNaN(event.position/event.duration * _range))
|
||||
{
|
||||
_scrubButton.x = event.position/event.duration * _range;
|
||||
_progressIndicator.width = _scrubButton.x + _scrubButton.width/2;
|
||||
}
|
||||
else if(event.position == 0)
|
||||
{
|
||||
_scrubButton.x = _progressIndicator.width = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*
|
||||
* @param event MouseEvent
|
||||
*/
|
||||
protected function scrubButtonMouseDownHandler(event:MouseEvent):void
|
||||
{
|
||||
//set _scrubbing to true
|
||||
//set the value of _mouseDownX and _mouseDownRightPadding
|
||||
//pause the media through the controller
|
||||
//add MOUSE_UP and MOUSE_MOVE listeners
|
||||
_scrubbing = true;
|
||||
_mouseDownX = _scrubButton.mouseX;
|
||||
_mouseDownRightPadding = _scrubButton.width - _mouseDownX;
|
||||
_controller.stop();
|
||||
this.stage.addEventListener(MouseEvent.MOUSE_UP, scrubButtonMouseUpHandler, false, 0, true);
|
||||
this.stage.addEventListener(MouseEvent.MOUSE_MOVE, scrubButtonMouseMoveHandler, false, 0, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*
|
||||
* @param event MouseEvent
|
||||
*/
|
||||
protected function scrubButtonMouseUpHandler(event:MouseEvent):void
|
||||
{
|
||||
//set _scrubbing to false
|
||||
//remove the MOUSE_UP and MOUSE_DOWN listeners
|
||||
//seek the media through the controller
|
||||
_scrubbing = false;
|
||||
this.stage.removeEventListener(MouseEvent.MOUSE_UP, scrubButtonMouseUpHandler);
|
||||
this.stage.removeEventListener(MouseEvent.MOUSE_MOVE, scrubButtonMouseMoveHandler);
|
||||
_controller.seek(_scrubButton.x/_range);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*
|
||||
* @param event MouseEvent
|
||||
*/
|
||||
protected function scrubButtonMouseMoveHandler(event:MouseEvent):void
|
||||
{
|
||||
//attached to the MOUSE_MOVE event of the _scrubButton
|
||||
//moves the _scrubButton and adjusts the _progressIndicator with the position of the mouse
|
||||
_scrubButton.x = Math.max(0, Math.min((_loadIndicator.width - _scrubButton.width), (mouseX - _mouseDownX)));
|
||||
_progressIndicator.width = _scrubButton.x + _scrubButton.width/2;
|
||||
event.updateAfterEvent();
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*
|
||||
* @param event ProgressEvent
|
||||
*/
|
||||
protected function progressUpdateHandler(event:ProgressEvent):void
|
||||
{
|
||||
//update the _loadIndicator and _clickStrip width with percentage of the media that has loaded
|
||||
_clickStrip.width = _loadIndicator.width = Math.min((event.bytesLoaded/event.bytesTotal)*width, width);
|
||||
if(event.bytesLoaded >= event.bytesTotal)
|
||||
{
|
||||
_loaded = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_loaded = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
143
com/yahoo/astra/fl/controls/mediaPlayerClasses/MediaView.as
Executable file
143
com/yahoo/astra/fl/controls/mediaPlayerClasses/MediaView.as
Executable file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
|
||||
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
|
||||
*/
|
||||
package com.yahoo.astra.fl.controls.mediaPlayerClasses
|
||||
{
|
||||
import com.yahoo.astra.fl.events.MediaEvent;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import fl.core.UIComponent;
|
||||
import fl.controls.BaseButton;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.Sprite;
|
||||
import flash.events.MouseEvent;
|
||||
import flash.events.ProgressEvent;
|
||||
|
||||
//--------------------------------------
|
||||
// Class Description
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* MediaView is an abstract class that extends UIComponent, implements
|
||||
* the IMediaView interface and defines the functionality for a MediaView class.
|
||||
* MediaView classes should extend the MediaView class.
|
||||
*/
|
||||
|
||||
public class MediaView extends UIComponent implements IMediaView
|
||||
{
|
||||
|
||||
//--------------------------------------
|
||||
// Constructor
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param container display object container that the MediaView will be added to
|
||||
* @param model media clip that the MediaView will observe
|
||||
* @param controller media controller that will handle user input from the MediaView
|
||||
*/
|
||||
public function MediaView(container:DisplayObjectContainer = null, model:IMediaClip = null, controller:IMediaController = null)
|
||||
{
|
||||
super();
|
||||
if(container != null) container.addChild(this);
|
||||
if(model != null)
|
||||
{
|
||||
_model = model;
|
||||
addListeners();
|
||||
}
|
||||
if(controller != null) _controller = controller;
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Properties
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* the media that is being controlled by the MediaScrubber
|
||||
*/
|
||||
protected var _model:IMediaClip;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* the controller for the Media
|
||||
*/
|
||||
protected var _controller:IMediaController;
|
||||
|
||||
/**
|
||||
* Gets or sets the media clip
|
||||
*/
|
||||
public function get model():IMediaClip
|
||||
{
|
||||
return _model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (setter)
|
||||
*/
|
||||
public function set model(value:IMediaClip):void
|
||||
{
|
||||
if(_model != null) removeListeners();
|
||||
_model = value;
|
||||
addListeners();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets or sets the media controller
|
||||
*/
|
||||
public function get controller():IMediaController
|
||||
{
|
||||
return _controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (setter)
|
||||
*/
|
||||
public function set controller(value:IMediaController):void
|
||||
{
|
||||
_controller = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the coordinate for the bottom edge of the component (read-only)
|
||||
*/
|
||||
public function get bottom():Number
|
||||
{
|
||||
return y + height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the coordinate for the right edge of the component (read-only)
|
||||
*/
|
||||
public function get right():Number
|
||||
{
|
||||
return x + width;
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Protected Methods
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected function addListeners():void{}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected function removeListeners():void{}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected function setChildStyles(child:UIComponent,styleMap:Object):void
|
||||
{
|
||||
//set styles from a specified object to the specified component
|
||||
for (var n:String in styleMap)
|
||||
{
|
||||
child.setStyle(n, styleMap[n]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
245
com/yahoo/astra/fl/controls/mediaPlayerClasses/MuteToggleButton.as
Executable file
245
com/yahoo/astra/fl/controls/mediaPlayerClasses/MuteToggleButton.as
Executable file
@@ -0,0 +1,245 @@
|
||||
/*
|
||||
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
|
||||
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
|
||||
*/
|
||||
package com.yahoo.astra.fl.controls.mediaPlayerClasses
|
||||
{
|
||||
import com.yahoo.astra.fl.events.MediaEvent;
|
||||
|
||||
import fl.events.ComponentEvent;
|
||||
|
||||
import flash.accessibility.Accessibility;
|
||||
import flash.accessibility.AccessibilityProperties;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
|
||||
//--------------------------------------
|
||||
// Class Description
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* MuteToggleButton extends MediaView and creates an IconButton to toggle
|
||||
* the mute state of a media clip.
|
||||
*
|
||||
* @see com.yahoo.astra.fl.controls.mediaPlayerClasses.MediaView
|
||||
* @see com.yahoo.astra.fl.controls.mediaPlayerClasses.IconButton
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public class MuteToggleButton extends MediaView
|
||||
{
|
||||
|
||||
//--------------------------------------
|
||||
// Constructor
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param container display object container that the MuteToggleButton will be added to
|
||||
* @param model media clip that the MuteToggleButton will observe
|
||||
* @param controller media controller that will handle user input from the MuteToggleButton
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public function MuteToggleButton(container:DisplayObjectContainer, model:IMediaClip, controller:MediaController)
|
||||
{
|
||||
super(container, model, controller);
|
||||
_button = new IconButton();
|
||||
_button.selected = !_model.mute;
|
||||
_button.width = width;
|
||||
_button.height = height;
|
||||
|
||||
_button.accessibilityProperties = getCurrentAccessibilityProperties();
|
||||
|
||||
addChild(_button);
|
||||
setChildStyles(_button, getStyleDefinition());
|
||||
_button.selected = !_model.mute;
|
||||
_button.addEventListener(ComponentEvent.BUTTON_DOWN, dispatchToggleChange);
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Properties
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _button:IconButton;
|
||||
|
||||
/**
|
||||
* Gets or sets the vertical padding of the button
|
||||
*/
|
||||
public function get verticalPadding():Number
|
||||
{
|
||||
return _button.verticalPadding;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (setter)
|
||||
*/
|
||||
public function set verticalPadding(value:Number):void
|
||||
{
|
||||
_button.verticalPadding = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets or set the amount of horizontal space between the icon and the sides of the button
|
||||
*/
|
||||
public function get horizontalPadding():Number
|
||||
{
|
||||
return _button.horizontalPadding;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (setter)
|
||||
*/
|
||||
public function set horizontalPadding(value:Number):void
|
||||
{
|
||||
_button.horizontalPadding = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
private static var defaultStyles:Object = {
|
||||
icon:null,
|
||||
upIcon:"mute_upIcon",
|
||||
downIcon:"mute_downIcon",
|
||||
overIcon:"mute_overIcon",
|
||||
disabledIcon:null,
|
||||
selectedDisabledIcon:null,
|
||||
selectedUpIcon:"sound_upIcon",
|
||||
selectedDownIcon:"sound_downIcon",
|
||||
selectedOverIcon:"sound_overIcon",
|
||||
textFormat:null,
|
||||
disabledTextFormat:null,
|
||||
textPadding:5,
|
||||
embedFonts:false
|
||||
};
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
override public function set height(value:Number):void
|
||||
{
|
||||
super.height = _button.height = value;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
override public function set width(value:Number):void
|
||||
{
|
||||
super.width = _button.width = value;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Public Methods
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* Gets the styles for the component
|
||||
*
|
||||
* @return Object created from defaultStyle and the BaseButton styles.
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public static function getStyleDefinition():Object
|
||||
{
|
||||
//return mergeStyles(defaultStyles, BaseButton.getStyleDefinition());
|
||||
return defaultStyles;
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Protected Methods
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
override protected function addListeners():void
|
||||
{
|
||||
//add listeners to the _model
|
||||
_model.addEventListener(MediaEvent.VOLUME_CHANGE, toggleState);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
override protected function removeListeners():void
|
||||
{
|
||||
//remove listeners from the _model
|
||||
_model.removeEventListener(MediaEvent.VOLUME_CHANGE, toggleState);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
protected function dispatchToggleChange(event:ComponentEvent):void
|
||||
{
|
||||
//pass the selected property of _button to the _controller's setMute function
|
||||
_controller.setMute(_button.selected);
|
||||
setAccessibilityProperties();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
protected function toggleState(event:MediaEvent):void
|
||||
{
|
||||
//set the _selected property of _button based on the state of the media
|
||||
_button.selected = !event.target.mute;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* Get the accessibility properties depending on the button state
|
||||
*/
|
||||
protected function getCurrentAccessibilityProperties():AccessibilityProperties
|
||||
{
|
||||
var accProps= new AccessibilityProperties();
|
||||
accProps.name = _button.selected? "mute" :"unmute";
|
||||
accProps.description = _button.selected? "Click to mute Volume" :"Muted. Click to restore Volume";
|
||||
return accProps;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* Set the accessibility properties depending on the button state
|
||||
*/
|
||||
protected function setAccessibilityProperties():void
|
||||
{
|
||||
if(Accessibility.active)
|
||||
{
|
||||
_button.accessibilityProperties = getCurrentAccessibilityProperties();
|
||||
Accessibility.updateProperties();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
236
com/yahoo/astra/fl/controls/mediaPlayerClasses/PlayPauseToggleButton.as
Executable file
236
com/yahoo/astra/fl/controls/mediaPlayerClasses/PlayPauseToggleButton.as
Executable file
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
|
||||
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
|
||||
*/
|
||||
package com.yahoo.astra.fl.controls.mediaPlayerClasses
|
||||
{
|
||||
import com.yahoo.astra.fl.events.MediaEvent;
|
||||
|
||||
import fl.events.ComponentEvent;
|
||||
|
||||
import flash.accessibility.Accessibility;
|
||||
import flash.accessibility.AccessibilityProperties;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
|
||||
//--------------------------------------
|
||||
// Class Description
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* PlayPauseToggleButton extends MediaView and creates an IconButton to toggle
|
||||
* the playing state of a media clip.
|
||||
*
|
||||
* @see com.yahoo.astra.fl.controls.mediaPlayerClasses.MediaView
|
||||
* @see com.yahoo.astra.fl.controls.mediaPlayerClasses.IconButton
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public class PlayPauseToggleButton extends MediaView
|
||||
{
|
||||
|
||||
//--------------------------------------
|
||||
// Constructor
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param container display object container that the PlayPauseToggleButton will be added to
|
||||
* @param model media clip that the PlayPauseToggleButton will observe
|
||||
* @param controller media controller that will handle user input from the PlayPauseToggleButton
|
||||
*/
|
||||
public function PlayPauseToggleButton(container:DisplayObjectContainer, model:IMediaClip, controller:MediaController)
|
||||
{
|
||||
super(container, model, controller);
|
||||
_button = new IconButton();
|
||||
_button.width = width;
|
||||
_button.height = height;
|
||||
|
||||
_button.accessibilityProperties = getCurrentAccessibilityProperties();
|
||||
|
||||
addChild(_button);
|
||||
setChildStyles(_button, getStyleDefinition());
|
||||
_button.addEventListener(ComponentEvent.BUTTON_DOWN, dispatchToggleChange);
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Properties
|
||||
//--------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _button:IconButton;
|
||||
|
||||
/**
|
||||
* Gets or sets the vertical padding of the button
|
||||
*/
|
||||
public function get verticalPadding():Number
|
||||
{
|
||||
return _button.verticalPadding;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (setter)
|
||||
*/
|
||||
public function set verticalPadding(value:Number):void
|
||||
{
|
||||
_button.verticalPadding = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets or set the amount of horizontal space between the icon and the sides of the button
|
||||
*/
|
||||
public function get horizontalPadding():Number
|
||||
{
|
||||
return _button.horizontalPadding;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (setter)
|
||||
*/
|
||||
public function set horizontalPadding(value:Number):void
|
||||
{
|
||||
_button.horizontalPadding = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
private static var defaultStyles:Object = {
|
||||
icon:null,
|
||||
upIcon:"play_upIcon",
|
||||
downIcon:"play_downIcon",
|
||||
overIcon:"play_overIcon",
|
||||
disabledIcon:null,
|
||||
selectedDisabledIcon:null,
|
||||
selectedUpIcon:"pause_upIcon",
|
||||
selectedDownIcon:"pause_downIcon",
|
||||
selectedOverIcon:"pause_overIcon",
|
||||
textFormat:null,
|
||||
disabledTextFormat:null,
|
||||
textPadding:5,
|
||||
embedFonts:false
|
||||
};
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
override public function set height(value:Number):void
|
||||
{
|
||||
super.height = _button.height = value;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
override public function set width(value:Number):void
|
||||
{
|
||||
super.width = _button.width = value;
|
||||
invalidate();
|
||||
}
|
||||
//--------------------------------------
|
||||
// Public Methods
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* Gets the styles for the component
|
||||
* @return Object created from defaultStyle and the BaseButton styles.
|
||||
*/
|
||||
public static function getStyleDefinition():Object
|
||||
{
|
||||
//return mergeStyles(defaultStyles, BaseButton.getStyleDefinition());
|
||||
return defaultStyles;
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Protected Methods
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
override protected function addListeners():void
|
||||
{
|
||||
//add listeners to the _model
|
||||
_model.addEventListener(MediaEvent.MEDIA_PLAY_PAUSE, toggleState);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
override protected function removeListeners():void
|
||||
{
|
||||
//remove listeners from the _model
|
||||
_model.removeEventListener(MediaEvent.MEDIA_PLAY_PAUSE, toggleState);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
protected function dispatchToggleChange(event:ComponentEvent):void
|
||||
{
|
||||
//pass the selected value to the _controller's togglePlayPause function
|
||||
_controller.setPause(_button.selected);
|
||||
//TODO: Accessibility.active check and 2 sec timeout
|
||||
setAccessibilityProperties();
|
||||
|
||||
invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
protected function toggleState(event:MediaEvent):void
|
||||
{
|
||||
//sets the _selected property of _button based on the state of the media
|
||||
_button.selected = event.target.playing;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* Get the accessibility properties depending on the button state
|
||||
*/
|
||||
protected function getCurrentAccessibilityProperties():AccessibilityProperties
|
||||
{
|
||||
var accProps= new AccessibilityProperties();
|
||||
accProps.name = _button.selected? "Pause" :"Play";
|
||||
accProps.description = _button.selected? "Click to Pause" :"Click to Play";
|
||||
return accProps;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* Set the accessibility properties depending on the button state
|
||||
*/
|
||||
protected function setAccessibilityProperties():void
|
||||
{
|
||||
if(Accessibility.active)
|
||||
{
|
||||
_button.accessibilityProperties = getCurrentAccessibilityProperties();
|
||||
Accessibility.updateProperties();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
377
com/yahoo/astra/fl/controls/mediaPlayerClasses/VolumeSlider.as
Executable file
377
com/yahoo/astra/fl/controls/mediaPlayerClasses/VolumeSlider.as
Executable file
@@ -0,0 +1,377 @@
|
||||
/*
|
||||
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
|
||||
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
|
||||
*/
|
||||
package com.yahoo.astra.fl.controls.mediaPlayerClasses
|
||||
{
|
||||
import com.yahoo.astra.fl.events.MediaEvent;
|
||||
|
||||
import fl.controls.BaseButton;
|
||||
import fl.core.UIComponent;
|
||||
import fl.events.ComponentEvent;
|
||||
import fl.managers.IFocusManagerComponent;
|
||||
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import flash.display.Sprite;
|
||||
import flash.events.Event;
|
||||
import flash.events.KeyboardEvent;
|
||||
import flash.events.MouseEvent;
|
||||
import flash.ui.Keyboard;
|
||||
|
||||
//--------------------------------------
|
||||
// Class Description
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* VolumeSlider extends MediaView implements IMediaView and creates a slider to control
|
||||
* volume for a media clip.
|
||||
*
|
||||
* @see com.yahoo.astra.fl.controls.mediaPlayerClasses.MediaView
|
||||
* @see com.yahoo.astra.fl.controls.mediaPlayerClasses.IMediaView
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
* @author Dwight Bridges
|
||||
*/
|
||||
|
||||
public class VolumeSlider extends MediaView implements IMediaView, IFocusManagerComponent
|
||||
{
|
||||
|
||||
//--------------------------------------
|
||||
// Constructor
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param container display object container that the VolumeSlider will be added to
|
||||
* @param model media clip that the VolumeSlider will observe
|
||||
* @param controller media controller that will handle user input from the VolumeSlider
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public function VolumeSlider(container:DisplayObjectContainer = null, model:IMediaClip = null, controller:IMediaController = null)
|
||||
{
|
||||
super(container, model, controller);
|
||||
_background = getDisplayObjectInstance(getStyleValue("background_skin")) as Sprite;
|
||||
addChild(_background);
|
||||
|
||||
_indicator = getDisplayObjectInstance(getStyleValue("indicator_skin")) as Sprite;
|
||||
_indicator.addEventListener(MouseEvent.MOUSE_DOWN, indicatorMouseDownHandler);
|
||||
addChild(_indicator);
|
||||
|
||||
_clickStrip = getDisplayObjectInstance(getStyleValue("background_skin")) as Sprite;
|
||||
_clickStrip.addEventListener(MouseEvent.MOUSE_DOWN, indicatorMouseDownHandler);
|
||||
addChild(_clickStrip);
|
||||
|
||||
_slider = new BaseButton();
|
||||
setChildStyles(_slider, defaultKnobStyles);
|
||||
_slider.addEventListener(MouseEvent.MOUSE_DOWN, sliderMouseDownHandler);
|
||||
addChild(_slider);
|
||||
|
||||
_backgroundMask = getDisplayObjectInstance(getStyleValue("backgroundMaskSkin")) as Sprite;
|
||||
|
||||
if(_backgroundMask != null)
|
||||
{
|
||||
addChild(_backgroundMask);
|
||||
_background.cacheAsBitmap = _backgroundMask.cacheAsBitmap = true;
|
||||
_background.mask = _backgroundMask;
|
||||
}
|
||||
_indicatorMask = getDisplayObjectInstance(getStyleValue("indicatorMaskSkin")) as Sprite;
|
||||
if(_indicatorMask != null)
|
||||
{
|
||||
addChild(_indicatorMask);
|
||||
_indicator.cacheAsBitmap = _indicatorMask.cacheAsBitmap = true;
|
||||
_indicator.mask = _indicatorMask;
|
||||
}
|
||||
_knobMask = getDisplayObjectInstance(getStyleValue("knobMaskSkin")) as Sprite;
|
||||
if(_knobMask != null)
|
||||
{
|
||||
addChild(_knobMask);
|
||||
_slider.cacheAsBitmap = _knobMask.cacheAsBitmap = true;
|
||||
_slider.mask = _knobMask;
|
||||
}
|
||||
addEventListener(ComponentEvent.RESIZE, resizeEventHandler);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Properties
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _background:Sprite;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _slider:BaseButton;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _indicator:Sprite;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _clickStrip:Sprite;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _backgroundMask:Sprite;
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
protected var _indicatorMask:Sprite;
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
protected var _knobMask:Sprite;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* indicates the x coordinate of the _slider that user pressed
|
||||
*/
|
||||
protected var _mouseDownX:Number;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* indicates the amount of space to the right of the cursor on the _slider
|
||||
*/
|
||||
protected var _mouseDownRightPadding:Number;
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected var _range:Number;
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
private static var defaultStyles:Object = {
|
||||
background_skin:"volumeBackground_skin",
|
||||
indicator_skin:"volumeIndicator_skin",
|
||||
backgroundMaskSkin:"volumeBackground_mask",
|
||||
indicatorMaskSkin:"volumeIndicator_mask",
|
||||
knobMaskSkin:"volumeKnob_mask"
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
protected static var defaultKnobStyles:Object = {
|
||||
upSkin:"volumeKnob_upSkin",
|
||||
downSkin:"volumeKnob_downSkin",
|
||||
overSkin:"volumeKnob_overSkin",
|
||||
disabledSkin:"volumeKnob_upSkin",
|
||||
selectedDisabledSkin:"volumeKnob_upSkin",
|
||||
selectedUpSkin:"volumeKnob_upSkin",
|
||||
selectedDownSkin:"volumeKnob_downSkin",
|
||||
selectedOverSkin:"volumeKnob_overSkin"
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Class mixins
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Placeholder for mixin by VolumeSliderAccImpl.
|
||||
*/
|
||||
public static var createAccessibilityImplementation:Function;
|
||||
|
||||
//--------------------------------------
|
||||
// Public Methods
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* Gets the styles for the component
|
||||
*
|
||||
* @return defaultStyles
|
||||
*/
|
||||
public static function getStyleDefinition():Object
|
||||
{
|
||||
return mergeStyles(defaultStyles, UIComponent.getStyleDefinition());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the volume
|
||||
*
|
||||
* @param value Number A number between 0 and 1
|
||||
*/
|
||||
public function set volume(value:Number):void
|
||||
{
|
||||
_controller.setVolume(value);
|
||||
var changeEvent:Event = new Event(Event.CHANGE);
|
||||
dispatchEvent(changeEvent );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the volume
|
||||
*
|
||||
* @return The media clip's volume, from 0 to 1
|
||||
*/
|
||||
public function get volume():Number
|
||||
{
|
||||
return _controller.getVolume();
|
||||
}
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
override protected function addListeners():void
|
||||
{
|
||||
//attach listener to the MediaEvent.VOLUME_CHANGE
|
||||
_model.addEventListener(MediaEvent.VOLUME_CHANGE, volumeChangeHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
override protected function removeListeners():void
|
||||
{
|
||||
//remove listener
|
||||
_model.removeEventListener(MediaEvent.VOLUME_CHANGE, volumeChangeHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected function sliderMouseDownHandler(event:MouseEvent):void
|
||||
{
|
||||
_mouseDownX = _slider.mouseX;
|
||||
_mouseDownRightPadding = _slider.width - _mouseDownX;
|
||||
this.stage.addEventListener(MouseEvent.MOUSE_UP, sliderMouseUpHandler, false, 0, true);
|
||||
this.stage.addEventListener(MouseEvent.MOUSE_MOVE, sliderMouseMoveHandler, false, 0, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected function sliderMouseUpHandler(event:MouseEvent):void
|
||||
{
|
||||
this.stage.removeEventListener(MouseEvent.MOUSE_UP, sliderMouseUpHandler);
|
||||
this.stage.removeEventListener(MouseEvent.MOUSE_MOVE, sliderMouseMoveHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected function sliderMouseMoveHandler(event:MouseEvent):void
|
||||
{
|
||||
if(mouseX - _mouseDownX <= 0)
|
||||
{
|
||||
_slider.x = 0;
|
||||
_indicator.width = 0;
|
||||
}
|
||||
else if(mouseX - _mouseDownRightPadding >= _range)
|
||||
{
|
||||
_slider.x = _range;
|
||||
_indicator.width = width;
|
||||
}
|
||||
else
|
||||
{
|
||||
_slider.x = mouseX - _mouseDownX;
|
||||
_indicator.width = _slider.x + _slider.width/2;
|
||||
}
|
||||
event.updateAfterEvent();
|
||||
volume = Math.round((_slider.x/_range)*100)/100;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected function volumeChangeHandler(event:MediaEvent):void
|
||||
{
|
||||
_slider.x = event.volume * _range;
|
||||
_indicator.width = _slider.x + _slider.width/2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*/
|
||||
protected function indicatorMouseDownHandler(event:MouseEvent):void
|
||||
{
|
||||
_slider.x = Math.max(0, Math.min(_range, mouseX - (_slider.width/2)));
|
||||
volume = Math.round((_slider.x/_range)*100)/100;
|
||||
_indicator.width = _slider.x + _slider.width/2;
|
||||
_mouseDownX = _slider.mouseX;
|
||||
_mouseDownRightPadding = _slider.width - _mouseDownX;
|
||||
this.stage.addEventListener(MouseEvent.MOUSE_UP, sliderMouseUpHandler, false, 0, true);
|
||||
this.stage.addEventListener(MouseEvent.MOUSE_MOVE, sliderMouseMoveHandler, false, 0, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the ability to change volume using keyboard navigation.
|
||||
*
|
||||
*/
|
||||
override protected function keyDownHandler(event:KeyboardEvent):void
|
||||
{
|
||||
switch(event.keyCode)
|
||||
{
|
||||
case Keyboard.LEFT:
|
||||
case Keyboard.DOWN:
|
||||
volume = Math.max(0, _model.volume - .1);
|
||||
|
||||
break;
|
||||
|
||||
case Keyboard.RIGHT:
|
||||
case Keyboard.UP:
|
||||
volume = Math.min(1, _model.volume + .1);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @private (protected)
|
||||
*
|
||||
* Sizes and positions elements.
|
||||
*/
|
||||
protected function resizeEventHandler(event:ComponentEvent):void
|
||||
{
|
||||
_background.width = width;
|
||||
_background.height = height;
|
||||
_indicator.width = width;
|
||||
_indicator.height = height;
|
||||
_clickStrip.width = width;
|
||||
_clickStrip.height = height;
|
||||
_clickStrip.alpha = 0;
|
||||
_slider.width = width/20;
|
||||
_slider.height = height;
|
||||
if(_backgroundMask != null)
|
||||
{
|
||||
_backgroundMask.width = width;
|
||||
_backgroundMask.height = height;
|
||||
}
|
||||
if(_indicatorMask != null)
|
||||
{
|
||||
_indicatorMask.width = width;
|
||||
_indicatorMask.height = height;
|
||||
}
|
||||
if(_knobMask != null)
|
||||
{
|
||||
_knobMask.width = width;
|
||||
_knobMask.height = height;
|
||||
}
|
||||
_range = width - _slider.width;
|
||||
_slider.x = _model.volume * _range;
|
||||
_indicator.width = _slider.x + _slider.width/2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
override protected function initializeAccessibility():void
|
||||
{
|
||||
if (VolumeSlider.createAccessibilityImplementation != null)
|
||||
VolumeSlider.createAccessibilityImplementation(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user