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

Commit

Permalink
Add endOfStream function
Browse files Browse the repository at this point in the history
In order to distinguish between just running out of buffer and completing the stream when in data generation mode, it's necessary to signal back to the the HTTPVideoProvider. Media sources uses endOfStream to accomplish this so we're exposing that method on the SWF.
  • Loading branch information
dmlap committed Jan 27, 2014
1 parent 988981f commit c6ccbc7
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 23 deletions.
5 changes: 5 additions & 0 deletions src/VideoJS.as
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ package{
try{
ExternalInterface.addCallback("vjs_appendBuffer", onAppendBufferCalled);
ExternalInterface.addCallback("vjs_echo", onEchoCalled);
ExternalInterface.addCallback("vjs_endOfStream", onEndOfStreamCalled);
ExternalInterface.addCallback("vjs_getProperty", onGetPropertyCalled);
ExternalInterface.addCallback("vjs_setProperty", onSetPropertyCalled);
ExternalInterface.addCallback("vjs_autoplay", onAutoplayCalled);
Expand Down Expand Up @@ -183,6 +184,10 @@ package{
private function onEchoCalled(pResponse:* = null):*{
return pResponse;
}

private function onEndOfStreamCalled():*{
_app.model.endOfStream();
}

private function onGetPropertyCalled(pPropertyName:String = ""):*{

Expand Down
4 changes: 4 additions & 0 deletions src/com/videojs/VideoJSModel.as
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ package com.videojs{
public function appendBuffer(bytes:ByteArray):void {
_provider.appendBuffer(bytes);
}

public function endOfStream():void {
_provider.endOfStream();
}

public function get backgroundColor():Number{
return _backgroundColor;
Expand Down
6 changes: 5 additions & 1 deletion src/com/videojs/providers/HTTPAudioProvider.as
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ package com.videojs.providers{
public function appendBuffer(bytes:ByteArray):void{
throw "HTTPAudioProvider does not support appendBuffer";
}

public function endOfStream():void{
throw "HTTPAudioProvider does not support endOfStream";
}

public function get buffered():Number{
if(duration > 0){
Expand Down Expand Up @@ -441,4 +445,4 @@ package com.videojs.providers{
_model.broadcastEventExternally(ExternalEventName.ON_METADATA, _metadata);
}
}
}
}
45 changes: 25 additions & 20 deletions src/com/videojs/providers/HTTPVideoProvider.as
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ package com.videojs.providers{
* @see http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html#play()
*/
private var _startOffset:Number = 0;
/**
* If true, an empty NetStream buffer should be interpreted as the end of the video. This
* is probably the case because the video data is being fed to the NetStream dynamically
* through appendBuffer, not for traditional file download video.
*/
private var _ending:Boolean = false;
private var _videoReference:Video;

/**
Expand Down Expand Up @@ -163,6 +169,10 @@ package com.videojs.providers{
public function appendBuffer(bytes:ByteArray):void{
_ns.appendBytes(bytes);
}

public function endOfStream():void{
_ending = true;
}

public function get buffered():Number{
// _src.path == null when in data generation mode
Expand Down Expand Up @@ -518,33 +528,28 @@ package com.videojs.providers{
case "NetStream.Buffer.Empty":
// should not fire if ended/paused. issue #38
if(!_isPlaying){ return; }
_isBuffering = true;
_model.broadcastEventExternally(ExternalEventName.ON_BUFFER_EMPTY);

if(_src.path === null)
{
if(_model.time >= _model.duration-.5)
{
if(!_loop) {
_isPlaying = false;
_isPaused = true;
_hasEnded = true;
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_STREAM_CLOSE, {info:e.info}));
_model.broadcastEventExternally(ExternalEventName.ON_PAUSE);
_model.broadcastEventExternally(ExternalEventName.ON_PLAYBACK_COMPLETE);
}
else {
// reaching the end of the buffer after endOfStream has been called means we've
// hit the end of the video
if (_ending) {
_ending = false;
_isPlaying = false;
_isPaused = true;
_hasEnded = true;
_model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_STREAM_CLOSE, {info:e.info}));
_model.broadcastEventExternally(ExternalEventName.ON_PAUSE);
_model.broadcastEventExternally(ExternalEventName.ON_PLAYBACK_COMPLETE);

}
_throughputTimer.stop();
_throughputTimer.reset();
}
_startOffset = 0;
_pausedSeekValue = 0;
break;
}

_isBuffering = true;
_model.broadcastEventExternally(ExternalEventName.ON_BUFFER_EMPTY);
break;

case "NetStream.Play.Stop":

if(!_loop){
_isPlaying = false;
_isPaused = true;
Expand Down
9 changes: 8 additions & 1 deletion src/com/videojs/providers/IProvider.as
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ package com.videojs.providers{
* @param bytes the ByteArray of data to append.
*/
function appendBuffer(bytes:ByteArray):void;

/**
* Indicates that no further bytes will appended to the source
* buffer. After this method has been called, reaching the end
* of buffered input is equivalent to the end of the media.
*/
function endOfStream():void;

/**
* Should return an interger that reflects the closest parallel to
Expand Down Expand Up @@ -168,4 +175,4 @@ package com.videojs.providers{
function die():void;

}
}
}
6 changes: 5 additions & 1 deletion src/com/videojs/providers/RTMPVideoProvider.as
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ package com.videojs.providers{
public function appendBuffer(bytes:ByteArray):void{
throw "RTMPVideoProvider does not support appendBuffer";
}

public function endOfStream():void{
throw "RTMPVideoProvider does not support endOfStream";
}

public function get buffered():Number{
if(duration > 0){
Expand Down Expand Up @@ -631,4 +635,4 @@ package com.videojs.providers{
*/
public function streamInfo(pObj:Object):void {}
}
}
}

0 comments on commit c6ccbc7

Please sign in to comment.