Packagecv.media
Classpublic class SoundPlayer
InheritanceSoundPlayer Inheritance flash.events.EventDispatcher
ImplementsIMediaPlayer

Version:

3.0.3

Date:

4/02/2009

Updates At:

http://blog.coursevector.com/tempolite

The SoundPlayer class is a facade for controlling loading, and playing of MP3 files within Flash. It intelligently handles pausing, and loading.



Public Properties
 PropertyDefined by
  autoRewind : Boolean = false
Will automatically call stop (rewind) after playing complete.
SoundPlayer
  autoStart : Boolean
Whether media will play automatically once loaded.
SoundPlayer
  buffer : int
Gets or sets how long SoundPlayer should buffer the audio before playing, in seconds.
SoundPlayer
  currentPercent : uint
[read-only] Gets the current play progress in terms of percent
SoundPlayer
  debug : Boolean = false
Enables/Disables debug traces
SoundPlayer
  leftToLeft : Number
A value, from 0 (none) to 1 (all), specifying how much of the left input is played in the left speaker.
SoundPlayer
  leftToRight : Number
A value, from 0 (none) to 1 (all), specifying how much of the left input is played in the right speaker.
SoundPlayer
  loadCurrent : uint
[read-only] Gets the current load progress in terms of bytes
SoundPlayer
  loadTotal : uint
[read-only] Gets the total size to be loaded in terms of bytes
SoundPlayer
  metaData : Object
[read-only] Gets the metadata if available for the currently playing audio file -MetaData Flash Player 9 and later supports ID3 2.0 tags, specifically 2.3 and 2.4 -IDE 2.0 tag COMM Sound.id3.comment TABL Sound.id3.album TCON Sound.id3.genre TIT2 Sound.id3.songName TPE1 Sound.id3.artist TRCK Sound.id3.track TYER Sound.id3.year -ID3 Earlier TFLT File type TIME Time TIT1 Content group description TIT2 Title/song name/content description TIT3 Subtitle/description refinement TKEY Initial key TLAN Languages TLEN Length TMED Media type TOAL Original album/movie/show title TOFN Original filename TOLY Original lyricists/text writers TOPE Original artists/performers TORY Original release year TOWN File owner/licensee TPE1 Lead performers/soloists TPE2 Band/orchestra/accompaniment TPE3 Conductor/performer refinement TPE4 Interpreted, remixed, or otherwise modified by TPOS Part of a set TPUB Publisher TRCK Track number/position in set TRDA Recording dates TRSN Internet radio station name TRSO Internet radio station owner TSIZ Size TSRC ISRC (international standard recording code) TSSE Software/hardware and settings used for encoding TYER Year WXXX URL Link frame
SoundPlayer
  pan : Number
The left-to-right panning of the sound, ranging from -1 (full pan left) to 1 (full pan right).
SoundPlayer
  paused : Boolean
[read-only] Returns the pause status of the player.
SoundPlayer
  rightToLeft : Number
A value, from 0 (none) to 1 (all), specifying how much of the right input is played in the left speaker.
SoundPlayer
  rightToRight : Number
A value, from 0 (none) to 1 (all), specifying how much of the right input is played in the right speaker.
SoundPlayer
  status : String
[read-only] Returns the load status of the player.
SoundPlayer
  timeCurrent : Number
[read-only] Gets the elapsed play time in milliseconds
SoundPlayer
  timeLeft : Number
[read-only] Gets the remaining play time in milliseconds
SoundPlayer
  timeTotal : Number
[read-only] Gets the total play time in milliseconds
SoundPlayer
  volume : Number
Gets or sets the current volume, from 0 - 1
SoundPlayer
Protected Properties
 PropertyDefined by
  _autoStart : Boolean = true
SoundPlayer
  _buffer : int = 1
SoundPlayer
  _isReadyToPlay : Boolean = false
SoundPlayer
  _leftToLeft : Number = 1
SoundPlayer
  _leftToRight : Number = 0
SoundPlayer
  _loadCurrent : uint
SoundPlayer
  _loadTotal : uint
SoundPlayer
  _metaData : Object
SoundPlayer
  _pan : Number = 0
SoundPlayer
  _paused : Boolean = false
SoundPlayer
  pausePosition : int = 0
SoundPlayer
  playTimer : Timer
