我正在寫我自己的視頻播放器根據教程here未捕獲的異常:在初始化之前無法調用滑塊上的方法;試圖調用方法'價值'
當我加載頁面,我得到標題錯誤。
這裏是與滑塊交易代碼:
//create html structure
//main wrapper
var $video_wrap = $('<div></div>').addClass('logan-video-player').addClass(options.theme).addClass(options.childtheme);
//controls wraper
var $video_controls = $('<div class="logan-video-controls"><a class="logan-video-play" title="Play/Pause"></a><div class="logan-video-seek"></div><div class="logan-video-timer">00:00</div><div class="logan-volume-box"><div class="logan-volume-slider"></div><a class="logan-volume-button" title="Mute/Unmute"></a></div></div>');
$lVideo.wrap($video_wrap);
$lVideo.after($video_controls);
//get new elements
var $logan_video_seek = $('.logan-video-seek', $video_container);
var seeksliding;
var createSeek = function() {
if($lVideo.attr('readyState')) {
var video_duration = $lVideo.attr('duration');
$logan_video_seek.slider({
value: 0,
step: 0.01,
orientation: "horizontal",
range: "min",
max: video_duration,
animate: true,
slide: function(){
seeksliding = true;
},
stop:function(e,ui){
seeksliding = false;
$lVideo.attr("currentTime",ui.value);
}
});
$video_controls.show();
} else {
setTimeout(createSeek, 150);
}
};
createSeek();
var gTimeFormat=function(seconds){
var m=Math.floor(seconds/60)<10?"0"+Math.floor(seconds/60):Math.floor(seconds/60);
var s=Math.floor(seconds-(m*60))<10?"0"+Math.floor(seconds-(m*60)):Math.floor(seconds-(m*60));
return m+":"+s;
};
var seekUpdate = function() {
var currenttime = $lVideo.attr('currentTime');
if(!seeksliding) $logan_video_seek.slider('value', currenttime);
$logan_video_timer.text(gTimeFormat(currenttime));
};
$lVideo.bind('timeupdate', seekUpdate);
我沒有太大的一個jQuery的buff,這是我第一次工作的插件,所以我不知道該怎麼辦對這個。無法在Google上找到太多內容。
感謝您的時間
編輯
我已經通過滑塊插件的JQuery的UI API規範,發現我可能設置滑塊值不正確:
$logan_video_seek.slider('value', currenttime) // see seekUpdate() function above
我已將其更改爲如下所示:
$logan_video_seek.slider('option', 'value', currenttime);
不幸的是我得到了同樣的錯誤:
uncaught exception: cannot call methods prior to initialization: attempted to call method 'option'
我找不到滑塊api文檔中的任何內容來初始化滑塊。我確信這會在上面的createSeek
函數中完成。
$ lVideo聲明在哪裏?並從該代碼執行的地方? –
@AndrewD。它在代碼中早得多。我通過在最後一次刪除'(jQuery)'來解決這個問題;在插件中。不知道這是什麼或爲什麼它打破了代碼,但現在控件顯示(視頻也很好地播放)。現在,我收到一個錯誤,說'對象[對象對象]沒有方法''VideoVideo'' – Ortund
當你不斷髮現錯誤,你可以粘貼完整的代碼像[jsfiddle](http:// http:// jsfiddle .net /)的完整性,但[codereview](http://codereview.stackexchange.com/)將更適合於他們。 –