Investigate into Portfolio Multi Media Tab Gallery - 3

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:

playback-inheritance 

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);
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值