mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
Merge pull request #1044 from zilongshanren/fix-issue-3987
fix currentTime, add duration and isPlaying APIs
This commit is contained in:
@@ -147,21 +147,24 @@ var VideoPlayer = cc.Class({
|
||||
url: cc.RawAsset
|
||||
},
|
||||
|
||||
_time: 0,
|
||||
/**
|
||||
* !#en The current time when video start to play.
|
||||
* !#zh 从当前时间点开始播放视频
|
||||
* !#en The current playback time of the now playing item in seconds, you could also change the start playback time.
|
||||
* !#zh 指定视频从什么时间点开始播放,单位是秒,也可以用来获取当前视频播放的时间进度。
|
||||
* @property {Number} currentTime
|
||||
*/
|
||||
currentTime: {
|
||||
tooltip: 'i18n:COMPONENT.videoplayer.currentTime',
|
||||
type: cc.Float,
|
||||
set: function ( time ) {
|
||||
this._time = time;
|
||||
this._sgNode.seekTo(time);
|
||||
if(this._sgNode) {
|
||||
this._sgNode.seekTo(time);
|
||||
}
|
||||
},
|
||||
get: function () {
|
||||
return this._time;
|
||||
if(this._sgNode) {
|
||||
return this._sgNode.currentTime();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -210,7 +213,6 @@ var VideoPlayer = cc.Class({
|
||||
},
|
||||
|
||||
onLoad: function() {
|
||||
|
||||
if(CC_JSB) {
|
||||
if (cc.sys.os === cc.sys.OS_OSX || cc.sys.os === cc.sys.OS_WINDOWS) {
|
||||
this.enabled = false;
|
||||
@@ -318,6 +320,28 @@ var VideoPlayer = cc.Class({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Gets the duration of the video
|
||||
* !#zh 获取视频文件的播放总时长
|
||||
*/
|
||||
getDuration: function() {
|
||||
if(this._sgNode) {
|
||||
return this._sgNode.duration();
|
||||
}
|
||||
return -1;
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Determine whether video is playing or not.
|
||||
* !#zh 判断当前视频是否处于播放状态
|
||||
*/
|
||||
isPlaying: function() {
|
||||
if(this._sgNode) {
|
||||
return this._sgNode.isPlaying();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
cc.VideoPlayer = module.exports = VideoPlayer;
|
||||
|
||||
@@ -73,6 +73,14 @@ _ccsg.VideoPlayer = _ccsg.Node.extend(/** @lends _ccsg.VideoPlayer# */{
|
||||
return this._renderCmd.isPlaying();
|
||||
},
|
||||
|
||||
duration: function () {
|
||||
return this._renderCmd.duration();
|
||||
},
|
||||
|
||||
currentTime: function() {
|
||||
return this._renderCmd.currentTime();
|
||||
},
|
||||
|
||||
createDomElementIfNeeded: function () {
|
||||
if (!this._renderCmd._video) {
|
||||
this._renderCmd.createDom();
|
||||
@@ -501,6 +509,7 @@ _ccsg.VideoPlayer.EventType = {
|
||||
};
|
||||
|
||||
proto.isPlaying = function () {
|
||||
var video = this._video;
|
||||
if(_ccsg.VideoPlayer._polyfill.autoplayAfterOperation && this._playing){
|
||||
setTimeout(function(){
|
||||
video.play();
|
||||
@@ -509,4 +518,18 @@ _ccsg.VideoPlayer.EventType = {
|
||||
return this._playing;
|
||||
};
|
||||
|
||||
proto.duration = function () {
|
||||
var video = this._video;
|
||||
if(!video) return -1;
|
||||
|
||||
return video.duration;
|
||||
};
|
||||
|
||||
proto.currentTime = function () {
|
||||
var video = this._video;
|
||||
if(!video) return -1;
|
||||
|
||||
return video.currentTime;
|
||||
};
|
||||
|
||||
})(_ccsg.VideoPlayer._polyfill);
|
||||
|
||||
Reference in New Issue
Block a user