SoundPlayer
  _rightToLeft : Number = 0
SoundPlayer
  _rightToRight : Number = 1
SoundPlayer
  sc : SoundChannel
SoundPlayer
  sendOnce : Boolean = false
SoundPlayer
  skipOnce : Boolean = false
SoundPlayer
  snd : Sound
SoundPlayer
  _status : String = "unloaded"
SoundPlayer
  strURL : String
SoundPlayer
  _volume : Number = .5
SoundPlayer
Public Methods
 MethodDefined by
  
SoundPlayer
  
isValid(ext:String, url:String):Boolean
Validates if the given filetype is compatible to be played with SoundPlayer.
SoundPlayer
  
load(item:*):void
Loads a new file to be played.
SoundPlayer
  
loadAsset(sound:Sound):void
Loads a sound from the library to be played.
SoundPlayer
  
pause(b:Boolean = true):void
Controls the pause of the audio
SoundPlayer
  
play(pos:int = 0):void
Plays the audio, starting at the given position.
SoundPlayer
  
seek(time:*):void
Seeks to time given in the audio.
SoundPlayer
  
seekPercent(n:Number):void
Seeks to the given percent in the audio
SoundPlayer
  
stop():void
Stops the audio at the specified position.
SoundPlayer
  
unload():void
Stops the audio, closes the sound class, and resets the metadata.
SoundPlayer
Protected Methods
 MethodDefined by
  
errorHandler(e:ErrorEvent):void
SoundPlayer
  
SoundPlayer
  
progressHandler(e:ProgressEvent):void
SoundPlayer
  
setStatus(str:String):void
SoundPlayer
  
soundHandler(e:Event):void
SoundPlayer
  
trace2(... arguements):void
SoundPlayer
  
SoundPlayer
Events
 EventSummaryDefined by
   Dispatched when the media file has completed loading SoundPlayer
   Dispatched as a media file is loaded SoundPlayer
   Dispatched as a media file begins loading SoundPlayer
   Dispatched as ID3 metadata is receieved from an MP3 SoundPlayer
   Dispatched as a media file finishes playing SoundPlayer
   Dispatched as a media file is playing SoundPlayer
   Dispatched once as a media file first begins to play SoundPlayer
   Dispatched when status has been updated.SoundPlayer
Public Constants
 ConstantDefined by
  VERSION : String = "3.0.3"
[static] The current version
SoundPlayer
Property detail
autoRewindproperty
public var autoRewind:Boolean = false

Will automatically call stop (rewind) after playing complete. If disabled, this will pause the player instead.

_autoStartproperty 
protected var _autoStart:Boolean = true
autoStartproperty 
autoStart:Boolean  [read-write]

Whether media will play automatically once loaded.

The default value is true.

Implementation
    public function get autoStart():Boolean
    public function set autoStart(value:Boolean):void
_bufferproperty 
protected var _buffer:int = 1
bufferproperty 
buffer:int  [read-write]

Gets or sets how long SoundPlayer should buffer the audio before playing, in seconds.

Implementation
    public function get buffer():int
    public function set buffer(value:int):void
currentPercentproperty 
currentPercent:uint  [read-only]

Gets the current play progress in terms of percent

Implementation
    public function get currentPercent():uint
debugproperty 
public var debug:Boolean = false

Enables/Disables debug traces

_isReadyToPlayproperty 
protected var _isReadyToPlay:Boolean = false
_leftToLeftproperty 
protected var _leftToLeft:Number = 1
leftToLeftproperty 
leftToLeft:Number  [read-write]

A value, from 0 (none) to 1 (all), specifying how much of the left input is played in the left speaker.

Implementation
    public function get leftToLeft():Number
    public function set leftToLeft(value:Number):void
_leftToRightproperty 
protected var _leftToRight:Number = 0
leftToRightproperty 
leftToRight:Number  [read-write]

A value, from 0 (none) to 1 (all), specifying how much of the left input is played in the right speaker.

Implementation
    public function get leftToRight():Number
    public function set leftToRight(value:Number):void
_loadCurrentproperty 
protected var _loadCurrent:uint
loadCurrentproperty 
loadCurrent:uint  [read-only]

Gets the current load progress in terms of bytes

Implementation
    public function get loadCurrent():uint
_loadTotalproperty 
protected var _loadTotal:uint
loadTotalproperty 
loadTotal:uint  [read-only]

