Skip to content

Commit

Permalink
Clear the buffer when switching audio streams.
Browse files Browse the repository at this point in the history
* Add an optional parameter to Player.selectAudioTrack to clear
  the buffer like selectVideoTrack.

Closes #119

Change-Id: I40c4c1969115826890fe9719a988315b51e5b28c
  • Loading branch information
Timothy Drews committed Jul 30, 2015
1 parent d4f6678 commit 39f908d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
16 changes: 10 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,14 @@ app.checkMpdStorageStatus_ = function() {
/**
* Called when a new video track is selected.
*
* @param {boolean=} opt_immediate
* @param {boolean=} opt_clearBuffer If true (and by default), removes the
* previous stream's content before switching to the new stream.
*/
app.onVideoChange = function(opt_immediate) {
app.onVideoChange = function(opt_clearBuffer) {
var id = document.getElementById('videoTracks').value;
document.getElementById('adaptationEnabled').checked = false;
app.onAdaptationChange();
app.player_.selectVideoTrack(id, opt_immediate);
app.player_.selectVideoTrack(id, opt_clearBuffer);
};


Expand Down Expand Up @@ -342,10 +343,13 @@ app.onAdaptationChange = function() {

/**
* Called when a new audio track is selected.
*
* @param {boolean=} opt_clearBuffer If true (and by default), removes the
* previous stream's content before switching to the new stream.
*/
app.onAudioChange = function() {
app.onAudioChange = function(opt_clearBuffer) {
var id = document.getElementById('audioTracks').value;
app.player_.selectAudioTrack(id);
app.player_.selectAudioTrack(id, opt_clearBuffer);
};


Expand All @@ -365,7 +369,7 @@ app.onTextChange = function() {
*/
app.cycleAudio = function() {
app.cycleTracks_('cycleAudio', 'audioTracks', 3, function() {
app.onAudioChange();
app.onAudioChange(false);
}, false);
};

Expand Down
11 changes: 7 additions & 4 deletions lib/player/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,8 @@ shaka.player.Player.prototype.getTextTracks = function() {
* you intend to switch to manual video track selection.
*
* @param {number} id The |id| field of the desired VideoTrack object.
* @param {boolean=} opt_clearBuffer If true, removes the previous stream's
* content before switching to the new stream.
* @param {boolean=} opt_clearBuffer If true (and by default), removes the
* previous stream's content before switching to the new stream.
*
* @return {boolean} True if the specified VideoTrack was found.
* @export
Expand All @@ -508,13 +508,16 @@ shaka.player.Player.prototype.selectVideoTrack = function(id, opt_clearBuffer) {
* Select an audio track by ID.
*
* @param {number} id The |id| field of the desired AudioTrack object.
* @param {boolean=} opt_clearBuffer If true (and by default), removes the
* previous stream's content before switching to the new stream.
*
* @return {boolean} True if the specified AudioTrack was found.
* @export
*/
shaka.player.Player.prototype.selectAudioTrack = function(id) {
shaka.player.Player.prototype.selectAudioTrack = function(id, opt_clearBuffer) {
if (!this.videoSource_) return false;
return this.videoSource_.selectAudioTrack(id, false);
var clearBuffer = (opt_clearBuffer == undefined) ? true : opt_clearBuffer;
return this.videoSource_.selectAudioTrack(id, clearBuffer);
};


Expand Down

0 comments on commit 39f908d

Please sign in to comment.