From 1c077f58b61f0e4dc7972c8fe3bdbfc242191591 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 21 Feb 2014 07:17:11 -0800 Subject: Just completely revert this, can't figure out why it's giving some people trouble still --- src/github/daneren2005/dsub/service/DownloadService.java | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index 01753026..6a307152 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -830,17 +830,7 @@ public class DownloadService extends Service { nextPlayingIndex++; } if (index != -1 && nextPlayingIndex < size()) { - if(nextPlaying != null && downloadList.get(nextPlayingIndex) == nextPlaying && nextPlayerState == PlayerState.PREPARED && remoteState == RemoteControlState.LOCAL) { - if(mediaPlayer.isPlaying()) { - mediaPlayer.stop(); - } - mediaPlayer.setOnErrorListener(null); - mediaPlayer.setOnCompletionListener(null); - mediaPlayer.reset(); - playNext(true); - } else { - play(nextPlayingIndex); - } + play(nextPlayingIndex); } } -- cgit v1.2.3 From d610d234f412173f81a6367c425d976e3a66f667 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 21 Feb 2014 19:18:42 -0800 Subject: Fix crash from changing media route from separate thread --- src/github/daneren2005/dsub/service/JukeboxController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/service/JukeboxController.java b/src/github/daneren2005/dsub/service/JukeboxController.java index 7f248f03..ebebbaf8 100644 --- a/src/github/daneren2005/dsub/service/JukeboxController.java +++ b/src/github/daneren2005/dsub/service/JukeboxController.java @@ -217,9 +217,9 @@ public class JukeboxController extends RemoteController { @Override public void run() { Util.toast(downloadService, resourceId, false); + downloadService.setRemoteEnabled(RemoteControlState.LOCAL); } }); - downloadService.setRemoteEnabled(RemoteControlState.LOCAL); } private MusicService getMusicService() { -- cgit v1.2.3 From f862a48ef1390deb70420334d02549bdb8f3ec4c Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 21 Feb 2014 19:22:27 -0800 Subject: Fix 2.3 crash --- src/github/daneren2005/dsub/fragments/DownloadFragment.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/src/github/daneren2005/dsub/fragments/DownloadFragment.java index 0a146b33..87cffd03 100644 --- a/src/github/daneren2005/dsub/fragments/DownloadFragment.java +++ b/src/github/daneren2005/dsub/fragments/DownloadFragment.java @@ -13,6 +13,7 @@ import android.content.SharedPreferences; import android.graphics.Color; import android.os.Bundle; import android.os.Handler; +import android.support.v4.view.MenuItemCompat; import android.support.v7.app.MediaRouteButton; import android.view.ContextMenu; import android.view.Display; @@ -505,7 +506,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe if(downloadService != null) { MenuItem mediaRouteItem = menu.findItem(R.id.menu_mediaroute); if(mediaRouteItem != null) { - MediaRouteButton mediaRouteButton = (MediaRouteButton) mediaRouteItem.getActionView(); + MediaRouteButton mediaRouteButton = (MediaRouteButton) MenuItemCompat.getActionView(mediaRouteItem); mediaRouteButton.setRouteSelector(downloadService.getRemoteSelector()); } } -- cgit v1.2.3 From 961a1ef5df15620c794aa8e062dd9594eb8ecb00 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 21 Feb 2014 19:28:09 -0800 Subject: Fix pressing play while restoring playing two songs at once --- src/github/daneren2005/dsub/service/DownloadService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index 6a307152..e8829aa6 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -368,7 +368,7 @@ public class DownloadService extends Service { } } - public void restore(List songs, List toDelete, int currentPlayingIndex, int currentPlayingPosition) { + public synchronized void restore(List songs, List toDelete, int currentPlayingIndex, int currentPlayingPosition) { SharedPreferences prefs = Util.getPreferences(this); remoteState = RemoteControlState.values()[prefs.getInt(Constants.PREFERENCES_KEY_CONTROL_MODE, 0)]; if(remoteState != RemoteControlState.LOCAL) { -- cgit v1.2.3 From a8d3785fc7685b097f305caedfc2f66aaaba6aee Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 21 Feb 2014 23:14:07 -0800 Subject: Use a separately maintained library for proxy connections --- .gitmodules | 3 + ServerProxy | 1 + Subsonic.iml | 1 + project.properties | 3 +- .../daneren2005/dsub/service/DownloadFile.java | 37 ++- .../daneren2005/dsub/service/DownloadService.java | 16 +- .../daneren2005/dsub/service/StreamProxy.java | 311 --------------------- 7 files changed, 51 insertions(+), 321 deletions(-) create mode 160000 ServerProxy delete mode 100644 src/github/daneren2005/dsub/service/StreamProxy.java (limited to 'src') diff --git a/.gitmodules b/.gitmodules index 5a0b6b8c..dcb0d0b7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "DragSortListView"] path = DragSortListView url = https://github.com/bauerca/drag-sort-listview.git +[submodule "ServerProxy"] + path = ServerProxy + url = https://github.com/daneren2005/ServerProxy.git diff --git a/ServerProxy b/ServerProxy new file mode 160000 index 00000000..1fab7a86 --- /dev/null +++ b/ServerProxy @@ -0,0 +1 @@ +Subproject commit 1fab7a8626616ea7f4df9aa3381a7c0bbf5529d6 diff --git a/Subsonic.iml b/Subsonic.iml index 31ebc6b4..0e656645 100644 --- a/Subsonic.iml +++ b/Subsonic.iml @@ -21,6 +21,7 @@ + diff --git a/project.properties b/project.properties index 80f83a52..d03eb683 100644 --- a/project.properties +++ b/project.properties @@ -12,4 +12,5 @@ target=android-19 android.library.reference.1=../../../../Program Files (x86)/Android/android-sdk/extras/android/support/v7/appcompat android.library.reference.2=DragSortListView/library android.library.reference.3=../../../../Program Files (x86)/Android/android-sdk/extras/android/support/v7/mediarouter -android.library.reference.4=../../../../Program Files (x86)/Android/android-sdk/extras/google/google_play_services/libproject/google-play-services_lib \ No newline at end of file +android.library.reference.4=../../../../Program Files (x86)/Android/android-sdk/extras/google/google_play_services/libproject/google-play-services_lib +android.library.reference.5=ServerProxy \ No newline at end of file diff --git a/src/github/daneren2005/dsub/service/DownloadFile.java b/src/github/daneren2005/dsub/service/DownloadFile.java index 9598b572..d7c3959c 100644 --- a/src/github/daneren2005/dsub/service/DownloadFile.java +++ b/src/github/daneren2005/dsub/service/DownloadFile.java @@ -36,6 +36,8 @@ import github.daneren2005.dsub.util.CancellableTask; import github.daneren2005.dsub.util.FileUtil; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.util.CacheCleaner; +import github.daneren2005.serverproxy.BufferFile; + import org.apache.http.Header; import org.apache.http.HttpResponse; @@ -45,7 +47,7 @@ import org.apache.http.HttpStatus; * @author Sindre Mehus * @version $Id$ */ -public class DownloadFile { +public class DownloadFile implements BufferFile { private static final String TAG = DownloadFile.class.getSimpleName(); private static final int MAX_FAILURES = 5; private final Context context; @@ -63,7 +65,7 @@ public class DownloadFile { private boolean isPlaying = false; private boolean saveWhenDone = false; private boolean completeWhenDone = false; - private Integer contentLength = null; + private Long contentLength = null; private long currentSpeed = 0; public DownloadFile(Context context, MusicDirectory.Entry song, boolean save) { @@ -108,7 +110,7 @@ public class DownloadFile { return br; } - public Integer getContentLength() { + public Long getContentLength() { return contentLength; } @@ -125,6 +127,7 @@ public class DownloadFile { } } + @Override public long getEstimatedSize() { if(contentLength != null) { return contentLength; @@ -136,7 +139,7 @@ public class DownloadFile { } else if(song.getDuration() == null) { return 0; } else { - int br = (getBitRate() * 1024) / 8; + int br = (getBitRate() * 1000) / 8; int duration = song.getDuration(); return br * duration; } @@ -171,6 +174,17 @@ public class DownloadFile { } } + @Override + public File getFile() { + if (saveFile.exists()) { + return saveFile; + } else if (completeFile.exists()) { + return completeFile; + } else { + return partialFile; + } + } + public File getCompleteFile() { if (saveFile.exists()) { return saveFile; @@ -195,11 +209,22 @@ public class DownloadFile { return saveFile.exists() || completeFile.exists(); } + @Override public synchronized boolean isWorkDone() { return saveFile.exists() || (completeFile.exists() && !save) || saveWhenDone || completeWhenDone; } - public synchronized boolean isDownloading() { + @Override + public void onStart() { + setPlaying(true); + } + + @Override + public void onStop() { + setPlaying(false); + } + + public synchronized boolean isDownloading() { return downloadTask != null && downloadTask.isRunning(); } @@ -353,7 +378,7 @@ public class DownloadFile { String contentLengthString = contentLengthHeader.getValue(); if(contentLengthString != null) { Log.i(TAG, "Content Length: " + contentLengthString); - contentLength = Integer.parseInt(contentLengthString); + contentLength = Long.parseLong(contentLengthString); } } in = response.getEntity().getContent(); diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index e8829aa6..5e02641a 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -43,6 +43,7 @@ import github.daneren2005.dsub.util.ShufflePlayBuffer; import github.daneren2005.dsub.util.SimpleServiceBinder; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.util.compat.RemoteControlClientHelper; +import github.daneren2005.serverproxy.BufferProxy; import java.io.File; import java.util.ArrayList; @@ -133,7 +134,7 @@ public class DownloadService extends Service { private boolean showVisualization; private RemoteControlState remoteState = RemoteControlState.LOCAL; private PositionCache positionCache; - private StreamProxy proxy; + private BufferProxy proxy; private Timer sleepTimer; private int timerDuration; @@ -274,6 +275,10 @@ public class DownloadService extends Service { remoteController.stop(); remoteController.shutdown(); } + if(proxy != null) { + proxy.stop(); + proxy = null; + } mediaRouter.destroy(); Util.hidePlayingNotification(this, this, handler); Util.hideDownloadingNotification(this); @@ -552,6 +557,10 @@ public class DownloadService extends Service { } updateJukeboxPlaylist(); setNextPlaying(); + if(proxy != null) { + proxy.stop(); + proxy = null; + } } public synchronized void remove(int which) { @@ -1206,10 +1215,11 @@ public class DownloadService extends Service { String dataSource = file.getPath(); if(isPartial) { if (proxy == null) { - proxy = new StreamProxy(this); + proxy = new BufferProxy(this); proxy.start(); } - dataSource = String.format("http://127.0.0.1:%d/%s", proxy.getPort(), URLEncoder.encode(dataSource, Constants.UTF_8)); + proxy.setBufferFile(downloadFile); + dataSource = proxy.getPrivateAddress(dataSource); Log.i(TAG, "Data Source: " + dataSource); } else if(proxy != null) { proxy.stop(); diff --git a/src/github/daneren2005/dsub/service/StreamProxy.java b/src/github/daneren2005/dsub/service/StreamProxy.java deleted file mode 100644 index d660b6d3..00000000 --- a/src/github/daneren2005/dsub/service/StreamProxy.java +++ /dev/null @@ -1,311 +0,0 @@ -package github.daneren2005.dsub.service; - -import java.io.BufferedOutputStream; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.net.InetAddress; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.SocketException; -import java.net.SocketTimeoutException; -import java.net.URLDecoder; -import java.net.UnknownHostException; -import java.util.StringTokenizer; - -import org.apache.http.Header; -import org.apache.http.HttpRequest; -import org.apache.http.message.BasicHttpRequest; - -import android.os.AsyncTask; -import android.os.Looper; -import android.util.Log; -import github.daneren2005.dsub.domain.MusicDirectory; -import github.daneren2005.dsub.util.Constants; - -public class StreamProxy implements Runnable { - private static final String TAG = StreamProxy.class.getSimpleName(); - - private Thread thread; - private boolean isRunning; - private ServerSocket socket; - private int port; - private DownloadService downloadService; - - public StreamProxy(DownloadService downloadService) { - - // Create listening socket - try { - socket = new ServerSocket(0, 0, InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 })); - socket.setSoTimeout(5000); - port = socket.getLocalPort(); - this.downloadService = downloadService; - } catch (UnknownHostException e) { // impossible - } catch (IOException e) { - Log.e(TAG, "IOException initializing server", e); - } - } - - public int getPort() { - return port; - } - - public void start() { - thread = new Thread(this, "StreamProxy"); - thread.start(); - } - - public void stop() { - isRunning = false; - thread.interrupt(); - } - - @Override - public void run() { - isRunning = true; - while (isRunning) { - try { - Socket client = socket.accept(); - if (client == null) { - continue; - } - Log.i(TAG, "client connected"); - - StreamToMediaPlayerTask task = new StreamToMediaPlayerTask(client); - if (task.processRequest()) { - new Thread(task).start(); - } - - } catch (SocketTimeoutException e) { - // Do nothing - } catch (IOException e) { - Log.e(TAG, "Error connecting to client", e); - } - } - Log.i(TAG, "Proxy interrupted. Shutting down."); - } - - private class StreamToMediaPlayerTask implements Runnable { - DownloadFile downloadFile; - File file; - Socket client; - int cbSkip = 0; - - public StreamToMediaPlayerTask(Socket client) { - this.client = client; - } - - private HttpRequest readRequest() { - HttpRequest request = null; - InputStream is; - String firstLine; - BufferedReader reader = null; - try { - is = client.getInputStream(); - reader = new BufferedReader(new InputStreamReader(is), 8192); - firstLine = reader.readLine(); - } catch (IOException e) { - Log.e(TAG, "Error parsing request", e); - return request; - } - - if (firstLine == null) { - Log.i(TAG, "Proxy client closed connection without a request."); - return request; - } - - StringTokenizer st = new StringTokenizer(firstLine); - String method = st.nextToken(); - String uri = st.nextToken(); - String realUri = uri.substring(1); - Log.i(TAG, realUri); - request = new BasicHttpRequest(method, realUri); - - // Get all of the headers - try { - String line; - while((line = reader.readLine()) != null && !"".equals(line)) { - String headerName = line.substring(0, line.indexOf(':')); - String headerValue = line.substring(line.indexOf(": ") + 2); - request.addHeader(headerName, headerValue); - } - } catch(IOException e) { - // Don't really care once past first line - } - - return request; - } - - public boolean processRequest() { - HttpRequest request = readRequest(); - if (request == null) { - return false; - } - - // Read HTTP headers - Log.i(TAG, "Processing request"); - - String localPath; - try { - localPath = URLDecoder.decode(request.getRequestLine().getUri(), Constants.UTF_8); - } catch (UnsupportedEncodingException e) { - Log.e(TAG, "Unsupported encoding", e); - return false; - } - - Log.i(TAG, "Processing request for file " + localPath); - downloadFile = downloadService.getCurrentPlaying(); - File partialFile = new File(localPath); - if (!partialFile.equals(downloadFile.getPartialFile())) { - Log.e(TAG, "File " + localPath + " does not exist"); - return false; - } - - // Use either partial or complete if downloading finished while StreamProxy was idle - file = downloadFile.isCompleteFileAvailable() ? downloadFile.getCompleteFile() : downloadFile.getPartialFile(); - - // Try to get range requested - Header rangeHeader = request.getFirstHeader("Range"); - - if(rangeHeader != null) { - String range = rangeHeader.getValue(); - int index = range.indexOf("="); - if(index >= 0) { - range = range.substring(index + 1); - - index = range.indexOf("-"); - if(index > 0) { - range = range.substring(0, index); - } - - cbSkip = Integer.parseInt(range); - - // Make sure to not try to read past where the file is downloaded - if(cbSkip >= file.length()) { - return false; - } - } - } - - return true; - } - - @Override - public void run() { - Log.i(TAG, "Streaming song in background"); - MusicDirectory.Entry song = downloadFile.getSong(); - - Integer contentLength = downloadFile.getContentLength(); - if(contentLength == null && downloadFile.isWorkDone()) { - contentLength = (int)file.length(); - } - - // Create HTTP header - String headers; - if(cbSkip == 0) { - headers = "HTTP/1.0 200 OK\r\n"; - } else { - headers = "HTTP/1.0 206 OK\r\n;"; - headers += "Content-Range: bytes " + cbSkip + "-" + (file.length() - 1) + "/"; - if(contentLength == null) { - headers += "*"; - } else { - headers += contentLength; - } - - Log.i(TAG, "Streaming starts from: " + cbSkip); - } - headers += "Content-Type: " + "application/octet-stream" + "\r\n"; - - long fileSize; - if(contentLength == null) { - fileSize = downloadFile.getBitRate() * ((song.getDuration() != null) ? song.getDuration() : 0) * 1000 / 8; - } else { - fileSize = contentLength; - headers += "Content-Length: " + fileSize + "\r\n"; - } - Log.i(TAG, "Streaming fileSize: " + fileSize); - - headers += "Connection: close\r\n"; - headers += "\r\n"; - - long cbToSend = fileSize - cbSkip; - OutputStream output = null; - byte[] buff = new byte[64 * 1024]; - try { - output = new BufferedOutputStream(client.getOutputStream(), 32*1024); - output.write(headers.getBytes()); - - // Make sure to have file lock - downloadFile.setPlaying(true); - - // Loop as long as there's stuff to send - while (isRunning && !client.isClosed()) { - - // See if there's more to send - int cbSentThisBatch = 0; - if (file.exists()) { - FileInputStream input = new FileInputStream(file); - input.skip(cbSkip); - int cbToSendThisBatch = input.available(); - while (cbToSendThisBatch > 0) { - int cbToRead = Math.min(cbToSendThisBatch, buff.length); - int cbRead = input.read(buff, 0, cbToRead); - if (cbRead == -1) { - break; - } - cbToSendThisBatch -= cbRead; - cbToSend -= cbRead; - output.write(buff, 0, cbRead); - output.flush(); - cbSkip += cbRead; - cbSentThisBatch += cbRead; - } - input.close(); - } - - // Done regardless of whether or not it thinks it is - if(downloadFile.isWorkDone() && cbSkip >= file.length()) { - break; - } - - // If we did nothing this batch, block for a second - if (cbSentThisBatch == 0) { - Log.d(TAG, "Blocking until more data appears (" + cbToSend + ")"); - Thread.sleep(1000); - } - } - - // Release file lock, use of stream proxy means nothing else is using it - downloadFile.setPlaying(false); - } - catch (SocketException socketException) { - Log.e(TAG, "SocketException() thrown, proxy client has probably closed. This can exit harmlessly"); - - // Release file lock, use of stream proxy means nothing else is using it - downloadFile.setPlaying(false); - } - catch (Exception e) { - Log.e(TAG, "Exception thrown from streaming task:"); - Log.e(TAG, e.getClass().getName() + " : " + e.getLocalizedMessage()); - } - - // Cleanup - try { - if (output != null) { - output.close(); - } - client.close(); - } - catch (IOException e) { - Log.e(TAG, "IOException while cleaning up streaming task:"); - Log.e(TAG, e.getClass().getName() + " : " + e.getLocalizedMessage()); - } - } - } -} -- cgit v1.2.3 From be9219c4610a31f7a74ba9889a21cc1e0daff2a7 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 22 Feb 2014 11:06:44 -0800 Subject: #285 Add support for offline ChromeCast --- ServerProxy | 2 +- res/menu/nowplaying_offline.xml | 9 +++- .../daneren2005/dsub/fragments/MainFragment.java | 4 ++ .../dsub/service/ChromeCastController.java | 59 +++++++++++++++++++--- .../daneren2005/dsub/service/DownloadService.java | 9 ++++ .../daneren2005/dsub/util/MediaRouteManager.java | 19 +++++-- 6 files changed, 91 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/ServerProxy b/ServerProxy index 1fab7a86..093db239 160000 --- a/ServerProxy +++ b/ServerProxy @@ -1 +1 @@ -Subproject commit 1fab7a8626616ea7f4df9aa3381a7c0bbf5529d6 +Subproject commit 093db23954f2343d280317dc59d33cd039715bca diff --git a/res/menu/nowplaying_offline.xml b/res/menu/nowplaying_offline.xml index 41d1d5d1..7656bf34 100644 --- a/res/menu/nowplaying_offline.xml +++ b/res/menu/nowplaying_offline.xml @@ -7,12 +7,19 @@ android:icon="?attr/shuffle" android:title="@string/download.menu_shuffle" compat:showAsAction="always|withText"/> + + + compat:showAsAction="ifRoom|withText"/> providers = new ArrayList(); + private List offlineProviders = new ArrayList(); static { try { @@ -116,10 +117,22 @@ public class MediaRouteManager extends MediaRouter.Callback { } } + public void addOfflineProviders() { + JukeboxRouteProvider jukeboxProvider = new JukeboxRouteProvider(downloadService); + router.addProvider(jukeboxProvider); + providers.add(jukeboxProvider); + offlineProviders.add(jukeboxProvider); + } + public void removeOfflineProviders() { + for(MediaRouteProvider provider: offlineProviders) { + router.removeProvider(provider); + } + } + private void addProviders() { - JukeboxRouteProvider routeProvider = new JukeboxRouteProvider(downloadService); - router.addProvider(routeProvider); - providers.add(routeProvider); + if(!Util.isOffline(downloadService)) { + addOfflineProviders(); + } } private void buildSelector() { MediaRouteSelector.Builder builder = new MediaRouteSelector.Builder(); -- cgit v1.2.3 From 2bdd4ba3db808d6b283d11d77dfd503e94ed4b1e Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 22 Feb 2014 11:18:13 -0800 Subject: Cancel buffer tasks when going to remote --- src/github/daneren2005/dsub/service/DownloadService.java | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index b3a989ed..396bfdee 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -1154,6 +1154,16 @@ public class DownloadService extends Service { if (currentDownloading != null) { currentDownloading.cancelDownload(); } + + // Cancels current setup tasks + if(bufferTask != null && bufferTask.isRunning()) { + bufferTask.cancel(); + bufferTask = null; + } + if(nextPlayingTask != null && nextPlayingTask.isRunning()) { + nextPlayingTask.cancel(); + nextPlayingTask = null; + } } SharedPreferences prefs = Util.getPreferences(this); -- cgit v1.2.3 From d622047a4d01122064afc177b89df522b19f12af Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 22 Feb 2014 11:23:34 -0800 Subject: #288 Only require external address for https addresses --- .../dsub/service/ChromeCastController.java | 26 +++++++++++++++++----- .../daneren2005/dsub/service/RESTMusicService.java | 4 ++-- 2 files changed, 23 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/service/ChromeCastController.java b/src/github/daneren2005/dsub/service/ChromeCastController.java index 3cfde4c6..02661f14 100644 --- a/src/github/daneren2005/dsub/service/ChromeCastController.java +++ b/src/github/daneren2005/dsub/service/ChromeCastController.java @@ -244,8 +244,8 @@ public class ChromeCastController extends RemoteController { url = musicService.getMusicUrl(downloadService, song, currentPlaying.getBitRate()); } - // Use separate profile for Chromecast so users can do ogg on phone, mp3 for CC - url = url.replace(Constants.REST_CLIENT_ID, Constants.CHROMECAST_CLIENT_ID); + url = fixURLs(url); + Log.i(TAG, "Cast url: " + url); } // Setup song/video information @@ -259,17 +259,19 @@ public class ChromeCastController extends RemoteController { meta.putString(MediaMetadata.KEY_ALBUM_ARTIST, song.getArtist()); meta.putString(MediaMetadata.KEY_ALBUM_TITLE, song.getAlbum()); - String coverArt; + String coverArt = ""; if(proxy == null) { coverArt = musicService.getCoverArtUrl(downloadService, song); + coverArt = fixURLs(coverArt); meta.addImage(new WebImage(Uri.parse(coverArt))); } else { File coverArtFile = FileUtil.getAlbumArtFile(downloadService, song); if(coverArtFile != null && coverArtFile.exists()) { - coverArt = coverArtFile.getPath(); - meta.addImage(new WebImage(Uri.parse(proxy.getPublicAddress(coverArt)))); + coverArt = proxy.getPublicAddress(coverArtFile.getPath()); + meta.addImage(new WebImage(Uri.parse(coverArt))); } } + Log.i(TAG, "Cover art: " + coverArt); } String contentType; @@ -315,6 +317,20 @@ public class ChromeCastController extends RemoteController { } } + private String fixURLs(String url) { + // Only change to internal when using https + if(url.indexOf("https") != -1) { + SharedPreferences prefs = Util.getPreferences(downloadService); + int instance = prefs.getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1); + String externalUrl = prefs.getString(Constants.PREFERENCES_KEY_SERVER_URL + instance, null); + String internalUrl = prefs.getString(Constants.PREFERENCES_KEY_SERVER_INTERNAL_URL + instance, null); + url = url.replace(internalUrl, externalUrl); + } + + // Use separate profile for Chromecast so users can do ogg on phone, mp3 for CC + return url.replace(Constants.REST_CLIENT_ID, Constants.CHROMECAST_CLIENT_ID); + } + private void failedLoad() { Util.toast(downloadService, downloadService.getResources().getString(R.string.download_failed_to_load)); downloadService.setPlayerState(PlayerState.STOPPED); diff --git a/src/github/daneren2005/dsub/service/RESTMusicService.java b/src/github/daneren2005/dsub/service/RESTMusicService.java index 8ea29a41..879339cc 100644 --- a/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -623,7 +623,7 @@ public class RESTMusicService implements MusicService { @Override public String getCoverArtUrl(Context context, MusicDirectory.Entry entry) throws Exception { - StringBuilder builder = new StringBuilder(getRestUrl(context, "getCoverArt", false)); + StringBuilder builder = new StringBuilder(getRestUrl(context, "getCoverArt")); builder.append("&id=").append(entry.getId()); String url = rewriteUrlWithRedirect(context, builder.toString()); return url; @@ -710,7 +710,7 @@ public class RESTMusicService implements MusicService { @Override public String getMusicUrl(Context context, MusicDirectory.Entry song, int maxBitrate) throws Exception { - StringBuilder builder = new StringBuilder(getRestUrl(context, "stream", false)); + StringBuilder builder = new StringBuilder(getRestUrl(context, "stream")); builder.append("&id=").append(song.getId()); builder.append("&maxBitRate=").append(maxBitrate); -- cgit v1.2.3 From ce4684ad9618f063abf3eb4a42cb81361a17be1d Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 23 Feb 2014 12:05:26 -0800 Subject: Fix issue with handler not being initialized in some cases --- src/github/daneren2005/dsub/util/BackgroundTask.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/util/BackgroundTask.java b/src/github/daneren2005/dsub/util/BackgroundTask.java index b9fe212f..fbeaea74 100644 --- a/src/github/daneren2005/dsub/util/BackgroundTask.java +++ b/src/github/daneren2005/dsub/util/BackgroundTask.java @@ -53,7 +53,7 @@ public abstract class BackgroundTask implements ProgressListener { private static Handler handler = null; static { try { - handler = new Handler(); + handler = new Handler(Looper.getMainLooper()); } catch(Exception e) { // Not called from main thread } @@ -69,6 +69,13 @@ public abstract class BackgroundTask implements ProgressListener { thread.start(); } } + if(handler == null) { + try { + handler = new Handler(Looper.getMainLooper()); + } catch(Exception e) { + // Not called from main thread + } + } } public static void stopThreads() { -- cgit v1.2.3 From 60b2b93c80ec35d91553b3336892b12eb24911e1 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 23 Feb 2014 13:07:01 -0800 Subject: Fix 4.1- issue --- src/github/daneren2005/dsub/activity/SubsonicActivity.java | 2 +- src/github/daneren2005/dsub/util/LoadingTask.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/src/github/daneren2005/dsub/activity/SubsonicActivity.java index c1534639..62349480 100644 --- a/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -649,7 +649,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte } } - public boolean isDestroyed() { + public boolean isDestroyedCompat() { return destroyed; } diff --git a/src/github/daneren2005/dsub/util/LoadingTask.java b/src/github/daneren2005/dsub/util/LoadingTask.java index c47931ee..17215abd 100644 --- a/src/github/daneren2005/dsub/util/LoadingTask.java +++ b/src/github/daneren2005/dsub/util/LoadingTask.java @@ -52,7 +52,7 @@ public abstract class LoadingTask extends BackgroundTask { @Override protected boolean isCancelled() { - return (tabActivity instanceof SubsonicActivity && tabActivity.isDestroyed()) || cancelled; + return (tabActivity instanceof SubsonicActivity && ((SubsonicActivity) tabActivity).isDestroyedCompat()) || cancelled; } @Override -- cgit v1.2.3 From 1ad51c4b9c8fcea55a517e626f9747e0a78d33f6 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 23 Feb 2014 13:29:52 -0800 Subject: Fix trying to use old suggestion after clearing list --- src/github/daneren2005/dsub/service/DownloadService.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index 396bfdee..924f53a7 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -570,6 +570,9 @@ public class DownloadService extends Service { proxy.stop(); proxy = null; } + + suggestedPlaylistName = null; + suggestedPlaylistId = null; } public synchronized void remove(int which) { -- cgit v1.2.3