Fix notification sounds causing playback to start, fixed some CacheCleaner issues
This commit is contained in:
parent
6429559026
commit
32024ed1af
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
package="net.sourceforge.subsonic.androidapp"
|
||||
a:versionCode="56"
|
||||
a:versionName="3.9.9.15" a:installLocation="auto">
|
||||
a:versionCode="57"
|
||||
a:versionName="3.9.9.16" a:installLocation="auto">
|
||||
|
||||
<uses-permission a:name="android.permission.INTERNET"/>
|
||||
<uses-permission a:name="android.permission.READ_PHONE_STATE"/>
|
||||
|
@ -12,7 +12,7 @@
|
|||
<uses-permission a:name="android.permission.RECORD_AUDIO"/>
|
||||
<uses-permission a:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
|
||||
|
||||
<uses-sdk a:minSdkVersion="14" a:targetSdkVersion="16"/>
|
||||
<uses-sdk a:minSdkVersion="14" a:targetSdkVersion="17"/>
|
||||
|
||||
<supports-screens a:anyDensity="true" a:xlargeScreens="true" a:largeScreens="true" a:normalScreens="true" a:smallScreens="true"/>
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ package net.sourceforge.subsonic.androidapp.activity;
|
|||
import android.app.Activity;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
|
@ -37,7 +38,7 @@ import net.sourceforge.subsonic.androidapp.util.Util;
|
|||
* @author Sindre Mehus
|
||||
*/
|
||||
public final class HelpActivity extends Activity {
|
||||
|
||||
private static final String TAG = HelpActivity.class.getSimpleName();
|
||||
private WebView webView;
|
||||
private Button backButton;
|
||||
|
||||
|
@ -111,7 +112,7 @@ public final class HelpActivity extends Activity {
|
|||
try {
|
||||
versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
|
||||
} catch (NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, e.getMessage(), e);
|
||||
}
|
||||
|
||||
setTitle(view.getTitle() + " (" + versionName + ")");
|
||||
|
|
|
@ -36,6 +36,11 @@ public class MediaButtonIntentReceiver extends BroadcastReceiver {
|
|||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (Util.getMediaButtonsPreference(context)) {
|
||||
String intentAction = intent.getAction();
|
||||
|
||||
if (!Intent.ACTION_MEDIA_BUTTON.equals(intentAction))
|
||||
return;
|
||||
|
||||
KeyEvent event = (KeyEvent) intent.getExtras().get(Intent.EXTRA_KEY_EVENT);
|
||||
Log.i(TAG, "Got MEDIA_BUTTON key event: " + event);
|
||||
|
||||
|
|
|
@ -106,6 +106,8 @@ public class DownloadServiceImpl extends Service implements DownloadService {
|
|||
private boolean showVisualization;
|
||||
private boolean jukeboxEnabled;
|
||||
|
||||
private static MusicDirectory.Entry currentSong;
|
||||
|
||||
RemoteControlClientCompat remoteControlClientCompat;
|
||||
|
||||
static {
|
||||
|
@ -127,8 +129,12 @@ public class DownloadServiceImpl extends Service implements DownloadService {
|
|||
|
||||
private OnAudioFocusChangeListener _afChangeListener = new OnAudioFocusChangeListener() {
|
||||
public void onAudioFocusChange(int focusChange) {
|
||||
if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
|
||||
if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) {
|
||||
pause();
|
||||
} else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
|
||||
if (playerState == PlayerState.STARTED) {
|
||||
start();
|
||||
}
|
||||
} else if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
|
||||
stop();
|
||||
}
|
||||
|
@ -776,9 +782,10 @@ public class DownloadServiceImpl extends Service implements DownloadService {
|
|||
RemoteControlClient.FLAG_KEY_MEDIA_STOP);
|
||||
|
||||
try {
|
||||
if (currentPlaying != null) {
|
||||
if (currentSong != currentPlaying.getSong()) {
|
||||
currentSong = currentPlaying.getSong();
|
||||
|
||||
//String artist = currentPlaying.getSong().getArtist();
|
||||
//String album = currentPlaying.getSong().getAlbum();
|
||||
String album = currentPlaying.getSong().getAlbum();
|
||||
String title = currentPlaying.getSong().getArtist() + " - " + currentPlaying.getSong().getTitle();
|
||||
Integer duration = currentPlaying.getSong().getDuration();
|
||||
|
@ -789,16 +796,18 @@ public class DownloadServiceImpl extends Service implements DownloadService {
|
|||
Bitmap bitmap = musicService.getCoverArt(this, currentPlaying.getSong(), size, true, null);
|
||||
|
||||
// Update the remote controls
|
||||
remoteControlClientCompat.editMetadata(true)
|
||||
//.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, artist)
|
||||
remoteControlClientCompat
|
||||
.editMetadata(true)
|
||||
.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, title)
|
||||
.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, album)
|
||||
.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, duration)
|
||||
.putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, bitmap)
|
||||
.apply();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.e(TAG, "Exception in setRemoteControl");
|
||||
Log.e(TAG, "Exception in setRemoteControl", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import java.util.Set;
|
|||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.util.Log;
|
||||
import net.sourceforge.subsonic.androidapp.domain.Artist;
|
||||
import net.sourceforge.subsonic.androidapp.domain.Indexes;
|
||||
import net.sourceforge.subsonic.androidapp.domain.JukeboxStatus;
|
||||
|
@ -132,6 +133,7 @@ public class OfflineMusicService extends RESTMusicService {
|
|||
try {
|
||||
byte[] bytes = Util.toByteArray(in);
|
||||
Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
|
||||
Log.i("getCoverArt", "getCoverArt");
|
||||
return Bitmap.createScaledBitmap(bitmap, size, size, true);
|
||||
} finally {
|
||||
Util.close(in);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package net.sourceforge.subsonic.androidapp.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
@ -36,6 +37,7 @@ import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory;
|
|||
*/
|
||||
public class AlbumView extends LinearLayout {
|
||||
|
||||
private static final String TAG = AlbumView.class.getSimpleName();
|
||||
private TextView titleView;
|
||||
private TextView artistView;
|
||||
private View coverArtView;
|
||||
|
@ -83,7 +85,7 @@ public class AlbumView extends LinearLayout {
|
|||
musicService.unstar(id, getContext(), null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package net.sourceforge.subsonic.androidapp.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
@ -32,7 +35,8 @@ public class CacheCleaner {
|
|||
}
|
||||
|
||||
public void clean() {
|
||||
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
Log.i(TAG, "Starting cache cleaning.");
|
||||
|
||||
if (downloadService == null) {
|
||||
|
@ -41,7 +45,6 @@ public class CacheCleaner {
|
|||
}
|
||||
|
||||
try {
|
||||
|
||||
List<File> files = new ArrayList<File>();
|
||||
List<File> dirs = new ArrayList<File>();
|
||||
|
||||
|
@ -58,6 +61,8 @@ public class CacheCleaner {
|
|||
Log.e(TAG, "Error in cache cleaning.", x);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void deleteEmptyDirs(List<File> dirs, Set<File> undeletable) {
|
||||
for (File dir : dirs) {
|
||||
|
@ -68,7 +73,7 @@ public class CacheCleaner {
|
|||
File[] children = dir.listFiles();
|
||||
|
||||
// Delete empty directory and associated album artwork.
|
||||
if (children.length == 0) {
|
||||
if (children != null && children.length == 0) {
|
||||
Util.delete(dir);
|
||||
Util.delete(FileUtil.getAlbumArtFile(dir));
|
||||
}
|
||||
|
@ -88,7 +93,11 @@ public class CacheCleaner {
|
|||
bytesUsedBySubsonic += file.length();
|
||||
}
|
||||
|
||||
long bytesToDelete = 0;
|
||||
|
||||
// Ensure that file system is not more than 95% full.
|
||||
try
|
||||
{
|
||||
StatFs stat = new StatFs(files.get(0).getPath());
|
||||
long bytesTotalFs = (long) stat.getBlockCount() * (long) stat.getBlockSize();
|
||||
long bytesAvailableFs = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
|
||||
|
@ -97,16 +106,18 @@ public class CacheCleaner {
|
|||
|
||||
long bytesToDeleteCacheLimit = Math.max(bytesUsedBySubsonic - cacheSizeBytes, 0L);
|
||||
long bytesToDeleteFsLimit = Math.max(bytesUsedFs - minFsAvailability, 0L);
|
||||
long bytesToDelete = Math.max(bytesToDeleteCacheLimit, bytesToDeleteFsLimit);
|
||||
bytesToDelete = Math.max(bytesToDeleteCacheLimit, bytesToDeleteFsLimit);
|
||||
|
||||
Log.i(TAG, "File system : " + Util.formatBytes(bytesAvailableFs) + " of " + Util.formatBytes(bytesTotalFs) + " available");
|
||||
Log.i(TAG, "Cache limit : " + Util.formatBytes(cacheSizeBytes));
|
||||
Log.i(TAG, "Cache size before : " + Util.formatBytes(bytesUsedBySubsonic));
|
||||
Log.i(TAG, "Minimum to delete : " + Util.formatBytes(bytesToDelete));
|
||||
} catch (Exception x) {
|
||||
//
|
||||
}
|
||||
|
||||
long bytesDeleted = 0L;
|
||||
for (File file : files) {
|
||||
|
||||
if (file.getName().equals(Constants.ALBUM_ART_FILE)) {
|
||||
// Move artwork to new folder.
|
||||
file.renameTo(FileUtil.getAlbumArtFile(file.getParentFile()));
|
||||
|
|
|
@ -86,6 +86,7 @@ public class FileUtil {
|
|||
File albumArtFile = getAlbumArtFile(context, entry);
|
||||
if (albumArtFile.exists()) {
|
||||
Bitmap bitmap = BitmapFactory.decodeFile(albumArtFile.getPath());
|
||||
Log.i("getAlbumArtBitmap", String.valueOf(size));
|
||||
return bitmap == null ? null : Bitmap.createScaledBitmap(bitmap, size, size, true);
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -81,7 +81,9 @@ public class ImageLoader implements Runnable {
|
|||
|
||||
private void createLargeUnknownImage(Context context) {
|
||||
BitmapDrawable drawable = (BitmapDrawable) context.getResources().getDrawable(R.drawable.unknown_album_large);
|
||||
Log.i(TAG, "createLargeUnknownImage");
|
||||
Bitmap bitmap = Bitmap.createScaledBitmap(drawable.getBitmap(), imageSizeLarge, imageSizeLarge, true);
|
||||
|
||||
//bitmap = createReflection(bitmap);
|
||||
largeUnknownImage = Util.createDrawableFromBitmap(context, bitmap);
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ public class SongView extends LinearLayout implements Checkable {
|
|||
musicService.unstar(id, getContext(), null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
|
|
|
@ -100,6 +100,8 @@ public class Util extends DownloadActivity {
|
|||
private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
private static Toast toast;
|
||||
|
||||
private static MusicDirectory.Entry currentSong;
|
||||
|
||||
private Util() {
|
||||
}
|
||||
|
||||
|
@ -580,6 +582,9 @@ public class Util extends DownloadActivity {
|
|||
|
||||
public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService, Handler handler, MusicDirectory.Entry song, final Notification notification, PlayerState playerState) {
|
||||
|
||||
if (currentSong != song) {
|
||||
currentSong = song;
|
||||
|
||||
// Use the same text for the ticker and the expanded notification
|
||||
String title = song.getTitle();
|
||||
String text = song.getArtist();
|
||||
|
@ -604,6 +609,7 @@ public class Util extends DownloadActivity {
|
|||
notification.contentView.setTextViewText(R.id.trackname, title);
|
||||
notification.contentView.setTextViewText(R.id.artist, text);
|
||||
notification.contentView.setTextViewText(R.id.album, album);
|
||||
}
|
||||
|
||||
if (playerState == PlayerState.PAUSED) {
|
||||
notification.contentView.setImageViewResource(R.id.control_play, R.drawable.ic_appwidget_music_play);
|
||||
|
@ -626,8 +632,10 @@ public class Util extends DownloadActivity {
|
|||
|
||||
public static void hidePlayingNotification(final Context context, final DownloadServiceImpl downloadService, Handler handler) {
|
||||
|
||||
currentSong = null;
|
||||
|
||||
// Remove notification and remove the service from the foreground
|
||||
handler.post(new Runnable() {
|
||||
handler.post(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
stopForeground(downloadService, true);
|
||||
|
|
Loading…
Reference in New Issue