ignore sort preference if query already has sort method applied
This commit is contained in:
parent
a0dc794755
commit
569813ae73
5 changed files with 22 additions and 56 deletions
|
|
@ -1,10 +1,8 @@
|
||||||
package com.dkanada.gramophone.service;
|
package com.dkanada.gramophone.service;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.media.MediaPlayer;
|
import android.media.MediaPlayer;
|
||||||
import android.media.audiofx.AudioEffect;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
@ -34,12 +32,6 @@ public class MultiPlayer implements Playback, MediaPlayer.OnErrorListener, Media
|
||||||
mCurrentMediaPlayer.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK);
|
mCurrentMediaPlayer.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param path The path of the file, or the http/rtsp URL of the stream
|
|
||||||
* you want to play
|
|
||||||
* @return True if the <code>player</code> has been prepared and is
|
|
||||||
* ready to play, false otherwise
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setDataSource(@NonNull final String path) {
|
public boolean setDataSource(@NonNull final String path) {
|
||||||
mIsInitialized = false;
|
mIsInitialized = false;
|
||||||
|
|
@ -51,13 +43,6 @@ public class MultiPlayer implements Playback, MediaPlayer.OnErrorListener, Media
|
||||||
return mIsInitialized;
|
return mIsInitialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param player The {@link MediaPlayer} to use
|
|
||||||
* @param path The path of the file, or the http/rtsp URL of the stream
|
|
||||||
* you want to play
|
|
||||||
* @return True if the <code>player</code> has been prepared and is
|
|
||||||
* ready to play, false otherwise
|
|
||||||
*/
|
|
||||||
private boolean setDataSourceImpl(@NonNull final MediaPlayer player, @NonNull final String path) {
|
private boolean setDataSourceImpl(@NonNull final MediaPlayer player, @NonNull final String path) {
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -81,21 +66,9 @@ public class MultiPlayer implements Playback, MediaPlayer.OnErrorListener, Media
|
||||||
player.setOnCompletionListener(this);
|
player.setOnCompletionListener(this);
|
||||||
player.setOnErrorListener(this);
|
player.setOnErrorListener(this);
|
||||||
|
|
||||||
final Intent intent = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION);
|
|
||||||
intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, getAudioSessionId());
|
|
||||||
intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, context.getPackageName());
|
|
||||||
intent.putExtra(AudioEffect.EXTRA_CONTENT_TYPE, AudioEffect.CONTENT_TYPE_MUSIC);
|
|
||||||
|
|
||||||
context.sendBroadcast(intent);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the MediaPlayer to start when this MediaPlayer finishes playback.
|
|
||||||
*
|
|
||||||
* @param path The path of the file, or the http/rtsp URL of the stream
|
|
||||||
* you want to play
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void setNextDataSource(@Nullable final String path) {
|
public void setNextDataSource(@Nullable final String path) {
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ import android.graphics.Bitmap;
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.media.audiofx.AudioEffect;
|
|
||||||
import android.media.session.MediaSession;
|
import android.media.session.MediaSession;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
@ -441,25 +440,16 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
||||||
pause();
|
pause();
|
||||||
playingNotification.stop();
|
playingNotification.stop();
|
||||||
|
|
||||||
closeAudioEffectSession();
|
|
||||||
getAudioManager().abandonAudioFocus(audioFocusListener);
|
getAudioManager().abandonAudioFocus(audioFocusListener);
|
||||||
stopSelf();
|
stopSelf();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void releaseResources() {
|
private void releaseResources() {
|
||||||
playerHandler.removeCallbacksAndMessages(null);
|
playerHandler.removeCallbacksAndMessages(null);
|
||||||
if (Build.VERSION.SDK_INT >= 18) {
|
musicPlayerHandlerThread.quitSafely();
|
||||||
musicPlayerHandlerThread.quitSafely();
|
|
||||||
} else {
|
|
||||||
musicPlayerHandlerThread.quit();
|
|
||||||
}
|
|
||||||
|
|
||||||
queueSaveHandler.removeCallbacksAndMessages(null);
|
queueSaveHandler.removeCallbacksAndMessages(null);
|
||||||
if (Build.VERSION.SDK_INT >= 18) {
|
queueSaveHandlerThread.quitSafely();
|
||||||
queueSaveHandlerThread.quitSafely();
|
|
||||||
} else {
|
|
||||||
queueSaveHandlerThread.quit();
|
|
||||||
}
|
|
||||||
|
|
||||||
playback.release();
|
playback.release();
|
||||||
playback = null;
|
playback = null;
|
||||||
|
|
@ -517,13 +507,6 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void closeAudioEffectSession() {
|
|
||||||
final Intent audioEffectsIntent = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION);
|
|
||||||
audioEffectsIntent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, playback.getAudioSessionId());
|
|
||||||
audioEffectsIntent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
|
|
||||||
sendBroadcast(audioEffectsIntent);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean requestFocus() {
|
private boolean requestFocus() {
|
||||||
return (getAudioManager().requestAudioFocus(audioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED);
|
return (getAudioManager().requestAudioFocus(audioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED);
|
||||||
}
|
}
|
||||||
|
|
@ -661,6 +644,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -751,14 +735,14 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
||||||
|
|
||||||
public void removeSong(@NonNull Song song) {
|
public void removeSong(@NonNull Song song) {
|
||||||
for (int i = 0; i < playingQueue.size(); i++) {
|
for (int i = 0; i < playingQueue.size(); i++) {
|
||||||
if (playingQueue.get(i).id == song.id) {
|
if (playingQueue.get(i).id.equals(song.id)) {
|
||||||
playingQueue.remove(i);
|
playingQueue.remove(i);
|
||||||
rePosition(i);
|
rePosition(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < originalPlayingQueue.size(); i++) {
|
for (int i = 0; i < originalPlayingQueue.size(); i++) {
|
||||||
if (originalPlayingQueue.get(i).id == song.id) {
|
if (originalPlayingQueue.get(i).id.equals(song.id)) {
|
||||||
originalPlayingQueue.remove(i);
|
originalPlayingQueue.remove(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -848,10 +832,12 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
||||||
registerReceiver(becomingNoisyReceiver, becomingNoisyReceiverIntentFilter);
|
registerReceiver(becomingNoisyReceiver, becomingNoisyReceiverIntentFilter);
|
||||||
becomingNoisyReceiverRegistered = true;
|
becomingNoisyReceiverRegistered = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notHandledMetaChangedForCurrentTrack) {
|
if (notHandledMetaChangedForCurrentTrack) {
|
||||||
handleChangeInternal(META_CHANGED);
|
handleChangeInternal(META_CHANGED);
|
||||||
notHandledMetaChangedForCurrentTrack = false;
|
notHandledMetaChangedForCurrentTrack = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyChange(PLAY_STATE_CHANGED);
|
notifyChange(PLAY_STATE_CHANGED);
|
||||||
|
|
||||||
// fixes a bug where the volume would stay ducked because the AudioManager.AUDIOFOCUS_GAIN event is not sent
|
// fixes a bug where the volume would stay ducked because the AudioManager.AUDIOFOCUS_GAIN event is not sent
|
||||||
|
|
@ -906,10 +892,8 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case REPEAT_MODE_THIS:
|
case REPEAT_MODE_THIS:
|
||||||
if (force) {
|
if (force && newPosition < 0) {
|
||||||
if (newPosition < 0) {
|
newPosition = getPlayingQueue().size() - 1;
|
||||||
newPosition = getPlayingQueue().size() - 1;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
newPosition = getPosition();
|
newPosition = getPosition();
|
||||||
}
|
}
|
||||||
|
|
@ -921,6 +905,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return newPosition;
|
return newPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -934,8 +919,10 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
||||||
|
|
||||||
public long getQueueDurationMillis(int position) {
|
public long getQueueDurationMillis(int position) {
|
||||||
long duration = 0;
|
long duration = 0;
|
||||||
for (int i = position + 1; i < playingQueue.size(); i++)
|
for (int i = position + 1; i < playingQueue.size(); i++) {
|
||||||
duration += playingQueue.get(i).duration;
|
duration += playingQueue.get(i).duration;
|
||||||
|
}
|
||||||
|
|
||||||
return duration;
|
return duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -981,6 +968,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
||||||
PreferenceManager.getDefaultSharedPreferences(this).edit()
|
PreferenceManager.getDefaultSharedPreferences(this).edit()
|
||||||
.putInt(SAVED_SHUFFLE_MODE, shuffleMode)
|
.putInt(SAVED_SHUFFLE_MODE, shuffleMode)
|
||||||
.apply();
|
.apply();
|
||||||
|
|
||||||
switch (shuffleMode) {
|
switch (shuffleMode) {
|
||||||
case SHUFFLE_MODE_SHUFFLE:
|
case SHUFFLE_MODE_SHUFFLE:
|
||||||
this.shuffleMode = shuffleMode;
|
this.shuffleMode = shuffleMode;
|
||||||
|
|
@ -997,9 +985,11 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
||||||
newPosition = getPlayingQueue().indexOf(song);
|
newPosition = getPlayingQueue().indexOf(song);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
position = newPosition;
|
position = newPosition;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
handleAndSendChangeInternal(SHUFFLE_MODE_CHANGED);
|
handleAndSendChangeInternal(SHUFFLE_MODE_CHANGED);
|
||||||
notifyChange(QUEUE_CHANGED);
|
notifyChange(QUEUE_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
@ -1276,8 +1266,8 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(final Context context, final Intent intent) {
|
public void onReceive(final Context context, final Intent intent) {
|
||||||
final String command = intent.getStringExtra(EXTRA_APP_WIDGET_NAME);
|
final String command = intent.getStringExtra(EXTRA_APP_WIDGET_NAME);
|
||||||
|
|
||||||
final int[] ids = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
|
final int[] ids = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
|
||||||
|
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case AppWidgetClassic.NAME:
|
case AppWidgetClassic.NAME:
|
||||||
appWidgetClassic.performUpdate(MusicService.this, ids);
|
appWidgetClassic.performUpdate(MusicService.this, ids);
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,7 @@ public class MusicUtil {
|
||||||
public static String getReadableDurationString(long songDurationMillis) {
|
public static String getReadableDurationString(long songDurationMillis) {
|
||||||
long minutes = (songDurationMillis / 1000) / 60;
|
long minutes = (songDurationMillis / 1000) / 60;
|
||||||
long seconds = (songDurationMillis / 1000) % 60;
|
long seconds = (songDurationMillis / 1000) % 60;
|
||||||
|
|
||||||
if (minutes < 60) {
|
if (minutes < 60) {
|
||||||
return String.format(Locale.getDefault(), "%01d:%02d", minutes, seconds);
|
return String.format(Locale.getDefault(), "%01d:%02d", minutes, seconds);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -199,6 +199,9 @@ public class QueryUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void applySortMethod(ItemQuery query, String method) {
|
private static void applySortMethod(ItemQuery query, String method) {
|
||||||
|
// album activity will always sort by track number
|
||||||
|
if (query.getSortBy() != null) return;
|
||||||
|
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case SortMethod.NAME:
|
case SortMethod.NAME:
|
||||||
query.setSortBy(new String[]{"SortName"});
|
query.setSortBy(new String[]{"SortName"});
|
||||||
|
|
|
||||||
|
|
@ -67,8 +67,7 @@ public abstract class BaseAppWidget extends AppWidgetProvider {
|
||||||
*/
|
*/
|
||||||
protected boolean hasInstances(final Context context) {
|
protected boolean hasInstances(final Context context) {
|
||||||
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
||||||
final int[] mAppWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context,
|
final int[] mAppWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, getClass()));
|
||||||
getClass()));
|
|
||||||
return mAppWidgetIds.length > 0;
|
return mAppWidgetIds.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue