PlaybackController, VideoPlaybackController and AudioPlaybackController:
The later two classes inherit PlaybackController. PlaybackController defines most logic of how it interacts with users, but it leave the methods that do control the playback progress abstract, letting its descendants to implement them. The rough relation is as:
The doxxx() methods are declared with 'protected' modifier, they all have their proxy callers, which arepublic, they can be regarded as interface for outer classes.This proxies method have define the logic that handles variables, and dispatches event to parent objects, and of course this logic are the same for both video and audio cases.
There are too many types of events that PlaybackController will dispatch, so that the author created an dedicated class PlaybackEvent. With comments:
/* Fired when media is loading. */
public static const LOAD_PROGRESS:String = "loadProgress";
/* Fired when media is buffering. */
public static const BUFFERING:String = "buffering";
/* Fired when media is buffering, everytime the buffer is updating. */
public static const BUFFER_PROGRESS:String = "bufferProgress";
/* Fired when media buffering is done. */
public static const BUFFER_FULL:String = "bufferFull";
/* Fired when media is ready for playback. */
public static const PLAYBACK_READY:String = "playbackReady";
/* Fired when current/total playback time is updated. */
public static const PLAYBACK_TIME_UPDATE:String = "playbackTimeUpdate";
/* Fired when playback starts. */
public static const PLAYBACK_START:String = "playbackStart";
/* Fired when playback stops/pauses. */
public static const PLAYBACK_STOP:String = "playbackStop";
/* Fired when playback completes. */
public static const PLAYBACK_COMPLETE:String = "playbackComplete";
/* Fired when an error occurs. */
public static const ERROR:String = "error";
/* Fired for mp3 files when ID3 is available. */
public static const MP3_ID3:String = "mp3ID3";
Except the last event is specific to Audio file:mp3, all the events are designed for both video and audio cases, in addition, these events are designed to be dispatched by apc orvpc of FileViewer, and be handled by FileViewer, which is container.
Now I will take video as example to discuss each of these events, so let's see how FileViwer handles these events:
/**
* Playback event handlers.
*/
private function pc_bufferingHandler(e:PlaybackEvent):void
{
pldrMc.show();
}
private function pc_bufferProgressHandler(e:PlaybackEvent):void
{
// handle buffer progress
}
private function pc_bufferFullHandler(e:PlaybackEvent):void
{
if (fileType != AUDIO_FILE || (fileType == AUDIO_FILE && ldrIsLoaded))
{
pldrMc.hide();
}
}
private function pc_loadProgressHandler(e:PlaybackEvent):void
{
controlsMc.progBarMc.loading = e.info.totalBytes > 0 ? e.info.loadedBytes / e.info.totalBytes : 0;
}
private function pc_playbackReadyHandler(e:PlaybackEvent):void
{
controlsMc.mouseChildren = true;
addUserInteraction();
if (fileType == VIDEO_FILE)
{
displayMc.mouseEnabled = true;
pldrMc.hide();
origW = vpc.originalVideoWidth;
origH = vpc.originalVideoHeight;
displayMc.addChild(videoInst);
hasDisplay = true;
stageLayout_resizeHandler(null, false);
doDisplayMcFadeIn();
if (!displayMc.doubleClickEnabled)
{
displayMc.doubleClickEnabled = true;
displayMc.addEventListener(MouseEvent.DOUBLE_CLICK, displayMc_doubleClickHandler, false, 0, true);
}
}
}
private function pc_playbackStartHandler(e:PlaybackEvent):void
{
controlsMc.playPauseMc.icon = PlayPauseButton.PAUSE_ICON;
}
private function pc_playbackStopHandler(e:PlaybackEvent):void
{
controlsMc.playPauseMc.icon = PlayPauseButton.PLAY_ICON;
}
private function pc_playbackTimeUpdateHandler(e:PlaybackEvent):void
{
if (!controlsMc.progBarMc.isDragged)
{
controlsMc.progBarMc.progress = e.info.totalTime > 0 ? e.info.currentTime / e.info.totalTime : 0;
}
controlsMc.progBarMc.currentTime = e.info.currentTimeString;
controlsMc.progBarMc.totalTime = e.info.totalTimeString;
}
private function pc_playbackCompleteHandler(e:PlaybackEvent):void
{
trace("[INFO]: Playback complete.");
}
private function pc_errorHandler(e:PlaybackEvent):void
{
trace("[ERROR]: Playback error: " + e.info.message);
}