Skip to content
This repository has been archived by the owner on Dec 10, 2020. It is now read-only.

Commit

Permalink
Updated RTMP provider. fixes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
iamjem committed Jun 26, 2013
1 parent 0a05d66 commit 4726e82
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 33 deletions.
Binary file modified bin-release/VideoJS.swf
Binary file not shown.
26 changes: 19 additions & 7 deletions src/VideoJS.as
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package{

import com.videojs.VideoJSApp;
import com.videojs.events.VideoJSEvent;
import com.videojs.structs.ExternalEventName;
import com.videojs.structs.ExternalErrorEventName;

import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.external.ExternalInterface;
import flash.geom.Rectangle;
Expand Down Expand Up @@ -120,10 +122,10 @@ package{
_app.model.srcFromFlashvars = String(loaderInfo.parameters.src);
}
else{
if(loaderInfo.parameters.RTMPConnection != undefined && loaderInfo.parameters.RTMPConnection != ""){
_app.model.rtmpConnectionURL = loaderInfo.parameters.RTMPConnection;
if(loaderInfo.parameters.rtmpConnection != undefined && loaderInfo.parameters.rtmpConnection != ""){
_app.model.rtmpConnectionURL = loaderInfo.parameters.rtmpConnection;
}
if(loaderInfo.parameters.RTMPStream != undefined && loaderInfo.parameters.RTMPStream != ""){
if(loaderInfo.parameters.rtmpStream != undefined && loaderInfo.parameters.rtmpStream != ""){
_app.model.rtmpStream = loaderInfo.parameters.rtmpStream;
}
}
Expand All @@ -141,6 +143,7 @@ package{
}

private function onAddedToStage(e:Event):void{
stage.addEventListener(MouseEvent.CLICK, onStageClick);
stage.addEventListener(Event.RESIZE, onStageResize);
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
Expand Down Expand Up @@ -244,12 +247,17 @@ package{
case "videoHeight":
return _app.model.videoHeight;
break;
case "rtmpConnection":
return _app.model.rtmpConnectionURL;
break;
case "rtmpStream":
return _app.model.rtmpStream;
break;
}
return null;
}

private function onSetPropertyCalled(pPropertyName:String = "", pValue:* = null):void{

private function onSetPropertyCalled(pPropertyName:String = "", pValue:* = null):void{
switch(pPropertyName){
case "mode":
_app.model.mode = String(pValue);
Expand Down Expand Up @@ -288,10 +296,10 @@ package{
case "volume":
_app.model.volume = Number(pValue);
break;
case "RTMPConnection":
case "rtmpConnection":
_app.model.rtmpConnectionURL = String(pValue);
break;
case "RTMPStream":
case "rtmpStream":
_app.model.rtmpStream = String(pValue);
break;
default:
Expand Down Expand Up @@ -331,6 +339,10 @@ package{
private function onUncaughtError(e:Event):void{
e.preventDefault();
}

private function onStageClick(e:MouseEvent):void{
_app.model.broadcastEventExternally(ExternalEventName.ON_STAGE_CLICK);
}

}
}
14 changes: 12 additions & 2 deletions src/com/videojs/VideoJSModel.as
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,19 @@ package com.videojs{
public function set rtmpStream(pValue:String):void{
_src = "";
_rtmpStream = pValue;
_currentPlaybackType = PlaybackType.RTMP;
broadcastEventExternally(ExternalEventName.ON_SRC_CHANGE, _src);
initProvider();
if (_provider != null && _currentPlaybackType == PlaybackType.RTMP) {
var __src:Object = {
connectionURL: _rtmpConnectionURL,
streamURL: _rtmpStream
};
_provider.src = __src;
}
else {
_currentPlaybackType = PlaybackType.RTMP;
initProvider();
}

if(_autoplay){
play();
}
Expand Down
81 changes: 57 additions & 24 deletions src/com/videojs/providers/RTMPVideoProvider.as
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ package com.videojs.providers{

private var _src:Object;
private var _metadata:Object;
private var _hasDuration:Boolean = false;
private var _isPlaying:Boolean = false;
private var _isPaused:Boolean = true;
private var _isBuffering:Boolean = false;
private var _isSeeking:Boolean = false;
private var _isLive:Boolean = false;
private var _canSeekAhead:Boolean = false;
private var _hasEnded:Boolean = false;
private var _reportEnded:Boolean = false;
private var _canPlayThrough:Boolean = false;
private var _loop:Boolean = false;

Expand Down Expand Up @@ -169,8 +171,7 @@ package com.videojs.providers{
}

public function get ended():Boolean{

return false;
return _reportEnded;
}

public function get seeking():Boolean{
Expand All @@ -186,6 +187,7 @@ package com.videojs.providers{
}

public function set src(pSrc:Object):void{
_hasDuration = false;
if(_isPlaying){
_ns.close();
_loadErrored = false;
Expand Down Expand Up @@ -232,15 +234,24 @@ package com.videojs.providers{
_metadata = {};
initNetConnection();
}
// if the asset is already loading
else{
// if the asset is paused
else if(_isPaused && !_reportEnded){
_pausePending = false;
_ns.resume();
_isPaused = false;
_model.broadcastEventExternally(ExternalEventName.ON_RESUME);
_model.broadcastEventExternally(ExternalEventName.ON_START);
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_STREAM_START, {}));
}
// video playback ended, seek to beginning
else if(_hasEnded){
_ns.seek(0);
_isPlaying = true;
_isPaused = false;
_hasEnded = false;
_reportEnded = false;
_isBuffering = true;
_model.broadcastEventExternally(ExternalEventName.ON_RESUME);
}
}

public function pause():void{
Expand All @@ -252,14 +263,17 @@ package com.videojs.providers{
_pausePending = true;
}
}
else if(_hasEnded && !_isPaused) {
_isPaused = true;
_model.broadcastEventExternally(ExternalEventName.ON_PAUSE);
}
}

public function resume():void{
if(_isPlaying && _isPaused){
_ns.resume();
_isPaused = false;
_model.broadcastEventExternally(ExternalEventName.ON_RESUME);
_model.broadcastEventExternally(ExternalEventName.ON_START);
}
}

Expand All @@ -274,7 +288,9 @@ package com.videojs.providers{
_ns.seek(pTime);
_isPlaying = true;
_hasEnded = false;
_reportEnded = false;
_isBuffering = true;
_model.broadcastEventExternally(ExternalEventName.ON_RESUME);
}
}

Expand All @@ -301,6 +317,7 @@ package com.videojs.providers{
_ns.close();
_isPlaying = false;
_hasEnded = true;
_reportEnded = true;
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_STREAM_CLOSE, {}));
_throughputTimer.stop();
_throughputTimer.reset();
Expand Down Expand Up @@ -349,6 +366,7 @@ package com.videojs.providers{
_ns.bufferTime = 1;
_ns.play(_src.streamURL);
_videoReference.attachNetStream(_ns);
_model.broadcastEventExternally(ExternalEventName.ON_LOAD_START);
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_STREAM_READY, {ns:_ns}));
}

Expand Down Expand Up @@ -416,22 +434,23 @@ package com.videojs.providers{

break;
case "NetStream.Play.Start":
_metadata = null;
_canPlayThrough = false;
_hasEnded = false;
_reportEnded = false;
_isBuffering = true;
_currentThroughput = 0;
_loadStartTimestamp = getTimer();
_throughputTimer.reset();
_throughputTimer.start();
_model.broadcastEventExternally(ExternalEventName.ON_LOAD_START);
_model.broadcastEventExternally(ExternalEventName.ON_BUFFER_EMPTY);
if(_pauseOnStart && _loadStarted == false){
_ns.pause();
_isPaused = true;
}
else{
_model.broadcastEventExternally(ExternalEventName.ON_RESUME);
if (!_isPlaying) {
_model.broadcastEventExternally(ExternalEventName.ON_RESUME);
}
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_STREAM_START, {info:e.info}));
}
_loadStarted = true;
Expand All @@ -451,22 +470,29 @@ package com.videojs.providers{
break;

case "NetStream.Buffer.Empty":
_isBuffering = true;
_model.broadcastEventExternally(ExternalEventName.ON_BUFFER_EMPTY);
// playback is over
if (_hasEnded) {
if(!_loop){
_isPlaying = false;
_hasEnded = true;
_reportEnded = true;
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_STREAM_CLOSE, {info:e.info}));
_model.broadcastEventExternally(ExternalEventName.ON_PLAYBACK_COMPLETE);
}
else{
_ns.seek(0);
}
}
// other stream buffering
else {
_isBuffering = true;
_model.broadcastEventExternally(ExternalEventName.ON_BUFFER_EMPTY);
}

break;

case "NetStream.Play.Stop":

if(!_loop){
_isPlaying = false;
_hasEnded = true;
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_STREAM_CLOSE, {info:e.info}));
_model.broadcastEventExternally(ExternalEventName.ON_PLAYBACK_COMPLETE);
}
else{
_ns.seek(0);
}

_hasEnded = true;
_throughputTimer.stop();
_throughputTimer.reset();
break;
Expand All @@ -482,7 +508,7 @@ package com.videojs.providers{
_throughputTimer.reset();
_throughputTimer.start();

break;
break;

case "NetStream.Play.StreamNotFound":
_loadErrored = true;
Expand Down Expand Up @@ -510,7 +536,10 @@ package com.videojs.providers{
if(pMetaData.duration != undefined){
_isLive = false;
_canSeekAhead = true;
_model.broadcastEventExternally(ExternalEventName.ON_DURATION_CHANGE, _metadata.duration);
if (!_hasDuration) {
_hasDuration = true;
_model.broadcastEventExternally(ExternalEventName.ON_DURATION_CHANGE, _metadata.duration);
}
}
else{
_isLive = true;
Expand All @@ -531,5 +560,9 @@ package com.videojs.providers{
public function onPlayStatus(e:Object):void{

}

public function onBWDone():void{

}
}
}
1 change: 1 addition & 0 deletions src/com/videojs/structs/ExternalEventName.as
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package com.videojs.structs{

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";

}
}

0 comments on commit 4726e82

Please sign in to comment.