Packagecv
Classpublic class TempoLite
InheritanceTempoLite Inheritance flash.events.EventDispatcher
ImplementsIMediaPlayer

Version:

3.0.1

Date:

3/06/2009

Updates At:

http://blog.coursevector.com/tempolite

TempoLite is based off of its sister project Tempo this is a parsed down version that does not handle a UI. TempoLite is best compared with players like video.Maru, in the sense that it’s just a component that is dragged on stage and handles all of the media playback. This allows for a UI as complicated as you want to make it while the actually playback is handled by TempoLite.

Coded By:

Gabriel Mariani, gabriel[at]coursevector.com
Copyright 2009, Course Vector (This work is subject to the terms in http://blog.coursevector.com/terms.)

Notes:



Example
This is the same code as in the TempoLiteDemo.fla

  import cv.TempoLite;
  import cv.media.SoundPlayer;
  import cv.media.NetStreamPlayer;
  import cv.media.RTMPPlayer;
  import cv.media.ImagePlayer;
  import flash.events.Event;
  import cv.events.LoadEvent;
  import cv.events.PlayProgressEvent;
  import cv.events.MetaDataEvent;
  import cv.formats.
  
  var tempo:TempoLite = new TempoLite(null, [ASX, ATOM, B4S, M3U, PLS, XSPF]);
  tempo.debug = true;
  
  var nsP:NetStreamPlayer = new NetStreamPlayer();
  nsP.video = vidScreen;
  tempo.addPlayer(nsP);
  nsP.debug = true;
  
  var sndP:SoundPlayer = new SoundPlayer();
  sndP.debug = true;
  tempo.addPlayer(sndP);
  
  var imgP:ImagePlayer = new ImagePlayer();
  this.addChildAt(imgP, 0);
  imgP.debug = true;
  tempo.addPlayer(imgP);
  
  var rtP:RTMPPlayer = new RTMPPlayer();
  rtP.streamHost = "rtmp://cp34534.edgefcs.net/ondemand";
  //rtP.video = vidScreen;
  //rtP.debug = true;
  //tempo.addPlayer(rtP);
  
  //tempo.load("images/2_1600.jpg");
  //tempo.load({url:"34548/PodcastIntro", extOverride:"flv"});
  //tempo.load("music/01 Sunrise Projector.mp3");
  //tempo.loadPlayList("playlists/xspf_example.xml");
  //tempo.loadPlayList("playlists/pls_example.pls");
  //tempo.loadPlayList("playlists/m3u_example.m3u");
  //tempo.loadPlayList("playlists/b4s_example.b4s");
  //tempo.loadPlayList("playlists/asx_example.xml");
  tempo.loadPlayList("playlists/atom_example.xml");
  



Public Properties
 PropertyDefined by
  autoStart : Boolean
Whether a video will play immediately when a playlist is loaded.
TempoLite
  autoStartIndex : int
If autoStart is true, the index of the item in the playlist to play first.
TempoLite
  currentIndex : uint
[read-only] Retrieve the current index in the playlist.
TempoLite
  currentItem : Object
[read-only] Retrieve the current item playing.
TempoLite
  currentPercent : uint
[read-only] Retrieve the current play progress as a percent.
TempoLite
  debug : Boolean = false
Enables/Disables debug traces
TempoLite
  length : uint
[read-only] Retrieves the number of items in the playlist.
TempoLite
  list : PlayList
[read-only] Retrieve the current playlist in PlayList format (enhanced array).
TempoLite
  loadCurrent : uint
[read-only] Retrieve the current bytes loaded of the current item.
TempoLite
  loadTotal : uint
[read-only] Retrieve the total bytes to load of the current item.
TempoLite
  metaData : Object
[read-only] Retrieve the metadata from the current item playing if available.
TempoLite
  paused : Boolean
[read-only] If TempoLite is currently paused.
TempoLite
  repeat : String
Sets whether repeat is enabled, or which type of repeat is enabled.
TempoLite
  shuffle : Boolean
Whether to shuffle the playlist or not.
TempoLite
  status : String
[read-only] Current status of media
TempoLite
  timeCurrent : Number
[read-only] Retrieve the current play time of the current item playing.
TempoLite
  timeLeft : Number
[read-only] Retrieve the play time remaining of the current item playing.
TempoLite
  timeTotal : Number
[read-only] Retrieve the total play time of the current item playing.
TempoLite
  volume : Number
A number from 0 to 1 determines volume.
TempoLite
Protected Properties
 PropertyDefined by
  _autoStart : Boolean = true
TempoLite
  _autoStartIndex : int = 0
TempoLite
  _cM : IMediaPlayer
TempoLite
  _ext : String
TempoLite
  _list : PlayList
TempoLite
  _listShuffled : PlayList
TempoLite
  _parsers : Array
TempoLite
  _pause : Boolean = false
TempoLite
  _players : Array
TempoLite
  _repeat : Boolean = false
TempoLite
  _repeatAll : Boolean = false
TempoLite
  _shuffle : Boolean = false
TempoLite
  strRepeat : String
TempoLite
  _volume : Number = 0.5
TempoLite
Public Methods
 MethodDefined by
  
TempoLite(players:Array = null, formats:Array = null)
Constructor.
TempoLite
  
addItem(item:*, index:int = -1):uint
Add an item to the playlist at the end, or at index specified.
TempoLite
  
addPlayer(player:IMediaPlayer):uint
Adds a player for use by TempoLite.
TempoLite
  
clearItems():void
Clears the current playlist.
TempoLite
  
isValid(ext:String, url:String):Boolean
TempoLite
  
load(item:*):void
Create a playlist of a single item and load the item.
TempoLite
  
loadPlayList(url:String):void
Loads a new playlist and clears any previous playlsit.
TempoLite
  
next():void
Plays the next item in the playlist.
TempoLite
  
pause(b:Boolean = true):void
Pauses the current playback.
TempoLite
  
play(pos:int = 0):void
Plays starting at the given position.
TempoLite
  
playItem(index:uint = 0):void
Plays the current item in the playlist, or at the specified index in the playlist.
TempoLite
  
previous():void
Plays the previous item in the playlist.
TempoLite
  
removeItem(index:int = -1):void
Remove an item from the playlist from the end, or at index specified.
TempoLite
  
Remove a player from TempoLite.
TempoLite
  
seek(time:*):void
Seek to a specific time (in seconds) in the current item playing.
TempoLite
  
seekPercent(percent:Number):void
Seek to a specific percent (0 - 1) in the current item playing.
TempoLite
  
stop():void
Stops the audio at the specified position.
TempoLite
  
stringToTime(text:String):int
[static] Converts a time in 00:00:000 format and converts it back into a number.
TempoLite
  
timeToString(n:int):String
[static] Converts milliseconds to a 00:00:000 format.
TempoLite
  
unload():void
Unloads the current item playing.
TempoLite
  
updateItem(index:uint, key:String, value:*):void
Updates a property of an Item in the playlist.
TempoLite
Protected Methods
 MethodDefined by
  
callPlayersMethod(methodName:String, methodValue:* = null):void
TempoLite
  
eventHandler(e:Event):void
TempoLite
  
getItemObject(item:*):Object
TempoLite
  
getType(data:String):PlayList
TempoLite
  
loadedHandler(e:Event):void
TempoLite
  
loadItem(o:Object):void
TempoLite
  
TempoLite
  
TempoLite
  
playlistHandler(e:Event):void
TempoLite
  
setPlayersProp(propName:String, propValue:*):void
TempoLite
  
TempoLite
  
trace2(... args):void
TempoLite
  
updateList():void
TempoLite
  
zero(n:int, isMS:Boolean = false):String
[static]
TempoLite
Events
 EventSummaryDefined by
   Dispatched from the PlayList when a change has occured TempoLite
   Dispatched everytime a cue point is encountered TempoLite
   Dispatched as a media file has completed loading TempoLite
   Dispatched as a media file is loaded TempoLite
   Dispatched as a media file begins loading TempoLite
   Dispatched as metadata is receieved from a player TempoLite
   Dispatched after Tempo has begun loading the next item, also at the end of an item playing TempoLite
   Dispatched as a media file finishes playing TempoLite
   Dispatched as a media file is playing TempoLite
   Dispatched once as a media file first begins to play TempoLite
   Dispatched after Tempo has begun loading the previous item TempoLite
   Dispatched from the PlayListManager when ever an item is removed, or updated, or the entire list is updated TempoLite
   Dispatched whenever the isPlaying, isReadyToPlay or isPause properties have changed.TempoLite
Public Constants
 ConstantDefined by
  NEW_PLAYLIST : String = "newPlaylist"
[static]
TempoLite
  NEXT : String = "next"
[static]
TempoLite
  PREVIOUS : String = "prev"
[static]
TempoLite
  REFRESH_PLAYLIST : String = "refreshPlaylist"
[static]
TempoLite
  REPEAT_ALL : String = "all"
[static]
TempoLite
  REPEAT_NONE : String = "none"
[static]
TempoLite
  REPEAT_TRACK : String = "track"
[static]
TempoLite
  VERSION : String = "3.0.2"
[static] The current version of TempoLite in use.
TempoLite
Property detail
_autoStartproperty
protected var _autoStart:Boolean = true
autoStartproperty 
autoStart:Boolean  [read-write]

Whether a video will play immediately when a playlist is loaded.

Implementation
    public function get autoStart():Boolean
    public function set autoStart(value:Boolean):void
_autoStartIndexproperty 
protected var _autoStartIndex:int = 0
autoStartIndexproperty 
autoStartIndex:int  [read-write]

If autoStart is true, the index of the item in the playlist to play first.

Implementation
    public function get autoStartIndex():int
    public function set autoStartIndex(value:int):void
_cMproperty 
protected var _cM:IMediaPlayer
currentIndexproperty 
currentIndex:uint  [read-only]

Retrieve the current index in the playlist.

Implementation
    public function get currentIndex():uint
currentItemproperty 
currentItem:Object  [read-only]

Retrieve the current item playing.

Implementation
    public function get currentItem():Object
currentPercentproperty 
currentPercent:uint  [read-only]

Retrieve the current play progress as a percent.

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

Enables/Disables debug traces

_extproperty 
protected var _ext:String
lengthproperty 
length:uint  [read-only]

Retrieves the number of items in the playlist.

Implementation
    public function get length():uint
_listproperty 
protected var _list:PlayList
listproperty 
list:PlayList  [read-only]

Retrieve the current playlist in PlayList format (enhanced array).

Implementation
    public function get list():PlayList
_listShuffledproperty 
protected var _listShuffled:PlayList
loadCurrentproperty 
loadCurrent:uint  [read-only]

Retrieve the current bytes loaded of the current item.

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

Retrieve the total bytes to load of the current item.

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

Retrieve the metadata from the current item playing if available.

Implementation
    public function get metaData():Object
_parsersproperty 
protected var _parsers:Array
_pauseproperty 
protected var _pause:Boolean = false
pausedproperty 
paused:Boolean  [read-only]

If TempoLite is currently paused.

Implementation
    public function get paused():Boolean
_playersproperty 
protected var _players:Array
_repeatproperty 
protected var _repeat:Boolean = false
repeatproperty 
repeat:String  [read-write]

Sets whether repeat is enabled, or which type of repeat is enabled. Accepted values are:

  • TempoLite.REPEAT_ALL
  • TempoLite.REPEAT_TRACK
  • TempoLite.REPEAT_NONE
  • The default value is TempoLite.REPEAT_NONE.

    Implementation
        public function get repeat():String
        public function set repeat(value:String):void
    _repeatAllproperty 
    protected var _repeatAll:Boolean = false
    _shuffleproperty 
    protected var _shuffle:Boolean = false
    shuffleproperty 
    shuffle:Boolean  [read-write]

    Whether to shuffle the playlist or not.

    The default value is false.

    Implementation
        public function get shuffle():Boolean
        public function set shuffle(value:Boolean):void
    statusproperty 
    status:String  [read-only]

    Current status of media

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

    Retrieve the current play time of the current item playing.

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

    Retrieve the play time remaining of the current item playing.

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

    Retrieve the total play time of the current item playing.

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

    A number from 0 to 1 determines volume.

    The default value is 0.5.

    Implementation
        public function get volume():Number
        public function set volume(value:Number):void
    Constructor detail
    TempoLite()constructor
    public function TempoLite(players:Array = null, formats:Array = null)

    Constructor. This creates a new TempoLite instance.

    Parameters
    players:Array (default = null) — An array of players to use with TempoLite
     
    formats:Array (default = null)
    Method detail
    addItem()method
    public function addItem(item:*, index:int = -1):uint

    Add an item to the playlist at the end, or at index specified.

    Parameters
    item:* — item to be added.
     
    index:int (default = -1) — where the item should be added in the playlist.

    Returns
    uint
    addPlayer()method 
    public function addPlayer(player:IMediaPlayer):uint

    Adds a player for use by TempoLite. Which can enable TempoLite to handle more types of media.

    Parameters
    player:IMediaPlayer — The player to add

    Returns
    uint
    callPlayersMethod()method 
    protected function callPlayersMethod(methodName:String, methodValue:* = null):voidParameters
    methodName:String
     
    methodValue:* (default = null)
    clearItems()method 
    public function clearItems():void

    Clears the current playlist.

    eventHandler()method 
    protected function eventHandler(e:Event):voidParameters
    e:Event
    getItemObject()method 
    protected function getItemObject(item:*):ObjectParameters
    item:*

    Returns
    Object
    getType()method 
    protected function getType(data:String):PlayListParameters
    data:String

    Returns
    PlayList
    isValid()method 
    public function isValid(ext:String, url:String):BooleanParameters
    ext:String
     
    url:String

    Returns
    Boolean
    load()method 
    public function load(item:*):void

    Create a playlist of a single item and load the item.

    Parameters
    item:* — The url or the item object to be played.
    loadedHandler()method 
    protected function loadedHandler(e:Event):voidParameters
    e:Event
    loadItem()method 
    protected function loadItem(o:Object):voidParameters
    o:Object
    loadPlayList()method 
    public function loadPlayList(url:String):void

    Loads a new playlist and clears any previous playlsit.

    Parameters
    url:String — The path to the playlist file.
    metaDataHandler()method 
    protected function metaDataHandler(e:MetaDataEvent):voidParameters
    e:MetaDataEvent
    next()method 
    public function next():void

    Plays the next item in the playlist.

    onNewPlaylist()method 
    protected function onNewPlaylist():void
    pause()method 
    public function pause(b:Boolean = true):void

    Pauses the current playback.

    Parameters
    b:Boolean (default = true) — Value to set pause to
    play()method 
    public function play(pos:int = 0):void

    Plays starting at the given position.

    Parameters
    pos:int (default = 0) — Position to play from
    playItem()method 
    public function playItem(index:uint = 0):void

    Plays the current item in the playlist, or at the specified index in the playlist.

    Parameters
    index:uint (default = 0) — The index of the item to be played
    playlistHandler()method 
    protected function playlistHandler(e:Event):voidParameters
    e:Event
    previous()method 
    public function previous():void

    Plays the previous item in the playlist.

    See also

    removeItem()method 
    public function removeItem(index:int = -1):void

    Remove an item from the playlist from the end, or at index specified.

    Parameters
    index:int (default = -1) — The index of the item to be removed

    See also

    removePlayer()method 
    public function removePlayer(player:IMediaPlayer):void

    Remove a player from TempoLite.

    Parameters
    player:IMediaPlayer — The player to be removed.
    seek()method 
    public function seek(time:*):void

    Seek to a specific time (in seconds) in the current item playing. Pass a string of the time to seek relative to the current play time.

    Parameters
    time:* — Specific time to seek to, in seconds
    seekPercent()method 
    public function seekPercent(percent:Number):void

    Seek to a specific percent (0 - 1) in the current item playing.

    Parameters
    percent:Number — Percentage to seek to
    setPlayersProp()method 
    protected function setPlayersProp(propName:String, propValue:*):voidParameters
    propName:String
     
    propValue:*
    shuffleList()method 
    protected function shuffleList(arr:PlayList):PlayListParameters
    arr:PlayList

    Returns
    PlayList
    stop()method 
    public function stop():void

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

    stringToTime()method 
    public static function stringToTime(text:String):int

    Converts a time in 00:00:000 format and converts it back into a number.

    Parameters
    text:String — The string to convert

    Returns
    int — The converted number
    timeToString()method 
    public static function timeToString(n:int):String

    Converts milliseconds to a 00:00:000 format.

    Parameters
    n:int — Milliseconds to convert

    Returns
    String — The converted string
    trace2()method 
    protected function trace2(... args):voidParameters
    ... args
    unload()method 
    public function unload():void

    Unloads the current item playing.

    updateItem()method 
    public function updateItem(index:uint, key:String, value:*):void

    Updates a property of an Item in the playlist. This is used in situations where the metadata has been loaded, and the correct duration or title is updated for the playlist display. Dispatches the TempoLite.REFRESH_PLAYLIST event.

    Parameters
    index:uint — The index of the item to be updated
     
    key:String — The property name (length, title, etc)
     
    value:* — The value to update the prop to.
    updateList()method 
    protected function updateList():void
    zero()method 
    protected static function zero(n:int, isMS:Boolean = false):StringParameters
    n:int
     
    isMS:Boolean (default = false)

    Returns
    String
    Event detail
    changeevent 
    Event object type: flash.events.Event

    Dispatched from the PlayList when a change has occured

    cuePointevent  
    Event object type: cv.events.MetaDataEvent

    Dispatched everytime a cue point is encountered

    loadCompleteevent  
    Event object type: cv.events.LoadEvent
    LoadEvent.type property = cv.events.LoadEvent.LOAD_COMPLETE

    Dispatched as a 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
    LoadEvent.type property = cv.events.LoadEvent.LOAD_START

    Dispatched as a media file begins loading

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

    This event has the following properties:

    Property Value
    bubbles false
    cancelablefalse; there is no default behavior to cancel.
    timeThe estimated duration of the media file.
    urlTThe url of the item being loaded.
    currentTargetThe object that is actively processing the event object with an event listener.
    indexThe zero-based index in the DataProvider that contains the renderer.
    itemA reference to the data that belongs to the renderer.
    mediaTypeThe type of media being loaded, either "audio" or "video".
    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.
    metadataevent  
    Event object type: cv.events.MetaDataEvent
    MetaDataEvent.type property = cv.events.MetaDataEvent.METADATA

    Dispatched as metadata is receieved from a player

    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.
    nextevent  
    Event object type: flash.events.Event

    Dispatched after Tempo has begun loading the next item, also at the end of an item playing

    playCompleteevent  
    Event object type: flash.events.Event

    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: flash.events.Event

    Dispatched once as a media file first begins to play

    previousevent  
    Event object type: flash.events.Event

    Dispatched after Tempo has begun loading the previous item

    refreshPlaylistevent  
    Event object type: flash.events.Event

    Dispatched from the PlayListManager when ever an item is removed, or updated, or the entire list is updated

    statusevent  
    Event object type: flash.events.Event

    Dispatched whenever the isPlaying, isReadyToPlay or isPause properties have changed.

    Constant detail
    NEW_PLAYLISTconstant
    public static const NEW_PLAYLIST:String = "newPlaylist"
    NEXTconstant 
    public static const NEXT:String = "next"
    PREVIOUSconstant 
    public static const PREVIOUS:String = "prev"
    REFRESH_PLAYLISTconstant 
    public static const REFRESH_PLAYLIST:String = "refreshPlaylist"
    REPEAT_ALLconstant 
    public static const REPEAT_ALL:String = "all"
    REPEAT_NONEconstant 
    public static const REPEAT_NONE:String = "none"
    REPEAT_TRACKconstant 
    public static const REPEAT_TRACK:String = "track"
    VERSIONconstant 
    public static const VERSION:String = "3.0.2"

    The current version of TempoLite in use.