首先,我应该说我对JavaScript不是很有经验,我希望在将sessionStorage值传递给设置时提供一些帮助。
$(document).ready(function(){
window.userSettings = null;
$("#jquery_jplayer_1").jPlayer({
ready: function () {
$(this).jPlayer("setMedia", {
title: "TestRadio",
mp3: "http:/streamlink"
});
},
swfPath: "jplayer/dist/jplayer",
supplied: "mp3",
wmode: "window",
volume: "75",
useStateClassSkin: true,
loop: true,
autoBlur: true,
smoothPlayBar: true,
keyEnabled: true,
remainingDuration: false,
toggleDuration: false
});
});
function storeUserjPlayerSettings(){
var settings = new Object();
settings.volume = $("#jquery_jplayer_1").data().jPlayer.status.volume;
settings.paused = $("#jquery_jplayer_1").data().jPlayer.status.paused;
settings.src = $("#jquery_jplayer_1").data().jPlayer.status.src;
sessionStorage.setItem('userjPlayerSettings', JSON.stringify(settings));
window.userSettings = JSON.parse(sessionStorage.getItem('settings'));
}
我想要做的是将settings.volume web存储值传递给volume参数
$("#jquery_jplayer_1").jPlayer({
ready: function () {
$(this).jPlayer("setMedia", {
title: "TestRadio",
mp3: "http:/streamlink"
});
},
swfPath: "jplayer/dist/jplayer",
supplied: "mp3",
wmode: "window",
**volume**: "75",
useStateClassSkin: true,
loop: true,
autoBlur: true,
smoothPlayBar: true,
keyEnabled: true,
remainingDuration: false,
toggleDuration: false
});
});
答案 0 :(得分:2)
您之前正在保存卷,因此您只需在需要时以相反的方式访问它。
例如,将volume: 75
初始化更改为对从您保存的设置中获取音量的函数的调用:volume: volumeSetting()
。
以下是您可以自己编写该函数的示例:
function volumeSetting() {
var settings = sessionStorage.getItem("userjPlayerSettings");
if (settings != null) {
settings = JSON.parse(settings);
if (typeof settings.volume == 'number')
return settings.volume;
}
return 75;
}