Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript syntax issue sessionStorage values to setting [duplicate]

First of all I should say that I am not very experienced with JavaScript and I would like some help on passing a sessionStorage value to a setting.

$(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'));
}

What I would like to do is to pass the settings.volume web stored value to the volume parameter

$("#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
        });
    });
like image 419
Konstantinos Koletsas Avatar asked Jun 06 '26 06:06

Konstantinos Koletsas


1 Answers

You are saving the volume earlier, so you just access it in the reverse process when you need it.

For example, change the volume: 75 initialization to a call to a function that get the volume from your saved settings: volume: volumeSetting().

Here's an example of how you might write that function itself:

function volumeSetting() {
  var settings = sessionStorage.getItem("userjPlayerSettings");
  if (settings != null) {
     settings = JSON.parse(settings);
     if (typeof settings.volume == 'number')
       return settings.volume;
  }
  return 75;
}
like image 100
John Coker Avatar answered Jun 07 '26 20:06

John Coker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!