Gets the total size to be loaded in terms of bytes

Implementation
    public function get loadTotal():uint
_metaDataproperty 
protected var _metaData:Object
metaDataproperty 
metaData:Object  [read-only]

Gets the metadata if available for the currently playing audio file -MetaData Flash Player 9 and later supports ID3 2.0 tags, specifically 2.3 and 2.4 -IDE 2.0 tag COMM Sound.id3.comment TABL Sound.id3.album TCON Sound.id3.genre TIT2 Sound.id3.songName TPE1 Sound.id3.artist TRCK Sound.id3.track TYER Sound.id3.year -ID3 Earlier TFLT File type TIME Time TIT1 Content group description TIT2 Title/song name/content description TIT3 Subtitle/description refinement TKEY Initial key TLAN Languages TLEN Length TMED Media type TOAL Original album/movie/show title TOFN Original filename TOLY Original lyricists/text writers TOPE Original artists/performers TORY Original release year TOWN File owner/licensee TPE1 Lead performers/soloists TPE2 Band/orchestra/accompaniment TPE3 Conductor/performer refinement TPE4 Interpreted, remixed, or otherwise modified by TPOS Part of a set TPUB Publisher TRCK Track number/position in set TRDA Recording dates TRSN Internet radio station name TRSO Internet radio station owner TSIZ Size TSRC ISRC (international standard recording code) TSSE Software/hardware and settings used for encoding TYER Year WXXX URL Link frame

Implementation
    public function get metaData():Object
_panproperty 
protected var _pan:Number = 0
panproperty 
pan:Number  [read-write]

The left-to-right panning of the sound, ranging from -1 (full pan left) to 1 (full pan right). A value of 0 represents no panning (balanced center between right and left).

Implementation
    public function get pan():Number
    public function set pan(value:Number):void
_pausedproperty 
protected var _paused:Boolean = false
pausedproperty 
paused:Boolean  [read-only]

Returns the pause status of the player.

Implementation
    public function get paused():Boolean
pausePositionproperty 
protected var pausePosition:int = 0
playTimerproperty 
protected var playTimer:Timer
_rightToLeftproperty 
protected var _rightToLeft:Number = 0
rightToLeftproperty 
rightToLeft:Number  [read-write]

A value, from 0 (none) to 1 (all), specifying how much of the right input is played in the left speaker.

Implementation
    public function get rightToLeft():Number
    public function set rightToLeft(value:Number):void
_rightToRightproperty 
protected var _rightToRight:Number = 1
rightToRightproperty 
rightToRight:Number  [read-write]

A value, from 0 (none) to 1 (all), specifying how much of the right input is played in the right speaker.

Implementation
    public function get rightToRight():Number
    public function set rightToRight(value:Number):void
scproperty 
protected var sc:SoundChannel
sendOnceproperty 
protected var sendOnce:Boolean = false
skipOnceproperty 
protected var skipOnce:Boolean = false
sndproperty 
protected var snd:Sound
_statusproperty 
protected var _status:String = "unloaded"
statusproperty 
status:String  [read-only]

Returns the load status of the player.

Implementation
    public function get status():String
strURLproperty 
protected var strURL:String
timeCurrentproperty 
timeCurrent:Number  [read-only]

Gets the elapsed play time in milliseconds

Implementation
    public function get timeCurrent():Number
timeLeftproperty 
timeLeft:Number  [read-only]

Gets the remaining play time in milliseconds

Implementation
    public function get timeLeft():Number
timeTotalproperty 
timeTotal:Number  [read-only]

Gets the total play time in milliseconds

Implementation
    public function get timeTotal():Number
_volumeproperty 
protected var _volume:Number = .5
volumeproperty 
volume:Number  [read-write]

Gets or sets the current volume, from 0 - 1

Implementation
    public function get volume():Number
    public function set volume(value:Number):void
Constructor detail
SoundPlayer()constructor
public function SoundPlayer()
Method detail
errorHandler()method
protected function errorHandler(e:ErrorEvent):voidParameters
e:ErrorEvent
getEstimatedLength()method 
protected function getEstimatedLength():int

Returns
int
isValid()method 
public function isValid(ext:String, url:String):Boolean

Validates if the given filetype is compatible to be played with SoundPlayer. The acceptable file types are :

