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

Commit

Permalink
Merge pull request #131 from videojs/hotfix/null-netstream
Browse files Browse the repository at this point in the history
Fix for null netstream in HTTPVideoProvider.calculateThroughput.
  • Loading branch information
dmlap committed Nov 18, 2014
2 parents 4c0f345 + 90a351f commit 8c03e65
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
Binary file modified dist/video-js.swf
Binary file not shown.
49 changes: 26 additions & 23 deletions src/com/videojs/providers/HTTPVideoProvider.as
Original file line number Diff line number Diff line change
Expand Up @@ -455,29 +455,32 @@ package com.videojs.providers{
}

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){
_canPlayThrough = true;
_loadCompleted = true;
_throughputTimer.stop();
_throughputTimer.reset();
_model.broadcastEventExternally(ExternalEventName.ON_CAN_PLAY_THROUGH);
}
// if it's still loading, but we know its duration, we can check to see if the current transfer rate
// will sustain uninterrupted playback - this requires the duration to be known, which is currently
// only accessible via metadata, which isn't parsed until the Flash Player encounters the metadata atom
// in the file itself, which means that this logic will only work if the asset is playing - preload
// won't ever cause this logic to run :(
else if(_ns.bytesTotal > 0 && _metadata != null && _metadata.duration != undefined){
_currentThroughput = _ns.bytesLoaded / ((getTimer() - _loadStartTimestamp) / 1000);
var __estimatedTimeToLoad:Number = (_ns.bytesTotal - _ns.bytesLoaded) * _currentThroughput;
if(__estimatedTimeToLoad <= _metadata.duration){
_throughputTimer.stop();
_throughputTimer.reset();
_canPlayThrough = true;
_model.broadcastEventExternally(ExternalEventName.ON_CAN_PLAY_THROUGH);
}
}
// If there is no NetStream, the rest of the calculation is moot.
if(_ns){
// if it's finished loading, we can kill the calculations and assume it can play through
if(_ns.bytesLoaded == _ns.bytesTotal){
_canPlayThrough = true;
_loadCompleted = true;
_throughputTimer.stop();
_throughputTimer.reset();
_model.broadcastEventExternally(ExternalEventName.ON_CAN_PLAY_THROUGH);
}
// if it's still loading, but we know its duration, we can check to see if the current transfer rate
// will sustain uninterrupted playback - this requires the duration to be known, which is currently
// only accessible via metadata, which isn't parsed until the Flash Player encounters the metadata atom
// in the file itself, which means that this logic will only work if the asset is playing - preload
// won't ever cause this logic to run :(
else if(_ns.bytesTotal > 0 && _metadata != null && _metadata.duration != undefined){
_currentThroughput = _ns.bytesLoaded / ((getTimer() - _loadStartTimestamp) / 1000);
var __estimatedTimeToLoad:Number = (_ns.bytesTotal - _ns.bytesLoaded) * _currentThroughput;
if(__estimatedTimeToLoad <= _metadata.duration){
_throughputTimer.stop();
_throughputTimer.reset();
_canPlayThrough = true;
_model.broadcastEventExternally(ExternalEventName.ON_CAN_PLAY_THROUGH);
}
}
}
}

private function onNetConnectionStatus(e:NetStatusEvent):void{
Expand Down

0 comments on commit 8c03e65

Please sign in to comment.