Skip to content

Commit

Permalink
add a config param (autoStartLoad, default to true)
Browse files Browse the repository at this point in the history
if set to false, hls.startLoad() needs to be invoked to start level playlist/fragment loading after MANIFEST_PARSED event
  • Loading branch information
mangui committed Jul 22, 2015
1 parent 2b41a0a commit ab1f0ba
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
23 changes: 21 additions & 2 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ each error is categorized by :
hls.js provides means to 'try to' recover fatal network and media errors, through these 2 methods:
##### ```hls.recoverNetworkError()```
##### ```hls.startLoad()```
should be invoked to recover network error
should be invoked to recover network error.
##### ```hls.recoverMediaError()```
Expand Down Expand Up @@ -172,6 +172,7 @@ configuration parameters could be provided to hls.js upon instantiation of Hls O

var config = {
debug : false,
autoStartLoad : true,
maxBufferLength : 30,
maxBufferSize : 60*1000*1000,
enableWorker : true,
Expand All @@ -196,6 +197,12 @@ var hls = new Hls(config);
setting ```config.debug=true``` will turn on debug logs on JS console.
a logger object could also be provided for custom logging : ```config.debug=customLogger```
#### ```autoStartLoad```
(default true)
- if set to true, start level playlist and first fragments will be loaded automatically, after triggering of ```Hls.Events.MANIFEST_PARSED``` event
- if set to false, an explicit API call (```hls.startLoad()```) will be needed to start quality level/fragment loading.
#### ```maxBufferLength```
(default 30s)
Expand Down Expand Up @@ -304,6 +311,17 @@ get/set : capping/max level value that could be used by automatic level selectio
default value is -1 (no level capping)
## Network Loading Control API
by default, hls.js will automatically start loading quality level playlists, and fragments after Events.MANIFEST_PARSED event triggering.
however if ```config.autoStartLoad``` is set to ```false```, the following method needs to be called to manually start playlist and fragments loading:
#### ```hls.startLoad()```
start/restart playlist/fragment loading
## Analytics
playback session analytics could be retrieved through two means.
Expand Down Expand Up @@ -488,5 +506,6 @@ see sample object below:
sn: 35,
start : 30,
url: 'http://fragURL.com'
url2 : 'http://fragURLfailover.com' // if redundant/failover streams detected in Manifest
}
```
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ <h4> Playback Control </h4>
<button type="button" class="btn btn-sm btn-info" onclick="$('#video')[0].currentTime-=10">currentTime-=10</button>
<button type="button" class="btn btn-sm btn-info" onclick="$('#video')[0].currentTime=$('#seek_pos').val()">seek to </button>
<input type="text" id='seek_pos' size="8" onkeydown="if(window.event.keyCode=='13'){$('#video')[0].currentTime=$('#seek_pos').val();}"><br><br>
<button type="button" class="btn btn-xs btn-warning" onclick="hls.recoverNetworkError()">recover Network Error</button>
<button type="button" class="btn btn-xs btn-warning" onclick="hls.startLoad()">recover Network Error</button>
<button type="button" class="btn btn-xs btn-warning" onclick="hls.recoverMediaError()">recover Media Error</button><br>
</div>

Expand Down
28 changes: 16 additions & 12 deletions src/controller/buffer-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,20 @@
this.state = this.IDLE;
}

start() {
this.startInternal();
if(this.lastCurrentTime) {
logger.log(`resuming video @ ${this.lastCurrentTime}`);
this.startPosition = this.lastCurrentTime;
this.state = this.IDLE;
startLoad() {
if(this.levels && this.video) {
this.startInternal();
if(this.lastCurrentTime) {
logger.log(`resuming video @ ${this.lastCurrentTime}`);
this.startPosition = this.lastCurrentTime;
this.state = this.IDLE;
} else {
this.state = this.STARTING;
}
this.tick();
} else {
this.state = this.STARTING;
logger.log(`cannot start loading as either manifest not parsed or video not attached`);
}
this.tick();
}

startInternal() {
Expand Down Expand Up @@ -658,8 +662,8 @@
this.video.addEventListener('seeking',this.onvseeking);
this.video.addEventListener('seeked',this.onvseeked);
this.video.addEventListener('loadedmetadata',this.onvmetadata);
if(this.levels) {
this.start();
if(this.levels && this.config.autoStartLoad) {
this.startLoad();
}
}
onVideoSeeking() {
Expand Down Expand Up @@ -702,8 +706,8 @@
this.levels = data.levels;
this.startLevelLoaded = false;
this.startFragmentRequested = false;
if(this.video) {
this.start();
if(this.video && this.config.autoStartLoad) {
this.startLoad();
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/hls.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Hls {

constructor(config = {}) {
var configDefault = {
autoStartLoad : true,
debug : false,
maxBufferLength : 30,
maxBufferSize : 60*1000*1000,
Expand Down Expand Up @@ -122,9 +123,8 @@ class Hls {
observer.trigger(Event.MANIFEST_LOADING, { url: url });
}

recoverNetworkError() {
logger.log('try to recover network Error');
this.bufferController.start();
startLoad() {
this.bufferController.startLoad();
}

recoverMediaError() {
Expand Down

0 comments on commit ab1f0ba

Please sign in to comment.