Skip to content

Commit

Permalink
fix(player): Set play request for Ads when clicking on media; fixed w…
Browse files Browse the repository at this point in the history
…orkflow to check if player can play media; removed setting controls when requesting Ads
  • Loading branch information
rafa8626 committed Oct 5, 2018
1 parent e1d31ba commit ff748bd
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 17 deletions.
20 changes: 17 additions & 3 deletions dist/openplayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5109,6 +5109,10 @@ var Play = function () {
var el = _this.player.activeElement();

if (el.paused || el.ended) {
if (_this.player.adsInstance) {
_this.player.adsInstance.playRequested = true;
}

el.play();
} else {
el.pause();
Expand Down Expand Up @@ -6229,7 +6233,11 @@ var Media = function () {
}

if (this.media && typeof this.media.destroy === 'function') {
this.media.destroy();
var sameMedia = sources.length === 1 && sources[0].src === this.media.media.src;

if (!sameMedia) {
this.media.destroy();
}
}

sources.some(function (media) {
Expand All @@ -6239,7 +6247,14 @@ var Media = function () {
_this3.media = new html5_1.default(_this3.element, media);
}

return _this3.canPlayType(media.type);
var canPlay = _this3.canPlayType(media.type);

if (!canPlay) {
_this3.media = new html5_1.default(_this3.element, media);
return _this3.canPlayType(media.type);
}

return canPlay;
});

try {
Expand Down Expand Up @@ -7357,7 +7372,6 @@ var Ads = function () {
this.adsRequest.setAdWillAutoPlay(this.autoplayAllowed);
this.adsRequest.setAdWillPlayMuted(this.autoplayRequiresMuted);
this.adsLoader.requestAds(this.adsRequest);
this.element.controls = !(constants_1.IS_IPHONE && general_1.isVideo(this.element));
}
}, {
key: "_contentLoadedAction",
Expand Down
2 changes: 1 addition & 1 deletion dist/openplayer.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/js/controls/play.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class Play implements PlayerComponent {
this.button.setAttribute('aria-pressed', 'true');
const el = this.player.activeElement();
if (el.paused || el.ended) {
if (this.player.adsInstance) {
this.player.adsInstance.playRequested = true;
}
el.play();
} else {
el.pause();
Expand Down
15 changes: 12 additions & 3 deletions src/js/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,12 @@ class Media {
throw new TypeError('Media not set');
}

// Remove previous media if any is detected
// Remove previous media if any is detected and it's different from current one
if (this.media && typeof this.media.destroy === 'function') {
this.media.destroy();
const sameMedia = sources.length === 1 && sources[0].src === this.media.media.src;
if (!sameMedia) {
this.media.destroy();
}
}

// Loop until first playable source is found
Expand All @@ -361,7 +364,13 @@ class Media {
this.media = new HTML5Media(this.element, media);
}

return this.canPlayType(media.type);
// If not valid, make one last attempt to check if it plays with native HTML5
const canPlay = this.canPlayType(media.type);
if (!canPlay) {
this.media = new HTML5Media(this.element, media);
return this.canPlayType(media.type);
}
return canPlay;
});

try {
Expand Down
2 changes: 0 additions & 2 deletions src/js/media/ads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -892,8 +892,6 @@ class Ads {
this.adsRequest.setAdWillAutoPlay(this.autoplayAllowed);
this.adsRequest.setAdWillPlayMuted(this.autoplayRequiresMuted);
this.adsLoader.requestAds(this.adsRequest);

this.element.controls = !(IS_IPHONE && isVideo(this.element));
}

/**
Expand Down
16 changes: 8 additions & 8 deletions src/js/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ class Player {
*/
public controls: Controls;

/**
* Instance of Ads object.
*
* @type Ads
* @memberof Player
*/
public adsInstance?: Ads;

/**
* Unique identified for the current player instance.
*
Expand All @@ -111,14 +119,6 @@ class Player {
*/
private ads?: string|string[];

/**
* Instance of Ads object.
*
* @type Ads
* @memberof Player
*/
private adsInstance?: Ads;

/**
* Flag to determine if player must be scaled and scrop to fit parent container
* (only for video elements)
Expand Down

0 comments on commit ff748bd

Please sign in to comment.