mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
First song played: What she said - The Smiths
This commit is contained in:
parent
c1c02b3c37
commit
0f19fc3190
12 changed files with 47 additions and 221 deletions
|
|
@ -79,7 +79,7 @@ dependencies {
|
||||||
implementation "com.github.woltapp:blurhash:f41a23cc50"
|
implementation "com.github.woltapp:blurhash:f41a23cc50"
|
||||||
|
|
||||||
// Exoplayer
|
// Exoplayer
|
||||||
implementation 'com.google.android.exoplayer:exoplayer:2.11.4'
|
implementation 'com.google.android.exoplayer:exoplayer:2.12.2'
|
||||||
|
|
||||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
|
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
|
||||||
annotationProcessor "androidx.room:room-compiler:2.2.5"
|
annotationProcessor "androidx.room:room-compiler:2.2.5"
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,14 @@ import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.cappielloantonio.play.App;
|
import com.cappielloantonio.play.App;
|
||||||
import com.cappielloantonio.play.R;
|
import com.cappielloantonio.play.R;
|
||||||
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
||||||
|
import com.cappielloantonio.play.helper.MusicPlayerRemote;
|
||||||
import com.cappielloantonio.play.model.Song;
|
import com.cappielloantonio.play.model.Song;
|
||||||
import com.cappielloantonio.play.repository.SongRepository;
|
import com.cappielloantonio.play.repository.SongRepository;
|
||||||
|
|
||||||
|
|
@ -66,6 +68,14 @@ public class PlayerNowPlayingSongAdapter extends RecyclerView.Adapter<PlayerNowP
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
SongRepository songRepository = new SongRepository(App.getInstance());
|
SongRepository songRepository = new SongRepository(App.getInstance());
|
||||||
songRepository.increasePlayCount(songs.get(getAdapterPosition()));
|
songRepository.increasePlayCount(songs.get(getAdapterPosition()));
|
||||||
|
|
||||||
|
if (MusicPlayerRemote.isPlaying()) {
|
||||||
|
MusicPlayerRemote.pauseSong();
|
||||||
|
Toast.makeText(context, "PAUSING", Toast.LENGTH_SHORT).show();
|
||||||
|
} else {
|
||||||
|
MusicPlayerRemote.resumePlaying();
|
||||||
|
Toast.makeText(context, "PLAYING", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||||
import com.cappielloantonio.play.App;
|
import com.cappielloantonio.play.App;
|
||||||
import com.cappielloantonio.play.R;
|
import com.cappielloantonio.play.R;
|
||||||
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
||||||
|
import com.cappielloantonio.play.helper.MusicPlayerRemote;
|
||||||
import com.cappielloantonio.play.model.Song;
|
import com.cappielloantonio.play.model.Song;
|
||||||
import com.cappielloantonio.play.repository.SongRepository;
|
import com.cappielloantonio.play.repository.SongRepository;
|
||||||
import com.cappielloantonio.play.ui.fragment.PlayerBottomSheetFragment;
|
import com.cappielloantonio.play.ui.fragment.PlayerBottomSheetFragment;
|
||||||
|
|
@ -82,6 +83,7 @@ public class PlayerSongQueueAdapter extends RecyclerView.Adapter<PlayerSongQueue
|
||||||
songRepository.increasePlayCount(songs.get(getAdapterPosition()));
|
songRepository.increasePlayCount(songs.get(getAdapterPosition()));
|
||||||
|
|
||||||
playerBottomSheetFragment.scrollPager(songs.get(getAdapterPosition()), getAdapterPosition(), true);
|
playerBottomSheetFragment.scrollPager(songs.get(getAdapterPosition()), getAdapterPosition(), true);
|
||||||
|
MusicPlayerRemote.openQueue(songs, getAdapterPosition(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ public class RecentMusicAdapter extends RecyclerView.Adapter<RecentMusicAdapter.
|
||||||
PlayerBottomSheetViewModel playerBottomSheetViewModel = new ViewModelProvider(mainActivity).get(PlayerBottomSheetViewModel.class);
|
PlayerBottomSheetViewModel playerBottomSheetViewModel = new ViewModelProvider(mainActivity).get(PlayerBottomSheetViewModel.class);
|
||||||
playerBottomSheetViewModel.setNowPlayingSong(songs.get(getAdapterPosition()));
|
playerBottomSheetViewModel.setNowPlayingSong(songs.get(getAdapterPosition()));
|
||||||
|
|
||||||
MusicPlayerRemote.openQueue(songs.subList(getAdapterPosition(), songs.size()), getAdapterPosition(), true);
|
MusicPlayerRemote.openQueue(songs.subList(getAdapterPosition(), songs.size()), 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||||
import com.cappielloantonio.play.App;
|
import com.cappielloantonio.play.App;
|
||||||
import com.cappielloantonio.play.R;
|
import com.cappielloantonio.play.R;
|
||||||
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
||||||
|
import com.cappielloantonio.play.helper.MusicPlayerRemote;
|
||||||
import com.cappielloantonio.play.model.Song;
|
import com.cappielloantonio.play.model.Song;
|
||||||
import com.cappielloantonio.play.repository.QueueRepository;
|
import com.cappielloantonio.play.repository.QueueRepository;
|
||||||
import com.cappielloantonio.play.repository.SongRepository;
|
import com.cappielloantonio.play.repository.SongRepository;
|
||||||
|
|
@ -102,6 +103,8 @@ public class SongResultSearchAdapter extends RecyclerView.Adapter<SongResultSear
|
||||||
|
|
||||||
PlayerBottomSheetViewModel playerBottomSheetViewModel = new ViewModelProvider(mainActivity).get(PlayerBottomSheetViewModel.class);
|
PlayerBottomSheetViewModel playerBottomSheetViewModel = new ViewModelProvider(mainActivity).get(PlayerBottomSheetViewModel.class);
|
||||||
playerBottomSheetViewModel.setNowPlayingSong(songs.get(getAdapterPosition()));
|
playerBottomSheetViewModel.setNowPlayingSong(songs.get(getAdapterPosition()));
|
||||||
|
|
||||||
|
MusicPlayerRemote.openQueue(songs.subList(getAdapterPosition(), songs.size()), 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import android.content.ContextWrapper;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
@ -18,10 +19,11 @@ import com.cappielloantonio.play.service.MusicService;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
public class MusicPlayerRemote {
|
public class MusicPlayerRemote {
|
||||||
|
private static final String TAG = "MusicPlayerRemote";
|
||||||
|
|
||||||
public static MusicService musicService;
|
public static MusicService musicService;
|
||||||
|
|
||||||
private static final WeakHashMap<Context, ServiceBinder> mConnectionMap = new WeakHashMap<>();
|
private static final WeakHashMap<Context, ServiceBinder> mConnectionMap = new WeakHashMap<>();
|
||||||
|
|
@ -143,22 +145,13 @@ public class MusicPlayerRemote {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void openQueue(final List<Song> queue, final int startPosition, final boolean startPlaying) {
|
public static void openQueue(final List<Song> queue, final int startPosition, final boolean startPlaying) {
|
||||||
|
Log.d(TAG, "MusicPlayerRemote - openQueue: S " + queue.size() + " P " + startPosition + " SP " + startPlaying);
|
||||||
|
|
||||||
if (!tryToHandleOpenPlayingQueue(queue, startPosition, startPlaying) && musicService != null) {
|
if (!tryToHandleOpenPlayingQueue(queue, startPosition, startPlaying) && musicService != null) {
|
||||||
musicService.openQueue(queue, startPosition, startPlaying);
|
musicService.openQueue(queue, startPosition, startPlaying);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void openAndShuffleQueue(final List<Song> queue, boolean startPlaying) {
|
|
||||||
int startPosition = 0;
|
|
||||||
if (!queue.isEmpty()) {
|
|
||||||
startPosition = new Random().nextInt(queue.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!tryToHandleOpenPlayingQueue(queue, startPosition, startPlaying) && musicService != null) {
|
|
||||||
openQueue(queue, startPosition, startPlaying);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean tryToHandleOpenPlayingQueue(final List<Song> queue, final int startPosition, final boolean startPlaying) {
|
private static boolean tryToHandleOpenPlayingQueue(final List<Song> queue, final int startPosition, final boolean startPlaying) {
|
||||||
if (getPlayingQueue() == queue) {
|
if (getPlayingQueue() == queue) {
|
||||||
if (startPlaying) {
|
if (startPlaying) {
|
||||||
|
|
@ -173,10 +166,6 @@ public class MusicPlayerRemote {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Song getCurrentSong() {
|
|
||||||
return musicService.getCurrentSong();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getPosition() {
|
public static int getPosition() {
|
||||||
if (musicService != null) {
|
if (musicService != null) {
|
||||||
return musicService.getPosition();
|
return musicService.getPosition();
|
||||||
|
|
@ -209,14 +198,6 @@ public class MusicPlayerRemote {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getQueueDurationMillis(int position) {
|
|
||||||
if (musicService != null) {
|
|
||||||
return musicService.getQueueDurationMillis(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int seekTo(int millis) {
|
public static int seekTo(int millis) {
|
||||||
if (musicService != null) {
|
if (musicService != null) {
|
||||||
return musicService.seek(millis);
|
return musicService.seek(millis);
|
||||||
|
|
@ -225,23 +206,6 @@ public class MusicPlayerRemote {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getRepeatMode() {
|
|
||||||
if (musicService != null) {
|
|
||||||
return musicService.getRepeatMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
return MusicService.REPEAT_MODE_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean cycleRepeatMode() {
|
|
||||||
if (musicService != null) {
|
|
||||||
musicService.cycleRepeatMode();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean playNext(Song song) {
|
public static boolean playNext(Song song) {
|
||||||
if (musicService != null) {
|
if (musicService != null) {
|
||||||
if (getPlayingQueue().size() > 0) {
|
if (getPlayingQueue().size() > 0) {
|
||||||
|
|
|
||||||
|
|
@ -68,8 +68,8 @@ public class MultiPlayer implements Playback {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadingChanged(boolean isLoading) {
|
public void onIsLoadingChanged(boolean isLoadingChanged) {
|
||||||
Log.i(TAG, "onLoadingChanged: " + isLoading);
|
Log.i(TAG, "onIsLoadingChanged: " + isLoadingChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -93,6 +93,11 @@ public class MultiPlayer implements Playback {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlaybackStateChanged(int state) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPositionDiscontinuity(int reason) {
|
public void onPositionDiscontinuity(int reason) {
|
||||||
Log.i(TAG, "onPositionDiscontinuity: " + reason);
|
Log.i(TAG, "onPositionDiscontinuity: " + reason);
|
||||||
|
|
|
||||||
|
|
@ -69,8 +69,6 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
||||||
public static final String META_CHANGED = PACKAGE_NAME + ".meta.changed";
|
public static final String META_CHANGED = PACKAGE_NAME + ".meta.changed";
|
||||||
public static final String QUEUE_CHANGED = PACKAGE_NAME + ".queue.changed";
|
public static final String QUEUE_CHANGED = PACKAGE_NAME + ".queue.changed";
|
||||||
|
|
||||||
public static final String REPEAT_MODE_CHANGED = PACKAGE_NAME + ".repeat.changed";
|
|
||||||
|
|
||||||
public static final int TRACK_STARTED = 9;
|
public static final int TRACK_STARTED = 9;
|
||||||
public static final int TRACK_CHANGED = 1;
|
public static final int TRACK_CHANGED = 1;
|
||||||
public static final int TRACK_ENDED = 2;
|
public static final int TRACK_ENDED = 2;
|
||||||
|
|
@ -83,11 +81,6 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
||||||
public static final int DUCK = 7;
|
public static final int DUCK = 7;
|
||||||
public static final int UNDUCK = 8;
|
public static final int UNDUCK = 8;
|
||||||
|
|
||||||
public static final int REPEAT_MODE_NONE = 0;
|
|
||||||
public static final int REPEAT_MODE_ALL = 1;
|
|
||||||
public static final int REPEAT_MODE_THIS = 2;
|
|
||||||
|
|
||||||
public static final int SAVE_QUEUE = 0;
|
|
||||||
public static final int LOAD_QUEUE = 9;
|
public static final int LOAD_QUEUE = 9;
|
||||||
|
|
||||||
private final IBinder musicBinder = new MusicBinder();
|
private final IBinder musicBinder = new MusicBinder();
|
||||||
|
|
@ -101,8 +94,6 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
||||||
private int position = -1;
|
private int position = -1;
|
||||||
private int nextPosition = -1;
|
private int nextPosition = -1;
|
||||||
|
|
||||||
private int repeatMode;
|
|
||||||
|
|
||||||
private boolean notHandledMetaChangedForCurrentTrack;
|
private boolean notHandledMetaChangedForCurrentTrack;
|
||||||
private boolean queuesRestored;
|
private boolean queuesRestored;
|
||||||
private boolean pausedByTransientLossOfFocus;
|
private boolean pausedByTransientLossOfFocus;
|
||||||
|
|
@ -113,7 +104,6 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
||||||
private PowerManager.WakeLock wakeLock;
|
private PowerManager.WakeLock wakeLock;
|
||||||
|
|
||||||
private PlaybackHandler playerHandler;
|
private PlaybackHandler playerHandler;
|
||||||
private Handler uiThreadHandler;
|
|
||||||
private ThrottledSeekHandler throttledSeekHandler;
|
private ThrottledSeekHandler throttledSeekHandler;
|
||||||
private QueueHandler queueHandler;
|
private QueueHandler queueHandler;
|
||||||
private ProgressHandler progressHandler;
|
private ProgressHandler progressHandler;
|
||||||
|
|
@ -170,7 +160,6 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
||||||
queueHandler = new QueueHandler(this, queueHandlerThread.getLooper());
|
queueHandler = new QueueHandler(this, queueHandlerThread.getLooper());
|
||||||
|
|
||||||
throttledSeekHandler = new ThrottledSeekHandler(playerHandler);
|
throttledSeekHandler = new ThrottledSeekHandler(playerHandler);
|
||||||
uiThreadHandler = new Handler();
|
|
||||||
|
|
||||||
registerReceiver(becomingNoisyReceiver, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY));
|
registerReceiver(becomingNoisyReceiver, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY));
|
||||||
|
|
||||||
|
|
@ -323,16 +312,13 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
||||||
case LOAD_QUEUE:
|
case LOAD_QUEUE:
|
||||||
service.restoreQueuesAndPositionIfNecessary();
|
service.restoreQueuesAndPositionIfNecessary();
|
||||||
break;
|
break;
|
||||||
case SAVE_QUEUE:
|
|
||||||
service.saveQueue();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveQueue() {
|
public void saveState() {
|
||||||
QueueRepository queueRepository = new QueueRepository(App.getInstance());
|
savePosition();
|
||||||
queueRepository.insertAllAndStartNew(playingQueue);
|
saveProgress();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void savePosition() {
|
private void savePosition() {
|
||||||
|
|
@ -343,19 +329,7 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
||||||
PreferenceManager.getDefaultSharedPreferences(this).edit().putInt(PreferenceUtil.PROGRESS, getSongProgressMillis()).apply();
|
PreferenceManager.getDefaultSharedPreferences(this).edit().putInt(PreferenceUtil.PROGRESS, getSongProgressMillis()).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveState() {
|
|
||||||
queueHandler.removeMessages(SAVE_QUEUE);
|
|
||||||
queueHandler.sendEmptyMessage(SAVE_QUEUE);
|
|
||||||
|
|
||||||
savePosition();
|
|
||||||
saveProgress();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void restoreState() {
|
private void restoreState() {
|
||||||
repeatMode = PreferenceManager.getDefaultSharedPreferences(this).getInt(PreferenceUtil.REPEAT, 0);
|
|
||||||
|
|
||||||
notifyChange(REPEAT_MODE_CHANGED);
|
|
||||||
|
|
||||||
queueHandler.removeMessages(LOAD_QUEUE);
|
queueHandler.removeMessages(LOAD_QUEUE);
|
||||||
queueHandler.sendEmptyMessage(LOAD_QUEUE);
|
queueHandler.sendEmptyMessage(LOAD_QUEUE);
|
||||||
}
|
}
|
||||||
|
|
@ -464,7 +438,7 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateNotification() {
|
public void updateNotification() {
|
||||||
if (playingNotification != null && getCurrentSong().getId() != null) {
|
if (playingNotification != null && getCurrentSong() != null) {
|
||||||
playingNotification.update();
|
playingNotification.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -481,7 +455,7 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
||||||
private void updateMediaSessionMetadata() {
|
private void updateMediaSessionMetadata() {
|
||||||
final Song song = getCurrentSong();
|
final Song song = getCurrentSong();
|
||||||
|
|
||||||
if (song.getId() == null) {
|
if (song == null) {
|
||||||
mediaSession.setMetadata(null);
|
mediaSession.setMetadata(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -499,10 +473,6 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
||||||
metaData.putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, getPlayingQueue().size());
|
metaData.putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, getPlayingQueue().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runOnUiThread(Runnable runnable) {
|
|
||||||
uiThreadHandler.post(runnable);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Song getCurrentSong() {
|
public Song getCurrentSong() {
|
||||||
return getSongAt(getPosition());
|
return getSongAt(getPosition());
|
||||||
}
|
}
|
||||||
|
|
@ -516,31 +486,7 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNextPosition(boolean force) {
|
public int getNextPosition(boolean force) {
|
||||||
int position = getPosition() + 1;
|
return getPosition() + 1;
|
||||||
switch (getRepeatMode()) {
|
|
||||||
case REPEAT_MODE_ALL:
|
|
||||||
if (isLastTrack()) {
|
|
||||||
position = 0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case REPEAT_MODE_THIS:
|
|
||||||
if (force) {
|
|
||||||
if (isLastTrack()) {
|
|
||||||
position = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
position -= 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
case REPEAT_MODE_NONE:
|
|
||||||
if (isLastTrack()) {
|
|
||||||
position -= 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return position;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isLastTrack() {
|
private boolean isLastTrack() {
|
||||||
|
|
@ -551,31 +497,15 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
||||||
return playingQueue;
|
return playingQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRepeatMode() {
|
|
||||||
return repeatMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRepeatMode(final int repeatMode) {
|
|
||||||
switch (repeatMode) {
|
|
||||||
case REPEAT_MODE_NONE:
|
|
||||||
case REPEAT_MODE_ALL:
|
|
||||||
case REPEAT_MODE_THIS:
|
|
||||||
this.repeatMode = repeatMode;
|
|
||||||
PreferenceManager.getDefaultSharedPreferences(this).edit()
|
|
||||||
.putInt(PreferenceUtil.REPEAT, repeatMode)
|
|
||||||
.apply();
|
|
||||||
prepareNext();
|
|
||||||
notifyChange(REPEAT_MODE_CHANGED);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void openQueue(@Nullable final List<Song> playingQueue, final int startPosition, final boolean startPlaying) {
|
public void openQueue(@Nullable final List<Song> playingQueue, final int startPosition, final boolean startPlaying) {
|
||||||
if (playingQueue != null && !playingQueue.isEmpty() && startPosition >= 0 && startPosition < playingQueue.size()) {
|
if (playingQueue != null && !playingQueue.isEmpty() && startPosition >= 0 && startPosition < playingQueue.size()) {
|
||||||
|
this.playingQueue = playingQueue;
|
||||||
|
this.position = startPosition;
|
||||||
|
|
||||||
if (startPlaying) {
|
if (startPlaying) {
|
||||||
playSongAt(startPosition);
|
playSongAt(position);
|
||||||
} else {
|
} else {
|
||||||
setPosition(startPosition);
|
setPosition(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyChange(QUEUE_CHANGED);
|
notifyChange(QUEUE_CHANGED);
|
||||||
|
|
@ -709,31 +639,7 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPreviousPosition(boolean force) {
|
public int getPreviousPosition(boolean force) {
|
||||||
int newPosition = getPosition() - 1;
|
return getPosition() - 1;
|
||||||
switch (repeatMode) {
|
|
||||||
case REPEAT_MODE_ALL:
|
|
||||||
if (newPosition < 0) {
|
|
||||||
newPosition = getPlayingQueue().size() - 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case REPEAT_MODE_THIS:
|
|
||||||
if (force) {
|
|
||||||
if (newPosition < 0) {
|
|
||||||
newPosition = getPlayingQueue().size() - 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
newPosition = getPosition();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
case REPEAT_MODE_NONE:
|
|
||||||
if (newPosition < 0) {
|
|
||||||
newPosition = 0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return newPosition;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSongProgressMillis() {
|
public int getSongProgressMillis() {
|
||||||
|
|
@ -761,20 +667,6 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cycleRepeatMode() {
|
|
||||||
switch (getRepeatMode()) {
|
|
||||||
case REPEAT_MODE_NONE:
|
|
||||||
setRepeatMode(REPEAT_MODE_ALL);
|
|
||||||
break;
|
|
||||||
case REPEAT_MODE_ALL:
|
|
||||||
setRepeatMode(REPEAT_MODE_THIS);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
setRepeatMode(REPEAT_MODE_NONE);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void notifyChange(@NonNull final String what) {
|
private void notifyChange(@NonNull final String what) {
|
||||||
handleChangeInternal(what);
|
handleChangeInternal(what);
|
||||||
sendChangeInternal(what);
|
sendChangeInternal(what);
|
||||||
|
|
@ -821,10 +713,6 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void acquireWakeLock(long milli) {
|
|
||||||
wakeLock.acquire(milli);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrackStarted() {
|
public void onTrackStarted() {
|
||||||
progressHandler.sendEmptyMessage(TRACK_STARTED);
|
progressHandler.sendEmptyMessage(TRACK_STARTED);
|
||||||
|
|
@ -837,8 +725,6 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
||||||
public void onTrackWentToNext() {
|
public void onTrackWentToNext() {
|
||||||
playerHandler.sendEmptyMessage(TRACK_CHANGED);
|
playerHandler.sendEmptyMessage(TRACK_CHANGED);
|
||||||
progressHandler.sendEmptyMessage(TRACK_CHANGED);
|
progressHandler.sendEmptyMessage(TRACK_CHANGED);
|
||||||
|
|
||||||
acquireWakeLock(30000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -895,20 +781,14 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TRACK_CHANGED:
|
case TRACK_CHANGED:
|
||||||
if (service.getRepeatMode() == REPEAT_MODE_NONE && service.isLastTrack()) {
|
|
||||||
service.pause();
|
|
||||||
service.seek(0);
|
|
||||||
service.notifyChange(STATE_CHANGED);
|
|
||||||
} else {
|
|
||||||
service.position = service.nextPosition;
|
service.position = service.nextPosition;
|
||||||
service.prepareNextImpl();
|
service.prepareNextImpl();
|
||||||
service.notifyChange(META_CHANGED);
|
service.notifyChange(META_CHANGED);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TRACK_ENDED:
|
case TRACK_ENDED:
|
||||||
// if there is a timer finished, don't continue
|
// if there is a timer finished, don't continue
|
||||||
if (service.pendingQuit || service.getRepeatMode() == REPEAT_MODE_NONE && service.isLastTrack()) {
|
if (service.pendingQuit && service.isLastTrack()) {
|
||||||
service.notifyChange(STATE_CHANGED);
|
service.notifyChange(STATE_CHANGED);
|
||||||
service.seek(0);
|
service.seek(0);
|
||||||
if (service.pendingQuit) {
|
if (service.pendingQuit) {
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,6 @@ public class BaseActivity extends AppCompatActivity implements EasyPermissions.P
|
||||||
|
|
||||||
final IntentFilter filter = new IntentFilter();
|
final IntentFilter filter = new IntentFilter();
|
||||||
filter.addAction(MusicService.STATE_CHANGED);
|
filter.addAction(MusicService.STATE_CHANGED);
|
||||||
filter.addAction(MusicService.REPEAT_MODE_CHANGED);
|
|
||||||
filter.addAction(MusicService.META_CHANGED);
|
filter.addAction(MusicService.META_CHANGED);
|
||||||
filter.addAction(MusicService.QUEUE_CHANGED);
|
filter.addAction(MusicService.QUEUE_CHANGED);
|
||||||
|
|
||||||
|
|
@ -240,9 +239,6 @@ public class BaseActivity extends AppCompatActivity implements EasyPermissions.P
|
||||||
case MusicService.STATE_CHANGED:
|
case MusicService.STATE_CHANGED:
|
||||||
activity.onPlayStateChanged();
|
activity.onPlayStateChanged();
|
||||||
break;
|
break;
|
||||||
case MusicService.REPEAT_MODE_CHANGED:
|
|
||||||
activity.onRepeatModeChanged();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ScrollView;
|
import android.widget.ScrollView;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
@ -154,34 +153,15 @@ public class PlayerBottomSheetFragment extends Fragment implements MusicServiceE
|
||||||
bind.playerHeaderLayout.playerHeaderSongArtistLabel.setText(song.getArtistName());
|
bind.playerHeaderLayout.playerHeaderSongArtistLabel.setText(song.getArtistName());
|
||||||
|
|
||||||
bind.playerBodyLayout.buttonFavorite.setChecked(song.isFavorite());
|
bind.playerBodyLayout.buttonFavorite.setChecked(song.isFavorite());
|
||||||
|
|
||||||
playSong(song);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpMusicControllers() {
|
private void setUpMusicControllers() {
|
||||||
setUpPlayPauseButton();
|
|
||||||
// setUpPrevNext();
|
// setUpPrevNext();
|
||||||
// setUpRepeatButton();
|
// setUpRepeatButton();
|
||||||
// setUpShuffleButton();
|
// setUpShuffleButton();
|
||||||
initSeekBar();
|
initSeekBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpPlayPauseButton() {
|
|
||||||
bind.playerBodyLayout.playPauseButton.setOnClickListener(v -> {
|
|
||||||
if (MusicPlayerRemote.isPlaying()) {
|
|
||||||
MusicPlayerRemote.pauseSong();
|
|
||||||
Toast.makeText(requireContext(), "PAUSING", Toast.LENGTH_SHORT).show();
|
|
||||||
} else {
|
|
||||||
MusicPlayerRemote.resumePlaying();
|
|
||||||
Toast.makeText(requireContext(), "PLAYING", Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void playSong(Song song) {
|
|
||||||
// Toast.makeText(activity, MusicUtil.getSongFileUri(song), Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
public View getPlayerHeader() {
|
public View getPlayerHeader() {
|
||||||
return getView().findViewById(R.id.player_header_layout);
|
return getView().findViewById(R.id.player_header_layout);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/now_playing_song_cover_image_view"
|
android:id="@+id/now_playing_song_cover_image_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"/>
|
android:layout_height="match_parent"
|
||||||
|
android:background="?android:attr/selectableItemBackground"/>
|
||||||
|
|
||||||
</androidx.cardview.widget.CardView>
|
</androidx.cardview.widget.CardView>
|
||||||
|
|
@ -22,21 +22,6 @@
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<ToggleButton
|
|
||||||
android:id="@+id/play_pause_button"
|
|
||||||
android:layout_width="26dp"
|
|
||||||
android:layout_height="26dp"
|
|
||||||
android:background="@drawable/button_play_pause_selector"
|
|
||||||
android:checked="true"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:layout_marginTop="20dp"
|
|
||||||
android:layout_marginEnd="24dp"
|
|
||||||
android:text=""
|
|
||||||
android:textOff=""
|
|
||||||
android:textOn=""
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
|
|
||||||
<androidx.viewpager2.widget.ViewPager2
|
<androidx.viewpager2.widget.ViewPager2
|
||||||
android:id="@+id/player_song_cover_view_pager"
|
android:id="@+id/player_song_cover_view_pager"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue