나는 video.prototype.getCurrentFrame()
메서드를 통해 재생중인 비디오에서 framecount를 반환해야하는 프로젝트에서 작업하고 있습니다. 내 스크립트는이 메서드에 의해 반환되는 숫자가 '정의되지 않은'것입니다 꽤 많이 exept exept 작동합니다. 내 문제는 내 변수의 범위와 뭔가를 할 수 있지만 자바 스크립트에 새로운 해요 그리고 난 내 자신의 작품을 만들 수없는 것 알아요 ...프로토 타입 변수 Javascript 업데이트
내 방법에 video.prototype.setUpPlayer
나는 그 날 framcount 'timeListener'
변수를 업데이 트 프레임 수를 계산할 수 있습니다; video.prototype.getCurrentFrame()
통해이 프레임 변수에 액세스하려고하면 업데이트 된 값에 도달하지 않습니다.
여기 내 코드는 지금까지 있습니다 :
var Video = function(aVideoId){
this.videoId = aVideoId;
this.frame;
this.videoContainer;
this.myPlayer;
this.timeListener;
this.progressListener;
};
Video.prototype.getCurrentFrame = function(){
return this.frame;
}
Video.prototype.setVideoContainer = function(){
videoContainer = $('<div>', {
id: this.videoId,
class: 'projekktor',
width: "100%",
height: "100%",
});
$('#innerContainer').html(videoContainer);
}
Video.prototype.setUpPlayer = function(){
videoId = this.videoId;
myPlayer = projekktor('#' + videoId, {
controls: "true",
volume: 0.5,
preload: false,
autoplay: true,
playlist: [{
0: {
src: '/' + videoId + '.mp4',
type: 'video/mp4'
},
1: {
src: '/' + videoId + '.mov',
type: 'video/mov'
},
2: {
src: '/' + videoId + '.ogv',
type: 'video/ogv'
}
}]
}, function() { // call back
myPlayer.addListener('time', timeListener);
myPlayer.addListener('progress', progressListener);
});
timeListener = function(duration) {
$('#currentTime').html(duration);
frame = Math.round(duration * 25);
$('#currentFrame').html(frame);
return this.frame = frame;
}
progressListener = function(value) {
$('#progress').html(Math.round(value))
$('#progress2').html(myPlayer.getLoadProgress());
}
}
감사합니다 사전에 도움을! 당신이 프로토 타입을 사용하여 현재 프레임을 검색 할 수
var video = new Video;
alert(video.getCurrentFrame());
유일한 방법은 또한 인스턴스를 요구하는 (apply()
을 사용하는 것입니다 :
어떻게'.getCurrentFrame()'함수를 호출할까요? 코드에'Video' 인스턴스를 표시하지 마십시오. – Esailija
코드에 한 가지 주석 : 함수에 사용 된 변수의 범위를 지정하는 것이 좋습니다. . 그것은 private ('var'를 추가하거나 프로토 타입 내에서 접근 가능하게하기 위해'this'를 추가)입니다. 그렇지 않으면 전역 범위에서 많은 "가비지"를 생성하게됩니다. 이 의견은 귀하의 질문과 관련이 없습니다. –