diff --git a/README b/README index 8b40549..184cd3d 100644 --- a/README +++ b/README @@ -1,5 +1,6 @@ -Hello World! +MiniSub +External Subsonic Music Player 8/15/2011 .001 Initial Release - -.003 Fixed song details on player \ No newline at end of file +8/15/2011 .003 Fixed song details on player +8/17/2011 .004 https fix, audio player tweaks \ No newline at end of file diff --git a/Style.css b/Style.css index 7a2f409..def972c 100644 --- a/Style.css +++ b/Style.css @@ -143,12 +143,14 @@ ul.simplelist li:hover { background: #F7FBFF; } -ul.mainlist li.index +ul.simplelist li.index { background: #EDEDED; border-bottom: 1px solid #DDDDDD; color: #A1A1A1; font-size: 11px; + margin: 2px 0; + padding: 0 4px; } ul.mainlist li.selected { diff --git a/index.html b/index.html index cb6b55d..b814374 100644 --- a/index.html +++ b/index.html @@ -87,15 +87,19 @@ } }); + // Main Click Events // Multiple Select $('.noselect').disableTextSelect(); var lastChecked = null; $('ul.songlist li.song').live('click', function (event) { var checkboxclass = 'ul.songlist li.song'; + var songid = $(this).attr('childid'); + var albumid = $(this).attr('parentid'); if ($(this).hasClass('selected')) { $(this).removeClass('selected'); } else { $(this).addClass('selected'); + playSong('selected', this, songid, albumid); } if (!lastChecked) { lastChecked = this; @@ -111,14 +115,13 @@ lastChecked = this; }); - // Main Click Events - // Load in a track on click + // Play Track - Global Click Event $('ul.songlist li.song').live('dblclick', function (e) { e.preventDefault(); - $(this).addClass('playing').siblings().removeClass('playing'); + //$(this).addClass('playing').siblings().removeClass('playing'); var songid = $(this).attr('childid'); var albumid = $(this).attr('parentid'); - playSong(songid, albumid); + playSong('', this, songid, albumid); }); // Action Menu Click Events @@ -219,7 +222,7 @@ $.cookie('password', null); }); - }); // End document.ready + }); // End document.ready var a; var audio; @@ -236,10 +239,10 @@ function changeTrack(next) { if (!next.length) next = $('ul.songlist li').first(); - next.addClass('playing').siblings().removeClass('playing'); + //next.addClass('playing').siblings().removeClass('playing'); var songid = $(next).attr('childid'); var albumid = $(next).attr('parentid'); - playSong(songid, albumid); + playSong('', next, songid, albumid); } @@ -286,7 +289,16 @@
+ +
diff --git a/js/app.js b/js/app.js index 54b270c..52a83fc 100644 --- a/js/app.js +++ b/js/app.js @@ -24,6 +24,11 @@ function loadTabContent(tab) { $(this).addClass('selected'); getPlaylist($(this).attr("id")); }); + $('ul#AutoPlaylistContainer li.item').live('click', function () { + $('ul#AutoPlaylistContainer li').removeClass('selected'); + $(this).addClass('selected'); + getAlbumListBy($(this).attr("id")); + }); break; case '#tabPreferences': //loadPreferences(); @@ -75,45 +80,47 @@ function getAlbums(id) { }, success: function (data) { $("#AlbumContainer").empty(); - // There is a bug in the API that doesn't return a JSON array for one artist - var children = []; - if (data["subsonic-response"].directory.child.length > 0) { - children = data["subsonic-response"].directory.child; - } else { - children[0] = data["subsonic-response"].directory.child; + if (data["subsonic-response"].directory.child != undefined) { + // There is a bug in the API that doesn't return a JSON array for one artist + var children = []; + if (data["subsonic-response"].directory.child.length > 0) { + children = data["subsonic-response"].directory.child; + } else { + children[0] = data["subsonic-response"].directory.child; + } + + var rowcolor; + var albumhtml; + $.each(children, function (i, child) { + if (i % 2 == 0) { + rowcolor = 'even'; + } else { + rowcolor = 'odd'; + } + + if (child.isDir == true) { + albumhtml = '
  • '; + albumhtml += '
    '; + albumhtml += '' + child.title + ''; + albumhtml += '
  • '; + $(albumhtml).appendTo("#AlbumContainer"); + } else { + var track; + if (child.track === undefined) { track = " "; } else { track = child.track; } + var time = secondsToTime(child.duration); + albumhtml = '
  • '; + albumhtml += '' + track + ' '; + albumhtml += child.title; + albumhtml += ' ' + time['m'] + ':' + time['s'] + ''; + albumhtml += '
  • '; + $(albumhtml).appendTo("#AlbumContainer"); + } + }); } - - var rowcolor; - var albumhtml; - $.each(children, function (i, child) { - if (i % 2 == 0) { - rowcolor = 'even'; - } else { - rowcolor = 'odd'; - } - - if (child.isDir == true) { - albumhtml = '
  • '; - albumhtml += '
    '; - albumhtml += '' + child.title + ''; - albumhtml += '
  • '; - $(albumhtml).appendTo("#AlbumContainer"); - } else { - var track; - if (child.track === undefined) { track = " "; } else { track = child.track; } - var time = secondsToTime(child.duration); - albumhtml = '
  • '; - albumhtml += '' + track + ' '; - albumhtml += child.title; - albumhtml += ' ' + time['m'] + ':' + time['s'] + ''; - albumhtml += '
  • '; - $(albumhtml).appendTo("#AlbumContainer"); - } - }); } }); } -function playSong(songid, albumid) { +function playSong(action, el, songid, albumid) { $.ajax({ url: baseURL + '/getMusicDirectory.view?v=1.5.0&c=subweb&f=json&id=' + albumid, method: 'GET', @@ -122,20 +129,28 @@ function playSong(songid, albumid) { req.setRequestHeader('Authorization', auth); }, success: function (data) { - if (data["subsonic-response"].directory.child.length > 0) { - $.each(data["subsonic-response"].directory.child, function (i, child) { - if (child.id == songid) { - $('#songdetails_song').html(child.title); - $('#songdetails_artist').html(child.artist); - $('#songdetails_album').html(child.album); - } - }); - } else { - + var title, artist, album; + if (data["subsonic-response"].directory != undefined) { + if (data["subsonic-response"].directory.child.length > 0) { + $.each(data["subsonic-response"].directory.child, function (i, child) { + if (child.id == songid) { + title = child.title; + artist = child.artist; + album = child.album; + } + }); + } } - audio.load(baseURL + '/stream.view?v=1.5.0&c=subweb&f=json&id=' + songid); - audio.play(); + $('#songdetails_song').html(title); + $('#songdetails_artist').html(artist); + $('#songdetails_album').html(album); $('#coverartimage').attr('src', baseURL + '/getCoverArt.view?v=1.5.0&c=subweb&f=json&size=120&id=' + songid); + if (action != 'selected') { + audio.load(baseURL + '/stream.view?v=1.5.0&c=subweb&f=json&id=' + songid); + audio.play(); + $('ul.songlist li.song').removeClass('playing'); + $(el).addClass('playing'); + } } }); } @@ -393,7 +408,67 @@ function getPlaylist(id) { } }); } +function getAlbumListBy(id) { + $.ajax({ + url: baseURL + '/getAlbumList.view?v=1.5.0&c=subweb&f=json&type=' + id, + method: 'GET', + dataType: 'json', + beforeSend: function (req) { + req.setRequestHeader('Authorization', auth); + }, + success: function (data) { + if (data["subsonic-response"].albumList.album != undefined) { + $("#TrackContainer").empty(); + // There is a bug in the API that doesn't return a JSON array for one artist + var albums = []; + if (data["subsonic-response"].albumList.album.length > 0) { + albums = data["subsonic-response"].albumList.album; + } else { + albums[0] = data["subsonic-response"].albumList.album; + } + var rowcolor; + var html; + $.each(albums, function (i, album) { + $.ajax({ + url: baseURL + '/getMusicDirectory.view?v=1.5.0&c=subweb&f=json&size=5&id=' + album.id, + method: 'GET', + dataType: 'json', + beforeSend: function (req) { + req.setRequestHeader('Authorization', auth); + }, + success: function (data) { + var children = []; + if (data["subsonic-response"].directory.child.length > 0) { + children = data["subsonic-response"].directory.child; + } else { + children[0] = data["subsonic-response"].directory.child; + } + $.each(children, function (i, child) { + if (i % 2 == 0) { + rowcolor = 'even'; + } else { + rowcolor = 'odd'; + } + var track; + if (child.track === undefined) { track = " "; } else { track = child.track; } + var time = secondsToTime(child.duration); + html = '
  • '; + html += '' + track + ' '; + html += child.title; + html += ' ' + time['m'] + ':' + time['s'] + ''; + html += '
  • '; + $(html).appendTo("#TrackContainer"); + }); + } + }); + }); + } else { + $('ul#TrackContainer').empty(); + } + } + }); +} /* Reusable Functions */ function confirmDelete() {