diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-02-18 17:16:19 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-02-18 17:16:19 -0800 |
commit | f7d18d5c3baac88c6dc4d506c684c0d7d67b045d (patch) | |
tree | 486479b13ddba54b285dfb97c877add5a4043c19 | |
parent | 468f93a1be94c78d6793a1504c61ec8c939b356f (diff) | |
parent | e4ce03c6f1c3fb5ec48fcefbf814d83a1d5090f4 (diff) | |
download | dsub-f7d18d5c3baac88c6dc4d506c684c0d7d67b045d.tar.gz dsub-f7d18d5c3baac88c6dc4d506c684c0d7d67b045d.tar.bz2 dsub-f7d18d5c3baac88c6dc4d506c684c0d7d67b045d.zip |
Merge commit 'e4ce03c6f1c3fb5ec48fcefbf814d83a1d5090f4' into Experimental
19 files changed, 304 insertions, 73 deletions
@@ -1,4 +1,6 @@ -subsonic-android/.classpath -subsonic-android/.project -subsonic-android/bin/* -subsonic-android/gen/*
\ No newline at end of file +subsonic-android/.classpath
+subsonic-android/.project
+subsonic-android/bin/*
+subsonic-android/gen/*
+/subsonic-android/libs/ActionBarSherlock/gen/
+/subsonic-android/private/*
\ No newline at end of file diff --git a/.gitmodules b/.gitmodules index 0303afcf..1d77a2e9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "ActionBarSherlock"] path = ActionBarSherlock - url = https://github.com/JakeWharton/ActionBarSherlock.git + url = https://github.com/JakeWharton/ActionBarSherlock.git
+[submodule "DragSortListView"] + path = DragSortListView + url = https://github.com/bauerca/drag-sort-listview.git @@ -1,3 +1,13 @@ +Basic Instructions +Run these commands to grab dependent libraries: +git submodule init +git submodule update + +Go to both ActionBarSherlock/library and DragSortListView/library and build project files with: +android update project --path ./ + + + Roadmap of major planned features in rough order that I plan to work on them in (little features get sprinkled in wherever): Gapless Playback (may not be possible to get perfect) diff --git a/subsonic-android/AndroidManifest.xml b/subsonic-android/AndroidManifest.xml index 44609b37..5ca6cf49 100644 --- a/subsonic-android/AndroidManifest.xml +++ b/subsonic-android/AndroidManifest.xml @@ -3,7 +3,7 @@ package="github.daneren2005.dsub"
android:installLocation="internalOnly"
android:versionCode="36"
- android:versionName="3.7.3">
+ android:versionName="3.7.4">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
diff --git a/subsonic-android/project.properties b/subsonic-android/project.properties index 9b3b31a8..cd253d77 100644 --- a/subsonic-android/project.properties +++ b/subsonic-android/project.properties @@ -9,4 +9,5 @@ # Project target. target=android-16 -android.library.reference.1=../../ActionBarSherlock +android.library.reference.1=../ActionBarSherlock/library +android.library.reference.2=../DragSortListView/library
\ No newline at end of file diff --git a/subsonic-android/res/layout-land/download.xml b/subsonic-android/res/layout-land/download.xml index 431fef96..4992d169 100644 --- a/subsonic-android/res/layout-land/download.xml +++ b/subsonic-android/res/layout-land/download.xml @@ -53,7 +53,6 @@ android:text="EQ"
android:textStyle="bold"
android:textSize="22sp"
- android:visibility="gone"
android:background="@android:color/transparent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -76,7 +75,6 @@ android:text="VIS"
android:textStyle="bold"
android:textSize="22sp"
- android:visibility="gone"
android:background="@android:color/transparent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
diff --git a/subsonic-android/res/menu/empty.xml b/subsonic-android/res/menu/empty.xml index 9096a727..b6db96aa 100644 --- a/subsonic-android/res/menu/empty.xml +++ b/subsonic-android/res/menu/empty.xml @@ -1,4 +1,8 @@ <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> - + <item + android:id="@+id/menu_refresh" + android:icon="@drawable/action_refresh" + android:title="@string/menu.refresh" + android:showAsAction="always|withText"/> </menu> diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java index dc70d4b8..a4222ce5 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java @@ -87,8 +87,8 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi private static final int DIALOG_SAVE_PLAYLIST = 100; private static final int PERCENTAGE_OF_SCREEN_FOR_SWIPE = 5; - private static final int COLOR_BUTTON_ENABLED = Color.rgb(129, 201, 54); - private static final int COLOR_BUTTON_DISABLED = Color.rgb(164, 166, 158); + private static final int COLOR_BUTTON_ENABLED = Color.rgb(51, 181, 229); + private static final int COLOR_BUTTON_DISABLED = Color.rgb(206, 213, 211); private static final int INCREMENT_TIME = 5000; private ViewFlipper playlistFlipper; @@ -275,8 +275,14 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi equalizerButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - startActivity(new Intent(DownloadActivity.this, EqualizerActivity.class)); - setControlsVisible(true); + DownloadService downloadService = getDownloadService(); + if(downloadService != null && downloadService.getEqualizerController() != null + && downloadService.getEqualizerController().getEqualizer() != null) { + startActivity(new Intent(DownloadActivity.this, EqualizerActivity.class)); + setControlsVisible(true); + } else { + Util.toast(DownloadActivity.this, "Failed to start equalizer. Try restarting."); + } } }); @@ -285,9 +291,14 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi public void onClick(View view) { boolean active = !visualizerView.isActive(); visualizerView.setActive(active); - getDownloadService().setShowVisualization(visualizerView.isActive()); + boolean isActive = visualizerView.isActive(); + getDownloadService().setShowVisualization(isActive); updateButtons(); - Util.toast(DownloadActivity.this, active ? R.string.download_visualizer_on : R.string.download_visualizer_off); + if(active == isActive) { + Util.toast(DownloadActivity.this, active ? R.string.download_visualizer_on : R.string.download_visualizer_off); + } else { + Util.toast(DownloadActivity.this, "Failed to start visualizer. Try restarting."); + } setControlsVisible(true); } }); @@ -343,8 +354,8 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi downloadService.setShufflePlayEnabled(true); } - boolean visualizerAvailable = downloadService != null && downloadService.getVisualizerController() != null; - boolean equalizerAvailable = downloadService != null && downloadService.getEqualizerController() != null; + boolean visualizerAvailable = downloadService != null && downloadService.getVisualizerAvailable(); + boolean equalizerAvailable = downloadService != null && downloadService.getEqualizerAvailable(); if (!equalizerAvailable) { equalizerButton.setVisibility(View.GONE); @@ -400,8 +411,8 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } - if (visualizerView != null) { - visualizerView.setActive(downloadService != null && downloadService.getShowVisualization()); + if (visualizerView != null && downloadService != null && downloadService.getShowVisualization()) { + visualizerView.setActive(true); } updateButtons(); @@ -441,10 +452,15 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi } private void updateButtons() { - boolean eqEnabled = getDownloadService() != null && getDownloadService().getEqualizerController() != null && - getDownloadService().getEqualizerController().isEnabled(); - equalizerButton.setTextColor(eqEnabled ? COLOR_BUTTON_ENABLED : COLOR_BUTTON_DISABLED); - + SharedPreferences prefs = Util.getPreferences(DownloadActivity.this); + boolean equalizerOn = prefs.getBoolean(Constants.PREFERENCES_EQUALIZER_ON, false); + if(equalizerOn && getDownloadService() != null && getDownloadService().getEqualizerController() != null && + getDownloadService().getEqualizerController().isEnabled()) { + equalizerButton.setTextColor(COLOR_BUTTON_ENABLED); + } else { + equalizerButton.setTextColor(COLOR_BUTTON_DISABLED); + } + if (visualizerView != null) { visualizerButton.setTextColor(visualizerView.isActive() ? COLOR_BUTTON_ENABLED : COLOR_BUTTON_DISABLED); } diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/EqualizerActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/EqualizerActivity.java index 9906673a..e5de3858 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/EqualizerActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/EqualizerActivity.java @@ -22,8 +22,10 @@ import java.util.HashMap; import java.util.Map; import android.app.Activity; +import android.content.SharedPreferences; import android.media.audiofx.Equalizer; import android.os.Bundle; +import android.util.Log; import android.view.ContextMenu; import android.view.LayoutInflater; import android.view.MenuItem; @@ -36,6 +38,8 @@ import android.widget.TextView; import github.daneren2005.dsub.R; import github.daneren2005.dsub.audiofx.EqualizerController; import github.daneren2005.dsub.service.DownloadServiceImpl; +import github.daneren2005.dsub.util.Constants; +import github.daneren2005.dsub.util.Util; /** * Equalizer controls. @@ -44,12 +48,14 @@ import github.daneren2005.dsub.service.DownloadServiceImpl; * @version $Id$ */ public class EqualizerActivity extends Activity { + private static final String TAG = EqualizerActivity.class.getSimpleName(); private static final int MENU_GROUP_PRESET = 100; private final Map<Short, SeekBar> bars = new HashMap<Short, SeekBar>(); private EqualizerController equalizerController; private Equalizer equalizer; + private short masterLevel = 0; @Override public void onCreate(Bundle bundle) { @@ -83,6 +89,17 @@ public class EqualizerActivity extends Activity { protected void onPause() { super.onPause(); equalizerController.saveSettings(); + + if(!equalizer.getEnabled()) { + equalizerController.release(); + } + } + + @Override + protected void onResume() { + super.onResume(); + equalizerController = DownloadServiceImpl.getInstance().getEqualizerController(); + equalizer = equalizerController.getEqualizer(); } @Override @@ -109,24 +126,46 @@ public class EqualizerActivity extends Activity { public boolean onContextItemSelected(MenuItem menuItem) { short preset = (short) menuItem.getItemId(); equalizer.usePreset(preset); - updateBars(); + updateBars(false); return true; } private void setEqualizerEnabled(boolean enabled) { + SharedPreferences prefs = Util.getPreferences(EqualizerActivity.this); + SharedPreferences.Editor editor = prefs.edit(); + editor.putBoolean(Constants.PREFERENCES_EQUALIZER_ON, enabled); + editor.commit(); equalizer.setEnabled(enabled); - updateBars(); + updateBars(true); } - private void updateBars() { - + private void updateBars(boolean changedEnabled) { + boolean isEnabled = equalizer.getEnabled(); + short minEQLevel = equalizer.getBandLevelRange()[0]; for (Map.Entry<Short, SeekBar> entry : bars.entrySet()) { short band = entry.getKey(); SeekBar bar = entry.getValue(); - bar.setEnabled(equalizer.getEnabled()); - short minEQLevel = equalizer.getBandLevelRange()[0]; - bar.setProgress(equalizer.getBandLevel(band) - minEQLevel); + bar.setEnabled(isEnabled); + if(band >= (short)0) { + if(changedEnabled) { + equalizer.setBandLevel(band, (short)(equalizer.getBandLevel(band) - masterLevel)); + bar.setProgress(equalizer.getBandLevel(band) - minEQLevel); + } else { + bar.setProgress(equalizer.getBandLevel(band) - minEQLevel); + equalizer.setBandLevel(band, (short)(equalizer.getBandLevel(band) + masterLevel)); + } + } else if(!isEnabled) { + bar.setProgress(-minEQLevel); + } } + + if(!isEnabled) { + masterLevel = 0; + SharedPreferences prefs = Util.getPreferences(EqualizerActivity.this); + SharedPreferences.Editor editor = prefs.edit(); + editor.putInt(Constants.PREFERENCES_EQUALIZER_SETTINGS, masterLevel); + editor.commit(); + } } private void initEqualizer() { @@ -134,6 +173,11 @@ public class EqualizerActivity extends Activity { final short minEQLevel = equalizer.getBandLevelRange()[0]; final short maxEQLevel = equalizer.getBandLevelRange()[1]; + + // Setup Pregain + SharedPreferences prefs = Util.getPreferences(this); + masterLevel = (short)prefs.getInt(Constants.PREFERENCES_EQUALIZER_SETTINGS, 0); + initPregain(layout, minEQLevel, maxEQLevel); for (short i = 0; i < equalizer.getNumberOfBands(); i++) { final short band = i; @@ -148,6 +192,9 @@ public class EqualizerActivity extends Activity { bars.put(band, bar); bar.setMax(maxEQLevel - minEQLevel); short level = equalizer.getBandLevel(band); + if(equalizer.getEnabled()) { + level = (short) (level - masterLevel); + } bar.setProgress(level - minEQLevel); bar.setEnabled(equalizer.getEnabled()); updateLevelText(levelTextView, level); @@ -157,7 +204,7 @@ public class EqualizerActivity extends Activity { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { short level = (short) (progress + minEQLevel); if (fromUser) { - equalizer.setBandLevel(band, level); + equalizer.setBandLevel(band, (short)(level + masterLevel)); } updateLevelText(levelTextView, level); } @@ -173,6 +220,48 @@ public class EqualizerActivity extends Activity { layout.addView(bandBar); } } + + private void initPregain(LinearLayout layout, final short minEQLevel, final short maxEQLevel) { + View bandBar = LayoutInflater.from(this).inflate(R.layout.equalizer_bar, null); + TextView freqTextView = (TextView) bandBar.findViewById(R.id.equalizer_frequency); + final TextView levelTextView = (TextView) bandBar.findViewById(R.id.equalizer_level); + SeekBar bar = (SeekBar) bandBar.findViewById(R.id.equalizer_bar); + + freqTextView.setText("Master"); + + bars.put((short)-1, bar); + bar.setMax(maxEQLevel - minEQLevel); + bar.setProgress(masterLevel - minEQLevel); + bar.setEnabled(equalizer.getEnabled()); + updateLevelText(levelTextView, masterLevel); + + bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + masterLevel = (short) (progress + minEQLevel); + if (fromUser) { + SharedPreferences prefs = Util.getPreferences(EqualizerActivity.this); + SharedPreferences.Editor editor = prefs.edit(); + editor.putInt(Constants.PREFERENCES_EQUALIZER_SETTINGS, masterLevel); + editor.commit(); + for (short i = 0; i < equalizer.getNumberOfBands(); i++) { + short level = (short) ((bars.get(i).getProgress() + minEQLevel) + masterLevel); + equalizer.setBandLevel(i, level); + } + } + updateLevelText(levelTextView, masterLevel); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + } + }); + layout.addView(bandBar); + } private void updateLevelText(TextView levelTextView, short level) { levelTextView.setText((level > 0 ? "+" : "") + level / 100 + " dB"); diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java index d2c61b59..938bf624 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java @@ -31,6 +31,7 @@ import android.content.Intent; import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.media.AudioManager;
+import android.media.MediaMetadataRetriever;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
@@ -504,24 +505,61 @@ public class SubsonicTabActivity extends SherlockActivity { }
public void displaySongInfo(final MusicDirectory.Entry song) {
+ Integer bitrate = null;
+ String format = null;
+ long size = 0;
+ try {
+ DownloadFile downloadFile = new DownloadFile(SubsonicTabActivity.this, song, false);
+ File file = downloadFile.getCompleteFile();
+ if(file.exists()) {
+ MediaMetadataRetriever metadata = new MediaMetadataRetriever();
+ metadata.setDataSource(file.getAbsolutePath());
+ String tmp = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE);
+ bitrate = Integer.parseInt((tmp != null) ? tmp : "0") / 1000;
+ format = FileUtil.getExtension(file.getName());
+ size = file.length();
+
+ if(Util.isOffline(SubsonicTabActivity.this)) {
+ song.setGenre(metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE));
+ String year = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR);
+ song.setYear(Integer.parseInt((year != null) ? year : "0"));
+ }
+ }
+ } catch(Exception e) {
+ Log.i(TAG, "Device doesn't properly support MediaMetadataRetreiver");
+ }
+
String msg = "";
if(!song.isVideo()) {
msg += "Artist: " + song.getArtist() + "\nAlbum: " + song.getAlbum();
}
+ if(song.getTrack() != null && song.getTrack() != 0) {
+ msg += "\nTrack: " + song.getTrack();
+ }
if(song.getGenre() != null && !"".equals(song.getGenre())) {
msg += "\nGenre: " + song.getGenre();
}
if(song.getYear() != null && song.getYear() != 0) {
msg += "\nYear: " + song.getYear();
}
- msg += "\nFormat: " + song.getSuffix();
- if(song.getBitRate() != null && song.getBitRate() != 0) {
- msg += "\nBitrate: " + song.getBitRate() + " kpbs";
+ if(!Util.isOffline(SubsonicTabActivity.this)) {
+ msg += "\nServer Format: " + song.getSuffix();
+ if(song.getBitRate() != null && song.getBitRate() != 0) {
+ msg += "\nServer Bitrate: " + song.getBitRate() + " kpbs";
+ }
+ }
+ if(format != null && !"".equals(format)) {
+ msg += "\nCached Format: " + format;
+ }
+ if(bitrate != null && bitrate != 0) {
+ msg += "\nCached Bitrate: " + bitrate + " kpbs";
+ }
+ if(size != 0) {
+ msg += "\nSize: " + Util.formatBytes(size);
}
if(song.getDuration() != null && song.getDuration() != 0) {
msg += "\nLength: " + Util.formatDuration(song.getDuration());
}
- msg += "\nSize: " + Util.formatBytes(song.getSize());
new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_alert)
diff --git a/subsonic-android/src/github/daneren2005/dsub/audiofx/EqualizerController.java b/subsonic-android/src/github/daneren2005/dsub/audiofx/EqualizerController.java index f16ff968..0dcee863 100644 --- a/subsonic-android/src/github/daneren2005/dsub/audiofx/EqualizerController.java +++ b/subsonic-android/src/github/daneren2005/dsub/audiofx/EqualizerController.java @@ -38,6 +38,8 @@ public class EqualizerController { private final Context context; private Equalizer equalizer; + private boolean released = false; + private int audioSessionId = 0; // Class initialization fails when this throws an exception. static { @@ -58,7 +60,8 @@ public class EqualizerController { public EqualizerController(Context context, MediaPlayer mediaPlayer) { this.context = context; try { - equalizer = new Equalizer(0, mediaPlayer.getAudioSessionId()); + audioSessionId = mediaPlayer.getAudioSessionId(); + equalizer = new Equalizer(0, audioSessionId); } catch (Throwable x) { Log.w(TAG, "Failed to create equalizer.", x); } @@ -97,11 +100,21 @@ public class EqualizerController { public void release() { if (isAvailable()) { + released = true; equalizer.release(); } } public Equalizer getEqualizer() { + if(released) { + released = false; + try { + equalizer = new Equalizer(0, audioSessionId); + } catch (Throwable x) { + equalizer = null; + Log.w(TAG, "Failed to create equalizer.", x); + } + } return equalizer; } diff --git a/subsonic-android/src/github/daneren2005/dsub/audiofx/VisualizerController.java b/subsonic-android/src/github/daneren2005/dsub/audiofx/VisualizerController.java index 184aeb51..b32245f4 100644 --- a/subsonic-android/src/github/daneren2005/dsub/audiofx/VisualizerController.java +++ b/subsonic-android/src/github/daneren2005/dsub/audiofx/VisualizerController.java @@ -36,6 +36,8 @@ public class VisualizerController { private final Context context; private Visualizer visualizer; + private boolean released = false; + private int audioSessionId = 0; // Class initialization fails when this throws an exception. static { @@ -56,7 +58,8 @@ public class VisualizerController { public VisualizerController(Context context, MediaPlayer mediaPlayer) { this.context = context; try { - visualizer = new Visualizer(mediaPlayer.getAudioSessionId()); + audioSessionId = mediaPlayer.getAudioSessionId(); + visualizer = new Visualizer(audioSessionId); } catch (Throwable x) { Log.w(TAG, "Failed to create visualizer.", x); } @@ -80,10 +83,21 @@ public class VisualizerController { public void release() { if (isAvailable()) { visualizer.release(); + released = true; } } public Visualizer getVisualizer() { + if(released) { + released = false; + try { + visualizer = new Visualizer(audioSessionId); + } catch (Throwable x) { + visualizer = null; + Log.w(TAG, "Failed to create visualizer.", x); + } + } + return visualizer; } } diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java index 663a6e6c..0536c198 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java @@ -106,6 +106,10 @@ public interface DownloadService { void setSuggestedPlaylistName(String name); String getSuggestedPlaylistName(); + + boolean getEqualizerAvailable(); + + boolean getVisualizerAvailable(); EqualizerController getEqualizerController(); diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java index ee2de43a..ba4f4bfe 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java @@ -173,21 +173,6 @@ public class DownloadServiceImpl extends Service implements DownloadService { mRemoteControl.register(this, mediaButtonReceiverComponent); } - if (equalizerAvailable) { - equalizerController = new EqualizerController(this, mediaPlayer); - if (!equalizerController.isAvailable()) { - equalizerController = null; - } else { - equalizerController.loadSettings(); - } - } - if (visualizerAvailable) { - visualizerController = new VisualizerController(this, mediaPlayer); - if (!visualizerController.isAvailable()) { - visualizerController = null; - } - } - PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName()); wakeLock.setReferenceCounted(false); @@ -204,6 +189,10 @@ public class DownloadServiceImpl extends Service implements DownloadService { instance = this; lifecycleSupport.onCreate(); + + if(prefs.getBoolean(Constants.PREFERENCES_EQUALIZER_ON, false)) { + getEqualizerController(); + } } @Override @@ -793,7 +782,6 @@ public class DownloadServiceImpl extends Service implements DownloadService { if(mediaPlayer != null && getPlayerState() == STARTED) { try { cachedPosition = mediaPlayer.getCurrentPosition(); - Util.broadcastNewTrackInfo(DownloadServiceImpl.this, currentPlaying.getSong()); } catch(Exception e) { executorService.shutdown(); } @@ -825,14 +813,38 @@ public class DownloadServiceImpl extends Service implements DownloadService { public String getSuggestedPlaylistName() { return suggestedPlaylistName; } + + @Override + public boolean getEqualizerAvailable() { + return equalizerAvailable; + } + + @Override + public boolean getVisualizerAvailable() { + return visualizerAvailable; + } @Override public EqualizerController getEqualizerController() { + if (equalizerAvailable && equalizerController == null) { + equalizerController = new EqualizerController(this, mediaPlayer); + if (!equalizerController.isAvailable()) { + equalizerController = null; + } else { + equalizerController.loadSettings(); + } + } return equalizerController; } @Override public VisualizerController getVisualizerController() { + if (visualizerAvailable && visualizerController == null) { + visualizerController = new VisualizerController(this, mediaPlayer); + if (!visualizerController.isAvailable()) { + visualizerController = null; + } + } return visualizerController; } diff --git a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java index b4c48bde..4fbbaf2d 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java @@ -148,25 +148,23 @@ public class OfflineMusicService extends RESTMusicService { entry.setSize(file.length()); String root = FileUtil.getMusicDirectory(context).getPath(); entry.setPath(file.getPath().replaceFirst("^" + root + "/" , "")); + String title = name; if (file.isFile()) { entry.setArtist(file.getParentFile().getParentFile().getName()); entry.setAlbum(file.getParentFile().getName()); - try { - MediaMetadataRetriever metadata = new MediaMetadataRetriever(); - metadata.setDataSource(file.getAbsolutePath()); - entry.setGenre(metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE)); - String bitrate = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE); - entry.setBitRate(Integer.parseInt((bitrate != null) ? bitrate : "0") / 1000); - String year = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR); - entry.setYear(Integer.parseInt((year != null) ? year : "0")); - String length = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); - entry.setDuration(Integer.parseInt(length) / 1000); - } catch(Exception e) { - Log.i(TAG, "Device doesn't properly support MediaMetadataRetreiver"); + int index = name.indexOf('-'); + if(index != -1) { + try { + entry.setTrack(Integer.parseInt(name.substring(0, index))); + title = title.substring(index + 1); + } catch(Exception e) { + // Failed parseInt, just means track filled out + } } } - entry.setTitle(name); + + entry.setTitle(title); entry.setSuffix(FileUtil.getExtension(file.getName().replace(".complete", ""))); File albumArt = FileUtil.getAlbumArtFile(context, entry); diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java index c116c484..3ee7d7e8 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java @@ -88,6 +88,8 @@ public final class Constants { public static final String PREFERENCES_KEY_SHUFFLE_GENRE = "genre"; public static final String PREFERENCES_KEY_KEEP_SCREEN_ON = "keepScreenOn"; public static final String PREFERENCES_KEY_BUFFER_LENGTH = "bufferLength"; + public static final String PREFERENCES_EQUALIZER_ON = "equalizerOn"; + public static final String PREFERENCES_EQUALIZER_SETTINGS = "equalizerSettings"; // Name of the preferences file. public static final String PREFERENCES_FILE_NAME = "github.daneren2005.dsub_preferences"; diff --git a/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java b/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java index 9586e24d..35e24039 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java @@ -64,7 +64,7 @@ public class ImageLoader implements Runnable { public ImageLoader(Context context) { this.context = context; final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); - final int cacheSize = maxMemory / 4; + final int cacheSize = maxMemory / 2; cache = new LruCache<String, Bitmap>(cacheSize) { @Override protected int sizeOf(String key, Bitmap bitmap) { diff --git a/subsonic-android/src/github/daneren2005/dsub/view/SongView.java b/subsonic-android/src/github/daneren2005/dsub/view/SongView.java index 1042546a..7cefae23 100644 --- a/subsonic-android/src/github/daneren2005/dsub/view/SongView.java +++ b/subsonic-android/src/github/daneren2005/dsub/view/SongView.java @@ -19,6 +19,8 @@ package github.daneren2005.dsub.view; import android.content.Context; +import android.media.MediaMetadataRetriever; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.widget.*; @@ -40,6 +42,7 @@ import java.io.File; public class SongView extends UpdateView implements Checkable { private static final String TAG = SongView.class.getSimpleName(); + private Context context; private MusicDirectory.Entry song; private CheckedTextView checkedTextView; @@ -52,6 +55,7 @@ public class SongView extends UpdateView implements Checkable { public SongView(Context context) { super(context); + this.context = context; LayoutInflater.from(context).inflate(R.layout.song_list_item, this, true); checkedTextView = (CheckedTextView) findViewById(R.id.song_check); @@ -64,6 +68,24 @@ public class SongView extends UpdateView implements Checkable { public void setSong(MusicDirectory.Entry song, boolean checkable) { this.song = song; + + if(Util.isOffline(context)) { + DownloadFile downloadFile = new DownloadFile(context, song, false); + File file = downloadFile.getCompleteFile(); + if(file.exists()) { + try { + MediaMetadataRetriever metadata = new MediaMetadataRetriever(); + metadata.setDataSource(file.getAbsolutePath()); + String bitrate = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE); + song.setBitRate(Integer.parseInt((bitrate != null) ? bitrate : "0") / 1000); + String length = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); + song.setDuration(Integer.parseInt(length) / 1000); + } catch(Exception e) { + Log.i(TAG, "Device doesn't properly support MediaMetadataRetreiver"); + } + } + } + StringBuilder artist = new StringBuilder(40); String bitRate = null; diff --git a/subsonic-android/src/github/daneren2005/dsub/view/VisualizerView.java b/subsonic-android/src/github/daneren2005/dsub/view/VisualizerView.java index 9bff3a2d..53ebc2ec 100644 --- a/subsonic-android/src/github/daneren2005/dsub/view/VisualizerView.java +++ b/subsonic-android/src/github/daneren2005/dsub/view/VisualizerView.java @@ -45,14 +45,14 @@ public class VisualizerView extends View { private byte[] data; private float[] points; - private boolean active; + private boolean active = false; public VisualizerView(Context context) { super(context); paint.setStrokeWidth(2f); paint.setAntiAlias(true); - paint.setColor(Color.rgb(129, 201, 54)); + paint.setColor(Color.rgb(51, 181, 229)); } public boolean isActive() { @@ -61,8 +61,10 @@ public class VisualizerView extends View { public void setActive(boolean active) { this.active = active; - Visualizer visualizer = getVizualiser(); + VisualizerController visualizerController = getVizualiser(); + Visualizer visualizer = visualizerController == null ? null : visualizerController.getVisualizer(); if (visualizer == null) { + this.active = false; return; } @@ -83,13 +85,16 @@ public class VisualizerView extends View { } visualizer.setEnabled(active); + if(!active) { + visualizerController.release(); + } invalidate(); } - private Visualizer getVizualiser() { + private VisualizerController getVizualiser() { DownloadService downloadService = DownloadServiceImpl.getInstance(); VisualizerController visualizerController = downloadService == null ? null : downloadService.getVisualizerController(); - return visualizerController == null ? null : visualizerController.getVisualizer(); + return visualizerController; } private void updateVisualizer(byte[] waveform) { |