From 243d9cc7d3a154e15f7c4ae17516c656d6e43d17 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 15 Apr 2013 20:07:55 -0700 Subject: Remove a couple of more syncs that are not needed --- .../src/github/daneren2005/dsub/service/DownloadServiceImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'subsonic-android') diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java index 8136114f..5975b9fe 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java @@ -334,7 +334,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { } @Override - public synchronized boolean isShufflePlayEnabled() { + public boolean isShufflePlayEnabled() { return shufflePlay; } @@ -570,7 +570,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { } @Override - public synchronized List getSongs() { + public List getSongs() { return downloadList; } @@ -583,7 +583,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { } @Override - public synchronized List getBackgroundDownloads() { + public List getBackgroundDownloads() { return backgroundDownloadList; } -- cgit v1.2.3 From 03bdca37fbde570746ac03a633ea06c20c310ec7 Mon Sep 17 00:00:00 2001 From: daneren2005 Date: Fri, 19 Apr 2013 15:21:04 -0700 Subject: Try to stop position caching well before end of the song is reached --- .../src/github/daneren2005/dsub/service/DownloadServiceImpl.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'subsonic-android') diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java index 5975b9fe..fce9ef5f 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java @@ -882,7 +882,10 @@ public class DownloadServiceImpl extends Service implements DownloadService { @Override public void run() { thread = Thread.currentThread(); - while(isRunning) { + int duration = currentPlaying.getSong().getDuration() == null ? mediaPlayer.getDuration() : currentPlaying.getSong().getDuration() * 1000; + cachedPosition = 0; + // Stop checking position before the song reaches completion + while(isRunning && (Math.abs(duration - cachedPosition) < 1000)) { try { if(mediaPlayer != null && playerState == STARTED) { cachedPosition = mediaPlayer.getCurrentPosition(); -- cgit v1.2.3 From 30ca30d7604b5da406f2cc6831a8afb1f4592de8 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 19 Apr 2013 21:31:24 -0700 Subject: Fix position cache never running --- .../src/github/daneren2005/dsub/service/DownloadServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'subsonic-android') diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java index fce9ef5f..6d134314 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java @@ -885,7 +885,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { int duration = currentPlaying.getSong().getDuration() == null ? mediaPlayer.getDuration() : currentPlaying.getSong().getDuration() * 1000; cachedPosition = 0; // Stop checking position before the song reaches completion - while(isRunning && (Math.abs(duration - cachedPosition) < 1000)) { + while(isRunning && (Math.abs(duration - cachedPosition) > 1000)) { try { if(mediaPlayer != null && playerState == STARTED) { cachedPosition = mediaPlayer.getCurrentPosition(); -- cgit v1.2.3 From 1395bea48fa3c8837c5a2b8933682cc9df32f889 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 22 Apr 2013 19:35:39 -0700 Subject: Background the view updating where possible --- .../src/github/daneren2005/dsub/view/SongView.java | 21 +++++-- .../github/daneren2005/dsub/view/UpdateView.java | 67 ++++++++++++++++++---- 2 files changed, 74 insertions(+), 14 deletions(-) (limited to 'subsonic-android') diff --git a/subsonic-android/src/github/daneren2005/dsub/view/SongView.java b/subsonic-android/src/github/daneren2005/dsub/view/SongView.java index 7cefae23..45ea04c9 100644 --- a/subsonic-android/src/github/daneren2005/dsub/view/SongView.java +++ b/subsonic-android/src/github/daneren2005/dsub/view/SongView.java @@ -52,6 +52,9 @@ public class SongView extends UpdateView implements Checkable { private TextView statusTextView; private ImageButton starButton; private ImageView moreButton; + + private DownloadService downloadService; + private DownloadFile downloadFile; public SongView(Context context) { super(context); @@ -124,16 +127,26 @@ public class SongView extends UpdateView implements Checkable { update(); } + + @Override + protected void updateBackground() { + if (downloadService == null) { + downloadService = DownloadServiceImpl.getInstance(); + if(downloadService == null) { + return; + } + } + + downloadFile = downloadService.forSong(song); + } @Override protected void update() { - starButton.setVisibility((Util.isOffline(getContext()) || !song.isStarred()) ? View.GONE : View.VISIBLE); - DownloadService downloadService = DownloadServiceImpl.getInstance(); if (downloadService == null) { return; } - - DownloadFile downloadFile = downloadService.forSong(song); + + starButton.setVisibility((Util.isOffline(getContext()) || !song.isStarred()) ? View.GONE : View.VISIBLE); File partialFile = downloadFile.getPartialFile(); int leftImage = 0; diff --git a/subsonic-android/src/github/daneren2005/dsub/view/UpdateView.java b/subsonic-android/src/github/daneren2005/dsub/view/UpdateView.java index 9fbaccf6..7ce27f06 100644 --- a/subsonic-android/src/github/daneren2005/dsub/view/UpdateView.java +++ b/subsonic-android/src/github/daneren2005/dsub/view/UpdateView.java @@ -20,16 +20,22 @@ package github.daneren2005.dsub.view; import android.content.Context; import android.os.Handler; +import android.os.Looper; import android.util.Log; import android.view.ViewGroup; import android.widget.AbsListView; import android.widget.LinearLayout; +import java.util.ArrayList; +import java.util.List; import java.util.WeakHashMap; public class UpdateView extends LinearLayout { private static final String TAG = UpdateView.class.getSimpleName(); private static final WeakHashMap INSTANCES = new WeakHashMap(); - private static Handler handler; + + private static Handler backgroundHandler; + private static Handler uiHandler; + private static Runnable updateRunnable; public UpdateView(Context context) { super(context); @@ -53,33 +59,74 @@ public class UpdateView extends LinearLayout { } private static synchronized void startUpdater() { - if (handler != null) { - return; - } - - handler = new Handler(); - Runnable runnable = new Runnable() { + if(uiHandler != null) { + return; + } + + uiHandler = new Handler(); + updateRunnable = new Runnable() { @Override public void run() { updateAll(); - handler.postDelayed(this, 1000L); } }; - handler.postDelayed(runnable, 1000L); + + new Thread(new Runnable() { + public void run() { + Looper.prepare(); + backgroundHandler = new Handler(Looper.myLooper()); + uiHandler.post(updateRunnable); + Looper.loop(); + } + }).start(); } private static void updateAll() { try { + List views = new ArrayList();; for (UpdateView view : INSTANCES.keySet()) { if (view.isShown()) { - view.update(); + views.add(view); } } + updateAllLive(views); } catch (Throwable x) { Log.w(TAG, "Error when updating song views.", x); } } + private static void updateAllLive(final List views) { + final Runnable runnable = new Runnable() { + @Override + public void run() { + try { + for(UpdateView view: views) { + view.update(); + } + } catch (Throwable x) { + Log.w(TAG, "Error when updating song views.", x); + } + uiHandler.postDelayed(updateRunnable, 1000L); + } + }; + + backgroundHandler.post(new Runnable() { + @Override + public void run() { + try { + for(UpdateView view: views) { + view.updateBackground(); + } + uiHandler.post(runnable); + } catch (Throwable x) { + Log.w(TAG, "Error when updating song views.", x); + } + } + }); + } + protected void updateBackground() { + + } protected void update() { } -- cgit v1.2.3 From 7aa5e9b72c414a627cd3cfab5d9a7ad9658dfd81 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 23 Apr 2013 07:30:45 -0700 Subject: Added in safety check that start can't be -1 --- .../src/github/daneren2005/dsub/service/DownloadServiceImpl.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'subsonic-android') diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java index 6d134314..b78e25d7 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java @@ -1289,6 +1289,9 @@ public class DownloadServiceImpl extends Service implements DownloadService { if(n != 0) { int start = currentPlaying == null ? 0 : getCurrentPlayingIndex(); + if(start == -1) { + start = 0; + } int i = start; do { DownloadFile downloadFile = downloadList.get(i); -- cgit v1.2.3 From dc4ee19b5a2e0ed0de170f7372075a13e9bdd88d Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 24 Apr 2013 20:26:32 -0700 Subject: Make sure to call updateBackground on first set as well --- subsonic-android/src/github/daneren2005/dsub/view/SongView.java | 1 + 1 file changed, 1 insertion(+) (limited to 'subsonic-android') diff --git a/subsonic-android/src/github/daneren2005/dsub/view/SongView.java b/subsonic-android/src/github/daneren2005/dsub/view/SongView.java index 45ea04c9..51927304 100644 --- a/subsonic-android/src/github/daneren2005/dsub/view/SongView.java +++ b/subsonic-android/src/github/daneren2005/dsub/view/SongView.java @@ -125,6 +125,7 @@ public class SongView extends UpdateView implements Checkable { } }); + updateBackground(); update(); } -- cgit v1.2.3 From a4208e2bbf70836bf2c233f86053347371af29b5 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 25 Apr 2013 21:35:09 -0700 Subject: Add in a check to try to kill the LPA player on S3 --- .../daneren2005/dsub/service/DownloadServiceImpl.java | 16 ++++++++++++++++ .../src/github/daneren2005/dsub/util/FileUtil.java | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+) (limited to 'subsonic-android') diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java index b78e25d7..ed869daf 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java @@ -63,6 +63,7 @@ import android.os.Looper; import android.os.PowerManager; import android.util.Log; import github.daneren2005.dsub.activity.SubsonicTabActivity; +import github.daneren2005.dsub.util.FileUtil; import java.net.URLEncoder; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -88,6 +89,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { private final IBinder binder = new SimpleServiceBinder(this); private Looper mediaPlayerLooper; + private MediaPlayer lpaPlayer; private MediaPlayer mediaPlayer; private MediaPlayer nextMediaPlayer; private boolean nextSetup = false; @@ -145,6 +147,19 @@ public class DownloadServiceImpl extends Service implements DownloadService { public void run() { Looper.prepare(); + // LPA Player on some devices causes weird issues, hold a default media player to mask them + try { + File randomSong = FileUtil.getAnySong(DownloadServiceImpl.this); + + lpaPlayer = new MediaPlayer(); + lpaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); + lpaPlayer.setDataSource(randomSong.getPath()); + lpaPlayer.prepareAsync(); + } catch(Exception e) { + // Failed to setup, ignore + Log.w(TAG, "Failed to setup redirect media player", e); + } + mediaPlayer = new MediaPlayer(); mediaPlayer.setWakeMode(DownloadServiceImpl.this, PowerManager.PARTIAL_WAKE_LOCK); @@ -220,6 +235,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName()); sendBroadcast(i); + lpaPlayer.release(); mediaPlayer.release(); if(nextMediaPlayer != null) { nextMediaPlayer.release(); diff --git a/subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java b/subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java index bb89a4d3..65f5a37f 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/FileUtil.java @@ -50,6 +50,25 @@ public class FileUtil { private static final List VIDEO_FILE_EXTENSIONS = Arrays.asList("flv", "mp4", "m4v", "wmv", "avi", "mov", "mpg", "mkv"); private static final List PLAYLIST_FILE_EXTENSIONS = Arrays.asList("m3u"); private static final File DEFAULT_MUSIC_DIR = createDirectory("music"); + + public static File getAnySong(Context context) { + File dir = getMusicDirectory(context); + return getAnySong(context, dir); + } + private static File getAnySong(Context context, File dir) { + for(File file: dir.listFiles()) { + if(file.isDirectory()) { + return getAnySong(context, file); + } + + String extension = getExtension(file.getName()); + if(MUSIC_FILE_EXTENSIONS.contains(extension)) { + return file; + } + } + + return null; + } public static File getSongFile(Context context, MusicDirectory.Entry song) { File dir = getAlbumDirectory(context, song); -- cgit v1.2.3 From b5c7529ed34139e382376d090e9f933e2c3ede18 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 29 Apr 2013 07:38:45 -0700 Subject: Remove a bunch of changes that didn't help --- .../dsub/service/DownloadServiceImpl.java | 30 +--------------------- 1 file changed, 1 insertion(+), 29 deletions(-) (limited to 'subsonic-android') diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java index ed869daf..f6d3f769 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java @@ -89,7 +89,6 @@ public class DownloadServiceImpl extends Service implements DownloadService { private final IBinder binder = new SimpleServiceBinder(this); private Looper mediaPlayerLooper; - private MediaPlayer lpaPlayer; private MediaPlayer mediaPlayer; private MediaPlayer nextMediaPlayer; private boolean nextSetup = false; @@ -147,19 +146,6 @@ public class DownloadServiceImpl extends Service implements DownloadService { public void run() { Looper.prepare(); - // LPA Player on some devices causes weird issues, hold a default media player to mask them - try { - File randomSong = FileUtil.getAnySong(DownloadServiceImpl.this); - - lpaPlayer = new MediaPlayer(); - lpaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); - lpaPlayer.setDataSource(randomSong.getPath()); - lpaPlayer.prepareAsync(); - } catch(Exception e) { - // Failed to setup, ignore - Log.w(TAG, "Failed to setup redirect media player", e); - } - mediaPlayer = new MediaPlayer(); mediaPlayer.setWakeMode(DownloadServiceImpl.this, PowerManager.PARTIAL_WAKE_LOCK); @@ -235,7 +221,6 @@ public class DownloadServiceImpl extends Service implements DownloadService { i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName()); sendBroadcast(i); - lpaPlayer.release(); mediaPlayer.release(); if(nextMediaPlayer != null) { nextMediaPlayer.release(); @@ -885,34 +870,21 @@ public class DownloadServiceImpl extends Service implements DownloadService { private class PositionCache implements Runnable { boolean isRunning = true; - Thread thread; public void stop() { isRunning = false; - if(thread != null) { - // Make it stop right NOW - thread.interrupt(); - } } @Override public void run() { - thread = Thread.currentThread(); - int duration = currentPlaying.getSong().getDuration() == null ? mediaPlayer.getDuration() : currentPlaying.getSong().getDuration() * 1000; - cachedPosition = 0; // Stop checking position before the song reaches completion - while(isRunning && (Math.abs(duration - cachedPosition) > 1000)) { + while(isRunning) { try { if(mediaPlayer != null && playerState == STARTED) { cachedPosition = mediaPlayer.getCurrentPosition(); } Thread.sleep(200L); } - catch (InterruptedException e) { - // Purposely interrupted, don't log error - isRunning = false; - positionCache = null; - } catch(Exception e) { Log.w(TAG, "Crashed getting current position", e); isRunning = false; -- cgit v1.2.3 From 372feb754c4ac74d50383d926764b5b500acba26 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 1 May 2013 19:21:31 -0700 Subject: Added a setting for gapless playback --- subsonic-android/res/values/strings.xml | 2 ++ subsonic-android/res/xml/settings.xml | 6 ++++++ .../src/github/daneren2005/dsub/service/DownloadServiceImpl.java | 5 ++++- subsonic-android/src/github/daneren2005/dsub/util/Constants.java | 1 + 4 files changed, 13 insertions(+), 1 deletion(-) (limited to 'subsonic-android') diff --git a/subsonic-android/res/values/strings.xml b/subsonic-android/res/values/strings.xml index 839a3e49..90e455eb 100644 --- a/subsonic-android/res/values/strings.xml +++ b/subsonic-android/res/values/strings.xml @@ -266,6 +266,8 @@ Do Nothing Persistent Notification Show the notification even after pausing. Press the stop button to clear it away. + Gapless Playback + The Galaxy S3 seems to be experiencing freezes/other weird issue since the introduction of gapless playback. Turn this off to fix the issue. Start Year: End Year: diff --git a/subsonic-android/res/xml/settings.xml b/subsonic-android/res/xml/settings.xml index a2ae7b20..d21f928f 100644 --- a/subsonic-android/res/xml/settings.xml +++ b/subsonic-android/res/xml/settings.xml @@ -239,6 +239,12 @@ android:key="screenLitOnDownload" android:defaultValue="true"/> + + = Build.VERSION_CODES.JELLY_BEAN && (playerState == PlayerState.STARTED || playerState == PlayerState.PAUSED)) { + + SharedPreferences prefs = Util.getPreferences(DownloadServiceImpl.this); + boolean gaplessPlayback = prefs.getBoolean(Constants.PREFERENCES_KEY_GAPLESS_PLAYBACK, true); + if(gaplessPlayback && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && (playerState == PlayerState.STARTED || playerState == PlayerState.PAUSED)) { mediaPlayer.setNextMediaPlayer(nextMediaPlayer); nextSetup = true; } diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java index ae88a2ef..a35573a6 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java @@ -91,6 +91,7 @@ public final class Constants { public static final String PREFERENCES_EQUALIZER_ON = "equalizerOn"; public static final String PREFERENCES_EQUALIZER_SETTINGS = "equalizerSettings"; public static final String PREFERENCES_KEY_PERSISTENT_NOTIFICATION = "persistentNotification"; + public static final String PREFERENCES_KEY_GAPLESS_PLAYBACK = "gaplessPlayback"; // Name of the preferences file. public static final String PREFERENCES_FILE_NAME = "github.daneren2005.dsub_preferences"; -- cgit v1.2.3 From 442f5839a79f1c823445921b7e7f8f3c634dfd58 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 1 May 2013 20:22:29 -0700 Subject: Upped version to 3.8.4 --- subsonic-android/AndroidManifest.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'subsonic-android') diff --git a/subsonic-android/AndroidManifest.xml b/subsonic-android/AndroidManifest.xml index 7f29832e..18197d58 100644 --- a/subsonic-android/AndroidManifest.xml +++ b/subsonic-android/AndroidManifest.xml @@ -2,8 +2,8 @@ + android:versionCode="42" + android:versionName="3.8.4"> -- cgit v1.2.3