MP3Player

Kind of class:class
Inherits from:AbstractPlayer
Implements:
Author:Andrew Guldman
Classpath:mx.controls.streamingmedia.MP3Player
File last modified:Tuesday, 18 December 2007, 15:44:38
FLVPlayer contains the logic to play MP3 streaming media files.

Summary


Constructor
  • MP3Player (aMediaUrl:String, aSoundHolder:MovieClip)
    • Constructor.
Class properties
  • STOP : Number
    • A constant that indicates that the sound should stop playing once it loads
Instance properties
Instance properties inherited from AbstractPlayer
Instance methods
Instance methods inherited from AbstractPlayer

Constructor

MP3Player

function MP3Player (
aMediaUrl:String, aSoundHolder:MovieClip)

Constructor.

Class properties

STOP

static STOP:Number = -1
(read)

A constant that indicates that the sound should stop playing once it loads

Instance properties

_listeners

private _listeners:Array
(read)

_loaded

private _loaded:Boolean
(read)

Has the mp3 been loaded?

_mediaUrl

private _mediaUrl:String
(read)

_positionOnLoad

private _positionOnLoad:Number
(read)

Position in seconds where the sound should play when it loads.
STOP indicates that it should not play at all.

_recentPosition

private _recentPosition:Number
(read)

# of seconds when the playhead was paused

_sound

private _sound:Sound
(read)

_soundHolder

private _soundHolder:MovieClip
(read)

_volume

private _volume:Number
(read)

The current volume setting. Used to initialize the volume of new
mp3's that are played.

Instance methods

addListener

function addListener (
aListener:Object) : Void

Specified by:

broadcastEvent

function broadcastEvent (
status:String) : Void

The listeners must implement the "handlePlayer"
function which takes two parameters: the slider and
the current value of the slider.

bufferIsFull

function bufferIsFull (
) : Void

Specified by:

close

function close (
) : Void

Close the player.
Specified by:

getMediaBytesLoaded

function getMediaBytesLoaded (
) : Number

Returns:
  • The number of bytes of the media that has loaded.

getMediaBytesTotal

function getMediaBytesTotal (
) : Number

Returns:
  • The total number of bytes of the media.

getMediaUrl

function getMediaUrl (
) : String

Specified by:

getPlayheadTime

function getPlayheadTime (
) : Number

Returns:
  • The playhead position, measued in seconds since the start.

getTotalTime

function getTotalTime (
) : Number

If the mp3 media has not completely loaded, then the duration property
of the Sound object is not accurate. The duration property increases
roughly linearly as the media loads. When the media is completely loaded,
it is accurate.

Hence, we can roughly calculate the total time of an mp3 by scaling the
duration by the ratio of bytesTotal/bytesLoaded. In practice, this has
been 95+% accurate.
Returns:
  • The total time of the media in seconds. For mp3 files, this is a
    property of the Sound object. For video, it is be a property
    that is manually set by the author.
Specified by:

getVolume

function getVolume (
) : Number

Specified by:

init

private function init (
)

Initialize the mp3 player.

initializeVolume

function initializeVolume (
) : Void

Set the volume of a new sound to the default volume.

isSizeChange

function isSizeChange (
) : Boolean

Specified by:

isSizeSet

function isSizeSet (
) : Boolean

Specified by:

load

function load (
) : Void

Load the media without playing it.
Specified by:

logError

function logError (
error:String) : Void

Specified by:

mediaLoaded

function mediaLoaded (
) : Void

Called when the media is completely loaded.
Specified by:

pause

function pause (
) : Void

Stop playback of the media without moving the playhead.
Specified by:

play

function play (
startingPoint:Number) : Void

Play the media starting at the specified starting point. If the media
hasn't yet been loaded, load it.
Parameters:
startingPoint:
The number of seconds into the media to start at.
This is an optional parameter. If omitted, playing will occur
at the current playhead position.
Specified by:

playStarted

function playStarted (
) : Void

This is called by the MediaDisplay object when playback starts.

playStopped

function playStopped (
) : Void

Specified by:

removeAllListeners

function removeAllListeners (
) : Void

resizeVideo

function resizeVideo (
) : Void

Specified by:

setMediaUrl

function setMediaUrl (
aUrl:String) : Void

Specified by:

setPlayheadTime

function setPlayheadTime (
aPosition:Number) : Void

Parameters:
aPosition:
Time in seconds where the playhead position should be placed

setSeeking

function setSeeking (
isSeeking:Boolean) : Void

For MP3Player, this is a no-op
Specified by:

setVolume

function setVolume (
aVol:Number) : Void

Specified by:

stop

function stop (
) : Void

Stop playback of the media and reset the playhead to zero.

willStop

function willStop (
) : Boolean

This is scoped public so that the MediaDisplay class can access it.