Fix video player inline play issue in x5 (#2761)

* Fix clip setting issue

* Cover more video player events

* Fix x5 inline play issue
This commit is contained in:
pandamicro
2018-05-29 21:43:03 +08:00
committed by GitHub
parent d9d1ab37c8
commit 5475d40da9
2 changed files with 29 additions and 17 deletions
+2 -4
View File
@@ -62,8 +62,8 @@ const VideoPlayerImpl = require('./video-player-impl');
* @property {Number} CLICKED
*/
/**
* !#en ready to play
* !#zh 视频准备好了,可以开始播放了
* !#en ready to play, this event is not guaranteed to be triggered on all platform or browser, please don't rely on it to play your video.<br/>
* !#zh 视频准备好了,这个事件并不保障会在所有平台或浏览器中被触发,它依赖于平台实现,请不要依赖于这个事件做视频播放的控制。
* @property {Number} READY_TO_PLAY
*/
const EventType = VideoPlayerImpl.EventType;
@@ -160,8 +160,6 @@ let VideoPlayer = cc.Class({
return this._clip;
},
set: function (value) {
if (typeof value !== 'string')
value = '';
this._clip = value;
this._updateVideoSource();
},
+27 -13
View File
@@ -62,9 +62,9 @@ let VideoPlayerImpl = cc.Class({
_bindEvent () {
let video = this._video, self = this;
//binding event
video.onloadedmetadata = function () {
video.addEventListener("loadedmetadata", function () {
self._dispatchEvent(VideoPlayerImpl.EventType.META_LOADED);
};
});
video.addEventListener("ended", function () {
if (self._video !== video) return;
self._playing = false;
@@ -113,9 +113,16 @@ let VideoPlayerImpl = cc.Class({
video.style.bottom = "0px";
video.style.left = "0px";
video.className = "cocosVideo";
video.setAttribute('preload', true);
video.setAttribute('preload', 'auto');
video.setAttribute('webkit-playsinline', '');
video.setAttribute('playsinline', '');
// Stupid tencent x5 adaptation
let orientation = cc.winSize.width > cc.winSize.height ? "landscape" : "portrait";
video.setAttribute("x5-playsinline", "");
video.setAttribute("x5-video-player-type", "h5");
video.setAttribute("x5-video-orientation", orientation);
this._video = video;
cc.game.container.appendChild(video);
},
@@ -138,7 +145,7 @@ let VideoPlayerImpl = cc.Class({
},
setURL (path) {
let source, video, extname;
let source, extname;
if (this._url === path) {
return;
@@ -154,17 +161,24 @@ let VideoPlayerImpl = cc.Class({
this._bindEvent();
video = this._video;
video.oncanplay = function () {
function onCanPlay () {
if (this._loaded)
return;
this._loaded = true;
// node.setContentSize(node._contentSize.width, node._contentSize.height);
video.currentTime = 0;
this._dispatchEvent(VideoPlayerImpl.EventType.READY_TO_PLAY);
this._updateVisibility();
}.bind(this);
let video = this._video;
if (video.readyState === 4) {
this._loaded = true;
// node.setContentSize(node._contentSize.width, node._contentSize.height);
video.currentTime = 0;
this._dispatchEvent(VideoPlayerImpl.EventType.READY_TO_PLAY);
this._updateVisibility();
}
}
let callback = onCanPlay.bind(this);
let video = this._video;
video.addEventListener('canplay', callback);
video.addEventListener('canplaythrough', callback);
video.addEventListener('suspend', callback);
video.style["visibility"] = "hidden";
this._loaded = false;