Auto-scroll playlist to current track

Third-party modifications and add-ons, Apps and Clients

Moderator: moderators

Auto-scroll playlist to current track

Postby bull » Tue Dec 14, 2010 4:34 am

I've been hacking together a custom interface for a touchscreen friendly version of Subsonic. As a result of limited screen space - and an aim to keeping things simple - I've moved the playlist to the top of the screen and reduced it to only 4 lines. Roughly my interface looks like this:

Image

This meant that after a few tracks I couldn't see which song was playing. After digging around I found the perfect spot to put a single line of Javascript to fix this; the updateCurrentImage() function in playlist.jsp (found around line 330). New code looks like this:

Code: Select all
function updateCurrentImage() {
        for (var i = 0; i < songs.length; i++) {
            var song  = songs[i];
            var id = i + 1;
            var image = $("currentImage" + id);

            if (image) {
                if (song.streamUrl == currentStreamUrl) {
                    image.show();
                    window.scroll(0,(i*18));
            } else {
                    image.hide();
                }
            }
        }
    }


The magic line is window.scroll. Depending on the size of your font you may need to adjust the number, for my setup each line was 18 pixels high. I tried to base this number on the em height provided in the CSS, but it was easier just to kludge it like this.

Also by default this won't scroll until a track has changed, which means that if you refresh the page the scrolling back to the top. I fixed this by calling updateCurrentImage() at the beginning of nowPlayingCallback function (around line 50)[/code]

I know this is pretty simple fix but was a huge help to me, and might be for others that use the default interface but have long playlists.
Last edited by bull on Wed Dec 15, 2010 10:20 pm, edited 2 times in total.
bull
 
Posts: 4
Joined: Sat Nov 13, 2010 7:10 am

Postby compcentral » Tue Dec 14, 2010 3:34 pm

I think you meant:

Code: Select all
window.scroll(0,i*18);


and actually, I think this will work a little better:

Code: Select all
window.scroll(0,(i+1)*18);
compcentral
 
Posts: 24
Joined: Tue Sep 28, 2010 8:56 pm

Postby colli419 » Tue Dec 14, 2010 5:41 pm

I have been looking for ways to reduce the overall size of the interface, this is great. Nice work!
colli419
 
Posts: 75
Joined: Thu Aug 27, 2009 8:23 pm

Postby bull » Tue Dec 14, 2010 7:50 pm

compcentral wrote:I think you meant:

Code: Select all
window.scroll(0,i*18);


and actually, I think this will work a little better:

Code: Select all
window.scroll(0,(i+1)*18);


Ah yes thanks for catching that (I've got a 4 pixel offsest that I add to mine, but removed it for this post and lost a bracket in the process!) I have intentionally kept it scrolling to the previous song as I like the idea of seeing the previous song/current song/next two songs...but you're right that is a "better" way.
bull
 
Posts: 4
Joined: Sat Nov 13, 2010 7:10 am

Postby kroken » Wed Dec 15, 2010 1:49 am

it just scrolls down on mine, see this video

http://www.speedyshare.com/files/25715779/clip0021.avi
kroken
 
Posts: 81
Joined: Sat Oct 16, 2010 6:28 am

Postby bull » Wed Dec 15, 2010 8:12 pm

kroken wrote:it just scrolls down on mine, see this video

http://www.speedyshare.com/files/25715779/clip0021.avi


Not quite sure what's going on there (it was a bit hard to understand in the video if you were skipping tracks manually or it was happening automatically) but if the position is getting progressively more and more out of sync, you'll need to adjust the number (in my example it's 18). This is the height of each row, so it might take a bit of fiddling to find the right multiplier. From the looks of if you will need to increase that number.

Ideally it would be nice to find a magic formula that pulls the em sizes from the CSS and make a one size fits all bit of code, but it's probably just as easy to tweak it by hand.
bull
 
Posts: 4
Joined: Sat Nov 13, 2010 7:10 am

Postby kroken » Thu Dec 16, 2010 12:27 am

yeah but when i have playlist with just an album it work fine but when i add like 200 songs it wont work, im using the default height.
kroken
 
Posts: 81
Joined: Sat Oct 16, 2010 6:28 am


Return to Mods, Apps and Clients

Who is online

Users browsing this forum: No registered users and 4 guests