Parameters
ext:String — The file extension to be validated
 
url:String — The full file url if the extension is not enough

Returns
Boolean — Boolean of whether the extension was valid or not.
load()method 
public function load(item:*):void

Loads a new file to be played.

Parameters
item:* — The url of the file to be loaded

See also

cv.events.LoadEvent.LOAD_START
cv.events.PlayProgressEvent.STATUS
loadAsset()method 
public function loadAsset(sound:Sound):void

Loads a sound from the library to be played. This cannot be used in conjunction with TempoLite since the location is not a url.

Parameters
sound:Sound — The sound object from the library

See also

cv.events.PlayProgressEvent.STATUS
pause()method 
public function pause(b:Boolean = true):void

Controls the pause of the audio

Parameters
b:Boolean (default = true) — Whether to pause or not

See also

cv.events.PlayProgressEvent.STATUS
cv.events.PlayProgressEvent.PLAY_PROGRESS
play()method 
public function play(pos:int = 0):void

Plays the audio, starting at the given position.

Parameters
pos:int (default = 0) — Position to play from
progressHandler()method 
protected function progressHandler(e:ProgressEvent):voidParameters
e:ProgressEvent
seek()method 
public function seek(time:*):void

Seeks to time given in the audio.

Parameters
time:* — Seconds into playback to seek to

See also

cv.events.PlayProgressEvent.PLAY_PROGRESS
seekPercent()method 
public function seekPercent(n:Number):void

Seeks to the given percent in the audio

Parameters
n:Number — Percent to seek to

See also

cv.events.PlayProgressEvent.PLAY_PROGRESS
setStatus()method 
protected function setStatus(str:String):voidParameters
str:String
soundHandler()method 
protected function soundHandler(e:Event):voidParameters
e:Event
stop()method 
public function stop():void

Stops the audio at the specified position. Sets the position given as the pause position.

trace2()method 
protected function trace2(... arguements):voidParameters
... arguements
unload()method 
public function unload():void

Stops the audio, closes the sound class, and resets the metadata.

See also

cv.events.PlayProgressEvent.STATUS
updateSoundTransform()method 
protected function updateSoundTransform():void
Event detail
loadCompleteevent 
Event object type: cv.events.LoadEvent
LoadEvent.type property = cv.events.LoadEvent.LOAD_COMPLETE

Dispatched when the media file has completed loading

Defines the value of the type property of an loadComplete event object.

loadProgressevent  
Event object type: flash.events.ProgressEvent
ProgressEvent.type property = cv.events.LoadEvent.LOAD_PROGRESS

Dispatched as a media file is loaded

Defines the value of the type property of an loadProgress event object.

loadStartevent  
Event object type: cv.events.LoadEvent

Dispatched as a media file begins loading

metadataevent  
Event object type: cv.events.MetaDataEvent
MetaDataEvent.type property = cv.events.MetaDataEvent.METADATA

Dispatched as ID3 metadata is receieved from an MP3

Defines the value of the type property of an audioMetadata event object.

This event has the following properties:

PropertyValue
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
dataThe metadata object.
currentTargetThe object that is actively processing the event object with an event listener.
targetThe object that dispatched the event. The target is not always the object listening for the event. Use the currentTarget property to access the object that is listening for the event.
playCompleteevent  
Event object type: cv.events.PlayProgressEvent

Dispatched as a media file finishes playing

playProgressevent  
Event object type: cv.events.PlayProgressEvent
PlayProgressEvent.type property = cv.events.PlayProgressEvent.PLAY_PROGRESS

Dispatched as a media file is playing

Defines the value of the type property of an playProgress event object.

This event has the following properties:

PropertyValue
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
percentThe percentage of progress for the media playing.
elapsedThe elapsed time of the media playing.
remainThe remaining time of the media playing.
totalThe total time of the media playing.
currentTargetThe object that is actively processing the event object with an event listener.
targetThe object that dispatched the event. The target is not always the object listening for the event. Use the currentTarget property to access the object that is listening for the event.
playStartevent  
Event object type: cv.events.PlayProgressEvent

Dispatched once as a media file first begins to play

statusevent  
Event object type: cv.events.PlayProgressEvent

Dispatched when status has been updated.

Constant detail
VERSIONconstant
public static const VERSION:String = "3.0.3"

The current version