Skip to content

Commit

Permalink
Fix for play(true) and play(false)
Browse files Browse the repository at this point in the history
  • Loading branch information
donato committed Jul 23, 2015
1 parent 8dc88c9 commit 8b50a12
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/js/api/api-mutators.js
Expand Up @@ -15,7 +15,6 @@ define([
'fullscreen',
'volume',
'mute',
'state',
'item', // this was playlistindex
'stretching',
'playlist'
Expand Down Expand Up @@ -48,6 +47,7 @@ define([
'getVisualQuality',

'getConfig',
'getState',

'getSafeRegion',
'isBeforeComplete',
Expand Down
24 changes: 9 additions & 15 deletions src/js/api/api.js
Expand Up @@ -200,8 +200,11 @@ define([
};

this.play = function (state) {
if (state !== undefined) {
_controller.play(state);
if (state === true) {
_controller.play();
return _this;
} else if (state === false) {
_controller.pause();
return _this;
}

Expand All @@ -219,20 +222,11 @@ define([
};

this.pause = function (state) {
if (state === undefined) {
state = _this.getState();
switch (state) {
case states.PLAYING:
case states.BUFFERING:
_controller.pause();
break;
default:
_controller.play();
}
} else {
_controller.pause(state);
if (_.isBoolean(state)) {
return this.play(!state);
}
return _this;

return this.play();
};

this.createInstream = function () {
Expand Down
33 changes: 18 additions & 15 deletions src/js/controller/controller.js
Expand Up @@ -241,18 +241,25 @@ define([
loader.load(toLoad);
}

function _play(state) {
var status;
if (state === false) {
return _pause();
function _getState() {
var adState = _this._instreamAdapter && _this._instreamAdapter.getState();
if (_.isString(adState)) {
return adState;
}
return _model.get('state');
}

function _play() {
var status;

if(_model.get('state') === states.ERROR) {
return;
}

if (_this._instreamAdapter && _this._instreamAdapter.getState() !== false) {
return _api.playAd();
var adState = _this._instreamAdapter && _this._instreamAdapter.getState();
if (_.isString(adState)) {
// this will resume the ad. _api.playAd would load a new ad
return _api.pauseAd(false);
}

if (_model.get('state') === states.COMPLETE) {
Expand Down Expand Up @@ -320,17 +327,12 @@ define([
return true;
}

function _pause(state) {
function _pause() {
_actionOnAttach = null;

if (!utils.exists(state)) {
state = true;
} else if (!state) {
return _play();
}

if (_this._instreamAdapter && _this._instreamAdapter.getState() !== false) {
return _api.pauseAd();
var adState = _this._instreamAdapter && _this._instreamAdapter.getState();
if (_.isString(adState)) {
return _api.pauseAd(true);
}

switch (_model.get('state')) {
Expand Down Expand Up @@ -556,6 +558,7 @@ define([
this.getCaptionsList = _getCaptionsList;
this.getVisualQuality = _getVisualQuality;
this.getConfig = _getConfig;
this.getState = _getState;

// Model passthroughs
this.setVolume = _model.setVolume;
Expand Down

0 comments on commit 8b50a12

Please sign in to comment.