Prevent Player Cache Issues [Done]

Mission accomplished!
User avatar
Madsonic
Administrator
Administrator
Posts: 984
Joined: 07 Dec 2012, 03:58
Answers: 7
Has thanked: 1201 times
Been thanked: 470 times

Prevent Player Cache Issues [Done]

Unread post by Madsonic »

I know this is in a million other posts, so I started a new topic. I developed a method of preventing the common browser cache issues that cause the player to appear to begin loading, but stops the music within the first few seconds of playback.

After this modification, you will rarely if ever have to clear your cache to play a song.

Basically, we are going to salt the URL passed to the player in playqueue.jsp.
Because the cache stores separate info for each unique URL, this will prevent the cache from re-caching the same URL over and over, which is what causes the problem in the first place.

We are going to edit playqueue.jsp.

Here is the part of the file we are going to edit:

Code: Select all

function skip(index) {
        if (index < 0 || index >= songs.length) {
            return;
        }

        var song = songs[index];
        currentStreamUrl = song.streamUrl;
        updateCurrentImage();
        var list = new Array();
        list[0] = {
            file:song.streamUrl,
            title:song.title,
            provider:"sound"
        };

        if (song.duration != null) {
            list[0].duration = song.duration;
        }
        if (song.format == "aac" || song.format == "m4a") {
            list[0].provider = "video";
        }

        player.sendEvent("LOAD", list);
        player.sendEvent("PLAY");
    }
All you have to do, is replace it with this:

Code: Select all

function skip(index) {
        if (index < 0 || index >= songs.length) {
            return;
        }

        var song = songs[index];
        var saltedUrl = song.streamUrl + "&salt=" + Math.floor(Math.random()*100000);
        
        currentStreamUrl = song.streamUrl;
        updateCurrentImage();
        var list = new Array();
        list[0] = {
            file:saltedUrl,
            title:song.title,
            provider:"sound"
        };

        if (song.duration != null) {
            list[0].duration = song.duration;
        }
        if (song.format == "aac" || song.format == "m4a") {
            list[0].provider = "video";
        }

        player.sendEvent("LOAD", list);
        player.sendEvent("PLAY");
    }
That will append a parameter named "salt" to the end of the URL and the value of the parameter will be picked randomly.

Hope this helps!
gurutech
Contributor
Contributor
Posts: 323
Joined: 02 Jan 2013, 04:56
Has thanked: 11 times
Been thanked: 105 times

Re: Prevent Player Cache Issues

Unread post by gurutech »

Just searched my playlist.jsp and don't see the skip(index) function.

Can I just add the modified code to the file, or am I out of luck? Running build 3292.

Thanks!
User avatar
Madsonic
Administrator
Administrator
Posts: 984
Joined: 07 Dec 2012, 03:58
Answers: 7
Has thanked: 1201 times
Been thanked: 470 times

Re: Prevent Player Cache Issues

Unread post by Madsonic »

This is already been implemented in madsonic, but since 4.7/4.8 it's in playqueue.jsp instead of playlist.jsp

best regards
gurutech
Contributor
Contributor
Posts: 323
Joined: 02 Jan 2013, 04:56
Has thanked: 11 times
Been thanked: 105 times

Re: Prevent Player Cache Issues

Unread post by gurutech »

Then this isn't the cause of the problems I'm having. :|

It must be something with how some of my MP3's were ripped (quality or compatibility?) MadSonic will play most of them just fine, but a select few will not play at all. These ones that don't play WILL play in another music player, so that leaves just the transcoder (ffmpeg?) that can't read the files for some reason.

Any way to test this?
User avatar
Madsonic
Administrator
Administrator
Posts: 984
Joined: 07 Dec 2012, 03:58
Answers: 7
Has thanked: 1201 times
Been thanked: 470 times

Re: Prevent Player Cache Issues

Unread post by Madsonic »

Can you send me one file to test with my server and settings?
best regards
gurutech
Contributor
Contributor
Posts: 323
Joined: 02 Jan 2013, 04:56
Has thanked: 11 times
Been thanked: 105 times

Re: Prevent Player Cache Issues

Unread post by gurutech »

Last edited by gurutech on 03 Jan 2013, 14:51, edited 1 time in total.
User avatar
Madsonic
Administrator
Administrator
Posts: 984
Joined: 07 Dec 2012, 03:58
Answers: 7
Has thanked: 1201 times
Been thanked: 470 times

Re: AW: Prevent Player Cache Issues

Unread post by Madsonic »

I will check this, in the next days.
Post Reply