From 6d0cc4dcdabae747792c004d431c653ca1e16ecd Mon Sep 17 00:00:00 2001 From: Alex Phillips Date: Mon, 18 Jul 2016 13:29:29 -0400 Subject: [PATCH] added support for onTextData event (#188) --- src/com/videojs/events/VideoPlaybackEvent.as | 17 ++- .../videojs/providers/HTTPVideoProvider.as | 5 + .../videojs/providers/RTMPVideoProvider.as | 141 +++++++++--------- src/com/videojs/structs/ExternalEventName.as | 12 +- 4 files changed, 94 insertions(+), 81 deletions(-) diff --git a/src/com/videojs/events/VideoPlaybackEvent.as b/src/com/videojs/events/VideoPlaybackEvent.as index f4143cb5..f2a7f66c 100644 --- a/src/com/videojs/events/VideoPlaybackEvent.as +++ b/src/com/videojs/events/VideoPlaybackEvent.as @@ -1,9 +1,9 @@ package com.videojs.events{ - + import flash.events.Event; - + public class VideoPlaybackEvent extends Event{ - + public static const ON_CUE_POINT:String = "VideoPlaybackEvent.ON_CUE_POINT"; public static const ON_META_DATA:String = "VideoPlaybackEvent.ON_META_DATA"; public static const ON_XMP_DATA:String = "VideoPlaybackEvent.ON_XMP_DATA"; @@ -22,18 +22,19 @@ package com.videojs.events{ public static const ON_ERROR:String = "VideoPlaybackEvent.ON_ERROR"; public static const ON_UPDATE:String = "VideoPlaybackEvent.ON_UPDATE"; public static const ON_VIDEO_DIMENSION_UPDATE:String = "VideoPlaybackEvent.ON_VIDEO_DIMENSION_UPDATE"; - + public static const ON_TEXT_DATA:String = "VideoPlaybackEvent.ON_TEXT_DATA"; + // a flexible container object for whatever data needs to be attached to any of these events private var _data:Object; - + public function VideoPlaybackEvent(pType:String, pData:Object = null){ super(pType, true, false); _data = pData; } - + public function get data():Object { return _data; } - + } -} \ No newline at end of file +} diff --git a/src/com/videojs/providers/HTTPVideoProvider.as b/src/com/videojs/providers/HTTPVideoProvider.as index 19114ee1..c9e96780 100644 --- a/src/com/videojs/providers/HTTPVideoProvider.as +++ b/src/com/videojs/providers/HTTPVideoProvider.as @@ -682,6 +682,11 @@ package com.videojs.providers{ _onmetadadataFired = true; } + public function onTextData(pTextData:Object):void { + _model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_TEXT_DATA, {textData:pTextData})); + _model.broadcastEventExternally(ExternalEventName.ON_TEXT_DATA, pTextData); + } + public function onCuePoint(pInfo:Object):void{ _model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_CUE_POINT, {cuepoint:pInfo})); } diff --git a/src/com/videojs/providers/RTMPVideoProvider.as b/src/com/videojs/providers/RTMPVideoProvider.as index 0d0ff405..10481c1a 100644 --- a/src/com/videojs/providers/RTMPVideoProvider.as +++ b/src/com/videojs/providers/RTMPVideoProvider.as @@ -1,11 +1,11 @@ package com.videojs.providers{ - + import com.videojs.VideoJSModel; import com.videojs.events.VideoPlaybackEvent; import com.videojs.structs.ExternalErrorEventName; import com.videojs.structs.ExternalEventName; import com.videojs.structs.PlaybackType; - + import flash.events.EventDispatcher; import flash.events.NetStatusEvent; import flash.events.TimerEvent; @@ -16,9 +16,9 @@ package com.videojs.providers{ import flash.utils.ByteArray; import flash.utils.Timer; import flash.utils.getTimer; - + public class RTMPVideoProvider extends EventDispatcher implements IProvider{ - + private var _nc:NetConnection; private var _ns:NetStream; private var _rtmpRetryTimer:Timer; @@ -33,7 +33,7 @@ package com.videojs.providers{ private var _pauseOnStart:Boolean = false; private var _pausePending:Boolean = false; private var _videoReference:Video; - + private var _src:Object; private var _metadata:Object; private var _hasDuration:Boolean = false; @@ -47,9 +47,9 @@ package com.videojs.providers{ private var _reportEnded:Boolean = false; private var _canPlayThrough:Boolean = false; private var _loop:Boolean = false; - + private var _model:VideoJSModel; - + public function RTMPVideoProvider(){ _model = VideoJSModel.getInstance(); _metadata = {}; @@ -62,11 +62,11 @@ package com.videojs.providers{ public function get loop():Boolean{ return _loop; } - + public function set loop(pLoop:Boolean):void{ _loop = pLoop; } - + public function get time():Number{ if(_ns != null){ return _ns.time; @@ -75,7 +75,7 @@ package com.videojs.providers{ return 0; } } - + public function get duration():Number{ if(_metadata != null && _metadata.duration != undefined){ return Number(_metadata.duration); @@ -84,7 +84,7 @@ package com.videojs.providers{ return 0; } } - + public function get readyState():int{ // if we have metadata and a known duration if(_metadata != null && _metadata.duration != undefined){ @@ -102,7 +102,7 @@ package com.videojs.providers{ } // otherwise, we can't be certain that seeking ahead will work else{ - return 2; + return 2; } } } @@ -116,7 +116,7 @@ package com.videojs.providers{ return 0; } } - + public function get networkState():int{ if(!_loadStarted){ return 0; @@ -167,41 +167,41 @@ package com.videojs.providers{ return 0; } } - + public function get bytesLoaded():int{ - + return 0; } - + public function get bytesTotal():int{ - + return 0; } - + public function get playing():Boolean{ return _isPlaying; } - + public function get paused():Boolean{ return _isPaused; } - + public function get ended():Boolean{ return _reportEnded; } - + public function get seeking():Boolean{ return _isSeeking; } - + public function get usesNetStream():Boolean{ return true; } - + public function get metadata():Object{ return _metadata; } - + public function set src(pSrc:Object):void{ _hasDuration = false; if(_isPlaying){ @@ -216,14 +216,14 @@ package com.videojs.providers{ init(pSrc, false); } } - + public function get srcAsString():String{ if(_src != null){ return _src.url; } return ""; } - + public function init(pSrc:Object, pAutoplay:Boolean):void{ _src = pSrc; _loadErrored = false; @@ -233,14 +233,14 @@ package com.videojs.providers{ play(); } } - + public function load():void{ _pauseOnStart = true; _isPlaying = false; _isPaused = true; initNetConnection(); } - + public function play():void{ // if this is a fresh playback request if(!_loadStarted){ @@ -269,7 +269,7 @@ package com.videojs.providers{ _model.broadcastEventExternally(ExternalEventName.ON_RESUME); } } - + public function pause():void{ if(_isPlaying && !_isPaused){ _ns.pause(); @@ -284,7 +284,7 @@ package com.videojs.providers{ _model.broadcastEventExternally(ExternalEventName.ON_PAUSE); } } - + public function resume():void{ if(_isPlaying && _isPaused){ _ns.resume(); @@ -292,7 +292,7 @@ package com.videojs.providers{ _model.broadcastEventExternally(ExternalEventName.ON_RESUME); } } - + public function seekBySeconds(pTime:Number):void{ if(_isPlaying){ _isSeeking = true; @@ -309,7 +309,7 @@ package com.videojs.providers{ _model.broadcastEventExternally(ExternalEventName.ON_RESUME); } } - + public function seekByPercent(pPercent:Number):void{ if(_isPlaying && _metadata.duration != undefined){ _isSeeking = true; @@ -323,11 +323,11 @@ package com.videojs.providers{ else{ _throughputTimer.stop(); _ns.seek(pPercent * _metadata.duration); - + } } } - + public function stop():void{ if(_isPlaying){ _ns.close(); @@ -339,11 +339,11 @@ package com.videojs.providers{ _throughputTimer.reset(); } } - + public function attachVideo(pVideo:Video):void{ _videoReference = pVideo; } - + public function die():void{ if(_videoReference) { @@ -390,14 +390,14 @@ package com.videojs.providers{ } } } - + private function initNetConnection():void{ if(_nc == null){ _nc = new NetConnection(); _nc.client = this; _nc.addEventListener(NetStatusEvent.NET_STATUS, onNetConnectionStatus); } - + // initiating an RTMP connection carries some overhead, so if we're already connected // to a server, and that server is the same as the one that hosts whatever we're trying to // play, we should skip straight to the playback @@ -413,7 +413,7 @@ package com.videojs.providers{ _nc.connect(_src.connectionURL); } } - + private function initNetStream():void{ if(_ns != null){ _ns.removeEventListener(NetStatusEvent.NET_STATUS, onNetStreamStatus); @@ -428,7 +428,7 @@ package com.videojs.providers{ _model.broadcastEventExternally(ExternalEventName.ON_LOAD_START); _model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_STREAM_READY, {ns:_ns})); } - + private function calculateThroughput():void{ // if it's finished loading, we can kill the calculations and assume it can play through if(_ns.bytesLoaded == _ns.bytesTotal){ @@ -454,11 +454,11 @@ package com.videojs.providers{ } } } - + private function onRTMPRetryTimerTick(e:TimerEvent):void{ initNetConnection(); } - + private function onNetConnectionStatus(e:NetStatusEvent):void{ switch(e.info.code){ case "NetConnection.Connect.Success": @@ -474,17 +474,17 @@ package com.videojs.providers{ } break; default: - + if(e.info.level == "error"){ _model.broadcastErrorEventExternally(e.info.code); _model.broadcastErrorEventExternally(e.info.description); } - + break; } _model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_NETCONNECTION_STATUS, {info:e.info})); } - + private function onNetStreamStatus(e:NetStatusEvent):void{ switch(e.info.code){ case "NetStream.Play.Reset": @@ -511,7 +511,7 @@ package com.videojs.providers{ } _loadStarted = true; break; - + case "NetStream.Buffer.Full": _isBuffering = false; _isPlaying = true; @@ -524,7 +524,7 @@ package com.videojs.providers{ _isPaused = true; } break; - + case "NetStream.Buffer.Empty": // playback is over if (_hasEnded) { @@ -546,13 +546,13 @@ package com.videojs.providers{ } break; - + case "NetStream.Play.Stop": _hasEnded = true; _throughputTimer.stop(); _throughputTimer.reset(); break; - + case "NetStream.Seek.Notify": _isPlaying = true; _isSeeking = false; @@ -563,29 +563,29 @@ package com.videojs.providers{ _loadStartTimestamp = getTimer(); _throughputTimer.reset(); _throughputTimer.start(); - + break; - + case "NetStream.Play.StreamNotFound": _loadErrored = true; _model.broadcastErrorEventExternally(ExternalErrorEventName.SRC_404); break; - + default: if(e.info.level == "error"){ _model.broadcastErrorEventExternally(e.info.code); _model.broadcastErrorEventExternally(e.info.description); } - + break; } _model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_NETSTREAM_STATUS, {info:e.info})); } - + private function onThroughputTimerTick(e:TimerEvent):void{ calculateThroughput(); } - + public function onMetaData(pMetaData:Object):void{ _metadata = pMetaData; if(pMetaData.duration != undefined){ @@ -603,51 +603,56 @@ package com.videojs.providers{ _model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_META_DATA, {metadata:_metadata})); _model.broadcastEventExternally(ExternalEventName.ON_METADATA, _metadata); } - + + public function onTextData(pTextData:Object):void { + _model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_TEXT_DATA, {textData:pTextData})); + _model.broadcastEventExternally(ExternalEventName.ON_TEXT_DATA, pTextData); + } + public function onCuePoint(pInfo:Object):void{ _model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_CUE_POINT, {cuepoint:pInfo})); } - + public function onXMPData(pInfo:Object):void{ _model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_XMP_DATA, {cuepoint:pInfo})); } - + public function onPlayStatus(e:Object):void{ } - + /** * Called from FMS during bandwidth detection */ public function onBWCheck(... pRest):Number { return 0; } - + /** * Called from FMS when bandwidth detection is completed. */ - public function onBWDone(... pRest):void { + public function onBWDone(... pRest):void { // no op for now but needed by NetConnection } - + /** * Called from FMS when subscribing to live streams. */ public function onFCSubscribe(pInfo:Object):void { - // no op for now but needed by NetConnection + // no op for now but needed by NetConnection } - + /** * Called from FMS when unsubscribing to live streams. */ public function onFCUnsubscribe(pInfo:Object):void { - // no op for now but needed by NetConnection - } - + // no op for now but needed by NetConnection + } + /** * Called from FMS for NetStreams. Incorrectly used for NetConnections as well. * This is here to prevent runtime errors. */ - public function streamInfo(pObj:Object):void {} + public function streamInfo(pObj:Object):void {} } } diff --git a/src/com/videojs/structs/ExternalEventName.as b/src/com/videojs/structs/ExternalEventName.as index abc82b56..f44417ce 100644 --- a/src/com/videojs/structs/ExternalEventName.as +++ b/src/com/videojs/structs/ExternalEventName.as @@ -1,7 +1,7 @@ package com.videojs.structs{ - + public class ExternalEventName{ - + public static const ON_SRC_CHANGE:String = "onsrcchange"; public static const ON_LOAD_START:String = "loadstart"; public static const ON_START:String = "playing"; @@ -18,10 +18,12 @@ package com.videojs.structs{ public static const ON_CAN_PLAY:String = "canplay"; public static const ON_CAN_PLAY_THROUGH:String = "canplaythrough"; public static const ON_VOLUME_CHANGE:String = "volumechange"; - + public static const ON_RTMP_CONNECT_SUCCESS:String = "rtmpconnected"; public static const ON_RTMP_RETRY:String = "rtmpretry"; public static const ON_STAGE_CLICK:String = "stageclick"; - + + public static const ON_TEXT_DATA:String = "textdata"; + } -} \ No newline at end of file +}