diff options
Diffstat (limited to 'app/src/main/java/github/daneren2005/dsub/service')
6 files changed, 57 insertions, 23 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/service/ChromeCastController.java b/app/src/main/java/github/daneren2005/dsub/service/ChromeCastController.java index a729ed4e..2f6ecd90 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/ChromeCastController.java +++ b/app/src/main/java/github/daneren2005/dsub/service/ChromeCastController.java @@ -319,21 +319,22 @@ public class ChromeCastController extends RemoteController { meta.putString(MediaMetadata.KEY_ALBUM_ARTIST, song.getArtist()); meta.putString(MediaMetadata.KEY_ALBUM_TITLE, song.getAlbum()); - String coverArt = ""; - if(proxy == null || proxy instanceof WebProxy) { - coverArt = musicService.getCoverArtUrl(downloadService, song); + if(castDevice.hasCapability(CastDevice.CAPABILITY_VIDEO_OUT)) { + if (proxy == null || proxy instanceof WebProxy) { + String coverArt = musicService.getCoverArtUrl(downloadService, song); - // If proxy is going, it is a web proxy - if(proxy != null) { - coverArt = proxy.getPublicAddress(coverArt); - } + // If proxy is going, it is a web proxy + if (proxy != null) { + coverArt = proxy.getPublicAddress(coverArt); + } - meta.addImage(new WebImage(Uri.parse(coverArt))); - } else { - File coverArtFile = FileUtil.getAlbumArtFile(downloadService, song); - if(coverArtFile != null && coverArtFile.exists()) { - coverArt = proxy.getPublicAddress(coverArtFile.getPath()); meta.addImage(new WebImage(Uri.parse(coverArt))); + } else { + File coverArtFile = FileUtil.getAlbumArtFile(downloadService, song); + if (coverArtFile != null && coverArtFile.exists()) { + String coverArt = proxy.getPublicAddress(coverArtFile.getPath()); + meta.addImage(new WebImage(Uri.parse(coverArt))); + } } } } diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java index bc465e74..7af21831 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java @@ -1754,6 +1754,7 @@ public class DownloadService extends Service { autoPlayStart = false; } else { setPlayerState(PAUSED); + onSongProgress(); } } diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java index 442d3dc1..4c8ac586 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java @@ -18,7 +18,6 @@ */ package github.daneren2005.dsub.service; -import java.io.Serializable; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -41,7 +40,6 @@ import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.domain.PlayerQueue; import github.daneren2005.dsub.domain.PlayerState; import github.daneren2005.dsub.domain.ServerInfo; -import github.daneren2005.dsub.util.BackgroundTask; import github.daneren2005.dsub.util.CacheCleaner; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.FileUtil; @@ -323,11 +321,19 @@ public class DownloadServiceLifecycleSupport { position = 0; } + MusicDirectory.Entry currentPlaying = state.songs.get(index); + List<MusicDirectory.Entry> songs = new ArrayList<>(); + for(MusicDirectory.Entry song: state.songs) { + if(song.isOnlineId(downloadService)) { + songs.add(song); + } + } + MusicService musicService = MusicServiceFactory.getMusicService(downloadService); - musicService.savePlayQueue(state.songs, state.songs.get(index), position, downloadService, null); - currentSavePlayQueueTask = null; + musicService.savePlayQueue(songs, currentPlaying, position, downloadService, null); } catch (Exception e) { Log.e(TAG, "Failed to save playing queue to server", e); + } finally { currentSavePlayQueueTask = null; } diff --git a/app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java b/app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java index 2146cd15..17aaf804 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/OfflineMusicService.java @@ -394,8 +394,8 @@ public class OfflineMusicService implements MusicService { Reader reader = null; BufferedReader buffer = null; + int songCount = 0; try { - int songCount = 0; reader = new FileReader(file); buffer = new BufferedReader(reader); @@ -427,7 +427,9 @@ public class OfflineMusicService implements MusicService { Util.close(reader); } - playlists.add(playlist); + if(songCount > 0) { + playlists.add(playlist); + } } } diff --git a/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java b/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java index 97899529..b405211d 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java @@ -41,7 +41,9 @@ import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.conn.params.ConnManagerParams; import org.apache.http.conn.params.ConnPerRouteBean; @@ -730,6 +732,22 @@ public class RESTMusicService implements MusicService { values.add(genre); } if(startYear != null && !"".equals(startYear)) { + // Check to make sure user isn't doing 2015 -> 2010 since Subsonic will return no results + if(endYear != null && !"".equals(endYear)) { + try { + int startYearInt = Integer.parseInt(startYear); + int endYearInt = Integer.parseInt(endYear); + + if(startYearInt > endYearInt) { + String tmp = startYear; + startYear = endYear; + endYear = tmp; + } + } catch(Exception e) { + Log.w(TAG, "Failed to convert start/end year into ints", e); + } + } + names.add("fromYear"); values.add(startYear); } @@ -1886,7 +1904,7 @@ public class RESTMusicService implements MusicService { while (true) { attempts++; HttpContext httpContext = new BasicHttpContext(); - final HttpPost request = new HttpPost(url); + final HttpRequestBase request = (url.indexOf("rest") == -1) ? new HttpGet(url) : new HttpPost(url); if (task != null) { // Attempt to abort the HTTP request if the task is cancelled. @@ -1913,12 +1931,12 @@ public class RESTMusicService implements MusicService { }); } - if (parameterNames != null) { + if (parameterNames != null && request instanceof HttpPost) { List<NameValuePair> params = new ArrayList<NameValuePair>(); for (int i = 0; i < parameterNames.size(); i++) { params.add(new BasicNameValuePair(parameterNames.get(i), String.valueOf(parameterValues.get(i)))); } - request.setEntity(new UrlEncodedFormEntity(params, Constants.UTF_8)); + ((HttpPost) request).setEntity(new UrlEncodedFormEntity(params, Constants.UTF_8)); } if (requestParams != null) { diff --git a/app/src/main/java/github/daneren2005/dsub/service/parser/AbstractParser.java b/app/src/main/java/github/daneren2005/dsub/service/parser/AbstractParser.java index 9ecbba52..664adcfb 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/parser/AbstractParser.java +++ b/app/src/main/java/github/daneren2005/dsub/service/parser/AbstractParser.java @@ -23,6 +23,7 @@ import java.io.Reader; import org.xmlpull.v1.XmlPullParser; import android.content.Context; +import android.util.Log; import android.util.Xml; import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.ServerInfo; @@ -34,7 +35,7 @@ import github.daneren2005.dsub.util.Util; * @author Sindre Mehus */ public abstract class AbstractParser { - + private static final String TAG = AbstractParser.class.getSimpleName(); protected final Context context; protected final int instance; private XmlPullParser parser; @@ -101,7 +102,12 @@ public abstract class AbstractParser { protected Integer getInteger(String name) { String s = get(name); - return s == null ? null : Integer.valueOf(s); + try { + return (s == null || "".equals(s)) ? null : Integer.valueOf(s); + } catch(Exception e) { + Log.w(TAG, "Failed to parse " + s + " into integer"); + return null; + } } protected Long getLong(String name) { |