Major cleanup, minor fixes
This commit is contained in:
parent
8c60e09914
commit
b83631107c
|
@ -960,7 +960,7 @@
|
|||
|
||||
<issue
|
||||
id="StaticFieldLeak"
|
||||
message="This AsyncTask class should be static or leaks might occur (org.moire.ultrasonic.service.DownloadServiceLifecycleSupport.SerializeTask)"
|
||||
message="This AsyncTask class should be static or leaks might occur (org.moire.ultrasonic.service.MediaPlayerLifecycleSupport.SerializeTask)"
|
||||
errorLine1=" private class SerializeTask extends AsyncTask<Void, Void, Void>"
|
||||
errorLine2=" ~~~~~~~~~~~~~">
|
||||
<location
|
||||
|
@ -971,7 +971,7 @@
|
|||
|
||||
<issue
|
||||
id="StaticFieldLeak"
|
||||
message="This AsyncTask class should be static or leaks might occur (org.moire.ultrasonic.service.DownloadServiceLifecycleSupport.DeserializeTask)"
|
||||
message="This AsyncTask class should be static or leaks might occur (org.moire.ultrasonic.service.MediaPlayerLifecycleSupport.DeserializeTask)"
|
||||
errorLine1=" private class DeserializeTask extends AsyncTask<Void, Void, Void>"
|
||||
errorLine2=" ~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
|
|
|
@ -206,8 +206,8 @@ public class BookmarkActivity extends SubsonicTabActivity
|
|||
if (!getSelectedSongs(albumListView).isEmpty())
|
||||
{
|
||||
int position = songs.get(0).getBookmarkPosition();
|
||||
if (getDownloadService() == null) return;
|
||||
getDownloadService().restore(songs, 0, position, true, true);
|
||||
if (getMediaPlayerController() == null) return;
|
||||
getMediaPlayerController().restore(songs, 0, position, true, true);
|
||||
selectAll(false, false);
|
||||
}
|
||||
}
|
||||
|
@ -296,7 +296,7 @@ public class BookmarkActivity extends SubsonicTabActivity
|
|||
|
||||
private void enableButtons()
|
||||
{
|
||||
if (getDownloadService() == null)
|
||||
if (getMediaPlayerController() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -345,7 +345,7 @@ public class BookmarkActivity extends SubsonicTabActivity
|
|||
|
||||
private void downloadBackground(final boolean save, final List<MusicDirectory.Entry> songs)
|
||||
{
|
||||
if (getDownloadService() == null)
|
||||
if (getMediaPlayerController() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -356,7 +356,7 @@ public class BookmarkActivity extends SubsonicTabActivity
|
|||
public void run()
|
||||
{
|
||||
warnIfNetworkOrStorageUnavailable();
|
||||
getDownloadService().downloadBackground(songs, save);
|
||||
getMediaPlayerController().downloadBackground(songs, save);
|
||||
|
||||
if (save)
|
||||
{
|
||||
|
@ -382,19 +382,19 @@ public class BookmarkActivity extends SubsonicTabActivity
|
|||
songs = getSelectedSongs(albumListView);
|
||||
}
|
||||
|
||||
if (getDownloadService() != null)
|
||||
if (getMediaPlayerController() != null)
|
||||
{
|
||||
getDownloadService().delete(songs);
|
||||
getMediaPlayerController().delete(songs);
|
||||
}
|
||||
}
|
||||
|
||||
private void unpin()
|
||||
{
|
||||
if (getDownloadService() != null)
|
||||
if (getMediaPlayerController() != null)
|
||||
{
|
||||
List<MusicDirectory.Entry> songs = getSelectedSongs(albumListView);
|
||||
Util.toast(BookmarkActivity.this, getResources().getQuantityString(R.plurals.select_album_n_songs_unpinned, songs.size(), songs.size()));
|
||||
getDownloadService().unpin(songs);
|
||||
getMediaPlayerController().unpin(songs);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ import org.moire.ultrasonic.domain.RepeatMode;
|
|||
import org.moire.ultrasonic.featureflags.Feature;
|
||||
import org.moire.ultrasonic.featureflags.FeatureStorage;
|
||||
import org.moire.ultrasonic.service.DownloadFile;
|
||||
import org.moire.ultrasonic.service.DownloadService;
|
||||
import org.moire.ultrasonic.service.MediaPlayerController;
|
||||
import org.moire.ultrasonic.service.MusicService;
|
||||
import org.moire.ultrasonic.service.MusicServiceFactory;
|
||||
import org.moire.ultrasonic.util.Constants;
|
||||
|
@ -257,7 +257,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
@Override
|
||||
protected Void doInBackground() throws Throwable
|
||||
{
|
||||
getDownloadService().previous();
|
||||
getMediaPlayerController().previous();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -295,7 +295,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
{
|
||||
if (downloader.getValue().getCurrentPlayingIndex() < downloader.getValue().downloadList.size() - 1)
|
||||
{
|
||||
getDownloadService().next();
|
||||
getMediaPlayerController().next();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -337,7 +337,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
@Override
|
||||
protected Void doInBackground() throws Throwable
|
||||
{
|
||||
getDownloadService().pause();
|
||||
getMediaPlayerController().pause();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -361,7 +361,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
@Override
|
||||
protected Void doInBackground() throws Throwable
|
||||
{
|
||||
getDownloadService().reset();
|
||||
getMediaPlayerController().reset();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -406,7 +406,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
@Override
|
||||
public void onClick(final View view)
|
||||
{
|
||||
getDownloadService().shuffle();
|
||||
getMediaPlayerController().shuffle();
|
||||
Util.toast(DownloadActivity.this, R.string.download_menu_shuffle_notification);
|
||||
}
|
||||
});
|
||||
|
@ -416,9 +416,9 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
@Override
|
||||
public void onClick(final View view)
|
||||
{
|
||||
final RepeatMode repeatMode = getDownloadService().getRepeatMode().next();
|
||||
final RepeatMode repeatMode = getMediaPlayerController().getRepeatMode().next();
|
||||
|
||||
getDownloadService().setRepeatMode(repeatMode);
|
||||
getMediaPlayerController().setRepeatMode(repeatMode);
|
||||
onDownloadListChanged();
|
||||
|
||||
switch (repeatMode)
|
||||
|
@ -448,7 +448,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
@Override
|
||||
protected Void doInBackground() throws Throwable
|
||||
{
|
||||
getDownloadService().seekTo(getProgressBar().getProgress());
|
||||
getMediaPlayerController().seekTo(getProgressBar().getProgress());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -483,7 +483,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
@Override
|
||||
protected Void doInBackground() throws Throwable
|
||||
{
|
||||
getDownloadService().play(position);
|
||||
getMediaPlayerController().play(position);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -499,15 +499,15 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
|
||||
registerForContextMenu(playlistView);
|
||||
|
||||
final DownloadService downloadService = getDownloadService();
|
||||
if (downloadService != null && getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, false))
|
||||
final MediaPlayerController mediaPlayerController = getMediaPlayerController();
|
||||
if (mediaPlayerController != null && getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, false))
|
||||
{
|
||||
warnIfNetworkOrStorageUnavailable();
|
||||
downloadService.setShufflePlayEnabled(true);
|
||||
mediaPlayerController.setShufflePlayEnabled(true);
|
||||
}
|
||||
|
||||
visualizerAvailable = (downloadService != null) && (downloadService.getVisualizerController() != null);
|
||||
equalizerAvailable = (downloadService != null) && (downloadService.getEqualizerController() != null);
|
||||
visualizerAvailable = (mediaPlayerController != null) && (mediaPlayerController.getVisualizerController() != null);
|
||||
equalizerAvailable = (mediaPlayerController != null) && (mediaPlayerController.getEqualizerController() != null);
|
||||
|
||||
new Thread(new Runnable()
|
||||
{
|
||||
|
@ -516,8 +516,8 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
{
|
||||
try
|
||||
{
|
||||
DownloadService downloadService = getDownloadService();
|
||||
jukeboxAvailable = (downloadService != null) && (downloadService.isJukeboxAvailable());
|
||||
MediaPlayerController mediaPlayerController = getMediaPlayerController();
|
||||
jukeboxAvailable = (mediaPlayerController != null) && (mediaPlayerController.isJukeboxAvailable());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -549,7 +549,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
public boolean onTouch(final View view, final MotionEvent motionEvent)
|
||||
{
|
||||
visualizerView.setActive(!visualizerView.isActive());
|
||||
getDownloadService().setShowVisualization(visualizerView.isActive());
|
||||
getMediaPlayerController().setShowVisualization(visualizerView.isActive());
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
@ -565,9 +565,9 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
{
|
||||
super.onResume();
|
||||
|
||||
final DownloadService downloadService = getDownloadService();
|
||||
final MediaPlayerController mediaPlayerController = getMediaPlayerController();
|
||||
|
||||
if (downloadService == null || player.getValue().currentPlaying == null)
|
||||
if (mediaPlayerController == null || localMediaPlayer.getValue().currentPlaying == null)
|
||||
{
|
||||
playlistFlipper.setDisplayedChild(1);
|
||||
}
|
||||
|
@ -592,7 +592,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
executorService = Executors.newSingleThreadScheduledExecutor();
|
||||
executorService.scheduleWithFixedDelay(runnable, 0L, 250L, TimeUnit.MILLISECONDS);
|
||||
|
||||
if (downloadService != null && downloadService.getKeepScreenOn())
|
||||
if (mediaPlayerController != null && mediaPlayerController.getKeepScreenOn())
|
||||
{
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
|
@ -603,7 +603,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
|
||||
if (visualizerView != null)
|
||||
{
|
||||
visualizerView.setActive(downloadService != null && downloadService.getShowVisualization());
|
||||
visualizerView.setActive(mediaPlayerController != null && mediaPlayerController.getShowVisualization());
|
||||
}
|
||||
|
||||
invalidateOptionsMenu();
|
||||
|
@ -612,7 +612,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
// Scroll to current playing/downloading.
|
||||
private void scrollToCurrent()
|
||||
{
|
||||
if (getDownloadService() == null)
|
||||
if (getMediaPlayerController() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -706,7 +706,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
{
|
||||
if (id == DIALOG_SAVE_PLAYLIST)
|
||||
{
|
||||
final String playlistName = (getDownloadService() != null) ? getDownloadService().getSuggestedPlaylistName() : null;
|
||||
final String playlistName = (getMediaPlayerController() != null) ? getMediaPlayerController().getSuggestedPlaylistName() : null;
|
||||
if (playlistName != null)
|
||||
{
|
||||
playlistNameView.setText(playlistName);
|
||||
|
@ -778,11 +778,11 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
visualizerMenuItem.setVisible(visualizerAvailable);
|
||||
}
|
||||
|
||||
final DownloadService downloadService = getDownloadService();
|
||||
final MediaPlayerController mediaPlayerController = getMediaPlayerController();
|
||||
|
||||
if (downloadService != null)
|
||||
if (mediaPlayerController != null)
|
||||
{
|
||||
DownloadFile downloadFile = player.getValue().currentPlaying;
|
||||
DownloadFile downloadFile = localMediaPlayer.getValue().currentPlaying;
|
||||
|
||||
if (downloadFile != null)
|
||||
{
|
||||
|
@ -807,7 +807,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
}
|
||||
|
||||
|
||||
if (downloadService.getKeepScreenOn())
|
||||
if (mediaPlayerController.getKeepScreenOn())
|
||||
{
|
||||
if (screenOption != null)
|
||||
{
|
||||
|
@ -827,7 +827,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
jukeboxOption.setEnabled(jukeboxAvailable);
|
||||
jukeboxOption.setVisible(jukeboxAvailable);
|
||||
|
||||
if (downloadService.isJukeboxEnabled())
|
||||
if (mediaPlayerController.isJukeboxEnabled())
|
||||
{
|
||||
jukeboxOption.setTitle(R.string.download_menu_jukebox_off);
|
||||
}
|
||||
|
@ -967,23 +967,23 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
startActivityForResultWithoutTransition(this, intent);
|
||||
return true;
|
||||
case R.id.menu_remove:
|
||||
getDownloadService().remove(song);
|
||||
getMediaPlayerController().remove(song);
|
||||
onDownloadListChanged();
|
||||
return true;
|
||||
case R.id.menu_item_screen_on_off:
|
||||
if (getDownloadService().getKeepScreenOn())
|
||||
if (getMediaPlayerController().getKeepScreenOn())
|
||||
{
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
getDownloadService().setKeepScreenOn(false);
|
||||
getMediaPlayerController().setKeepScreenOn(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
getDownloadService().setKeepScreenOn(true);
|
||||
getMediaPlayerController().setKeepScreenOn(true);
|
||||
}
|
||||
return true;
|
||||
case R.id.menu_shuffle:
|
||||
getDownloadService().shuffle();
|
||||
getMediaPlayerController().shuffle();
|
||||
Util.toast(this, R.string.download_menu_shuffle_notification);
|
||||
return true;
|
||||
case R.id.menu_item_equalizer:
|
||||
|
@ -1002,20 +1002,20 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
visualizerViewLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
getDownloadService().setShowVisualization(visualizerView.isActive());
|
||||
getMediaPlayerController().setShowVisualization(visualizerView.isActive());
|
||||
Util.toast(DownloadActivity.this, active ? R.string.download_visualizer_on : R.string.download_visualizer_off);
|
||||
return true;
|
||||
case R.id.menu_item_jukebox:
|
||||
final boolean jukeboxEnabled = !getDownloadService().isJukeboxEnabled();
|
||||
getDownloadService().setJukeboxEnabled(jukeboxEnabled);
|
||||
final boolean jukeboxEnabled = !getMediaPlayerController().isJukeboxEnabled();
|
||||
getMediaPlayerController().setJukeboxEnabled(jukeboxEnabled);
|
||||
Util.toast(DownloadActivity.this, jukeboxEnabled ? R.string.download_jukebox_on : R.string.download_jukebox_off, false);
|
||||
return true;
|
||||
case R.id.menu_item_toggle_list:
|
||||
toggleFullScreenAlbumArt();
|
||||
return true;
|
||||
case R.id.menu_item_clear_playlist:
|
||||
getDownloadService().setShufflePlayEnabled(false);
|
||||
getDownloadService().clear();
|
||||
getMediaPlayerController().setShufflePlayEnabled(false);
|
||||
getMediaPlayerController().clear();
|
||||
onDownloadListChanged();
|
||||
return true;
|
||||
case R.id.menu_item_save_playlist:
|
||||
|
@ -1077,7 +1077,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
}
|
||||
|
||||
final String songId = currentSong.getId();
|
||||
final int playerPosition = getDownloadService().getPlayerPosition();
|
||||
final int playerPosition = getMediaPlayerController().getPlayerPosition();
|
||||
|
||||
currentSong.setBookmarkPosition(playerPosition);
|
||||
|
||||
|
@ -1137,10 +1137,10 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
|
||||
return true;
|
||||
case R.id.menu_item_share:
|
||||
DownloadService downloadService = getDownloadService();
|
||||
MediaPlayerController mediaPlayerController = getMediaPlayerController();
|
||||
List<Entry> entries = new ArrayList<Entry>();
|
||||
|
||||
if (downloadService != null)
|
||||
if (mediaPlayerController != null)
|
||||
{
|
||||
List<DownloadFile> downloadServiceSongs = downloader.getValue().downloadList;
|
||||
|
||||
|
@ -1170,7 +1170,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
|
||||
private void update()
|
||||
{
|
||||
if (getDownloadService() == null)
|
||||
if (getMediaPlayerController() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -1180,7 +1180,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
onDownloadListChanged();
|
||||
}
|
||||
|
||||
if (currentPlaying != player.getValue().currentPlaying)
|
||||
if (currentPlaying != localMediaPlayer.getValue().currentPlaying)
|
||||
{
|
||||
onCurrentChanged();
|
||||
}
|
||||
|
@ -1192,7 +1192,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
private void savePlaylistInBackground(final String playlistName)
|
||||
{
|
||||
Util.toast(DownloadActivity.this, getResources().getString(R.string.download_playlist_saving, playlistName));
|
||||
getDownloadService().setSuggestedPlaylistName(playlistName);
|
||||
getMediaPlayerController().setSuggestedPlaylistName(playlistName);
|
||||
new SilentBackgroundTask<Void>(this)
|
||||
{
|
||||
@Override
|
||||
|
@ -1243,7 +1243,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
|
||||
private void start()
|
||||
{
|
||||
final DownloadService service = getDownloadService();
|
||||
final MediaPlayerController service = getMediaPlayerController();
|
||||
final PlayerState state = service.getPlayerState();
|
||||
|
||||
if (state == PAUSED || state == COMPLETED || state == STOPPED)
|
||||
|
@ -1269,8 +1269,8 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
|
||||
private void onDownloadListChanged()
|
||||
{
|
||||
final DownloadService downloadService = getDownloadService();
|
||||
if (downloadService == null)
|
||||
final MediaPlayerController mediaPlayerController = getMediaPlayerController();
|
||||
if (mediaPlayerController == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -1306,18 +1306,18 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
public void remove(int which)
|
||||
{
|
||||
DownloadFile item = adapter.getItem(which);
|
||||
DownloadService downloadService = getDownloadService();
|
||||
MediaPlayerController mediaPlayerController = getMediaPlayerController();
|
||||
|
||||
if (item == null || downloadService == null)
|
||||
if (item == null || mediaPlayerController == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DownloadFile currentPlaying = player.getValue().currentPlaying;
|
||||
DownloadFile currentPlaying = localMediaPlayer.getValue().currentPlaying;
|
||||
|
||||
if (currentPlaying == item)
|
||||
{
|
||||
getDownloadService().next();
|
||||
getMediaPlayerController().next();
|
||||
}
|
||||
|
||||
adapter.remove(item);
|
||||
|
@ -1335,7 +1335,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
emptyTextView.setVisibility(list.isEmpty() ? View.VISIBLE : View.GONE);
|
||||
currentRevision = downloader.getValue().getDownloadListUpdateRevision();
|
||||
|
||||
switch (downloadService.getRepeatMode())
|
||||
switch (mediaPlayerController.getRepeatMode())
|
||||
{
|
||||
case OFF:
|
||||
repeatButton.setImageDrawable(Util.getDrawableFromAttribute(this, R.attr.media_repeat_off));
|
||||
|
@ -1353,14 +1353,14 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
|
||||
private void onCurrentChanged()
|
||||
{
|
||||
DownloadService downloadService = getDownloadService();
|
||||
MediaPlayerController mediaPlayerController = getMediaPlayerController();
|
||||
|
||||
if (downloadService == null)
|
||||
if (mediaPlayerController == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
currentPlaying = player.getValue().currentPlaying;
|
||||
currentPlaying = localMediaPlayer.getValue().currentPlaying;
|
||||
|
||||
scrollToCurrent();
|
||||
|
||||
|
@ -1398,16 +1398,16 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
|
||||
private void onSliderProgressChanged()
|
||||
{
|
||||
DownloadService downloadService = getDownloadService();
|
||||
MediaPlayerController mediaPlayerController = getMediaPlayerController();
|
||||
|
||||
if (downloadService == null || onProgressChangedTask != null)
|
||||
if (mediaPlayerController == null || onProgressChangedTask != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
onProgressChangedTask = new SilentBackgroundTask<Void>(this)
|
||||
{
|
||||
DownloadService downloadService;
|
||||
MediaPlayerController mediaPlayerController;
|
||||
boolean isJukeboxEnabled;
|
||||
int millisPlayed;
|
||||
Integer duration;
|
||||
|
@ -1416,11 +1416,11 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
@Override
|
||||
protected Void doInBackground() throws Throwable
|
||||
{
|
||||
downloadService = getDownloadService();
|
||||
isJukeboxEnabled = downloadService.isJukeboxEnabled();
|
||||
millisPlayed = Math.max(0, downloadService.getPlayerPosition());
|
||||
duration = downloadService.getPlayerDuration();
|
||||
playerState = getDownloadService().getPlayerState();
|
||||
this.mediaPlayerController = getMediaPlayerController();
|
||||
isJukeboxEnabled = this.mediaPlayerController.isJukeboxEnabled();
|
||||
millisPlayed = Math.max(0, this.mediaPlayerController.getPlayerPosition());
|
||||
duration = this.mediaPlayerController.getPlayerDuration();
|
||||
playerState = getMediaPlayerController().getPlayerState();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1457,9 +1457,9 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
setActionBarSubtitle(R.string.download_playerstate_buffering);
|
||||
break;
|
||||
case STARTED:
|
||||
final DownloadService downloadService = getDownloadService();
|
||||
final MediaPlayerController mediaPlayerController = getMediaPlayerController();
|
||||
|
||||
if (downloadService != null && downloadService.isShufflePlayEnabled())
|
||||
if (mediaPlayerController != null && mediaPlayerController.isShufflePlayEnabled())
|
||||
{
|
||||
setActionBarSubtitle(R.string.download_playerstate_playing_shuffle);
|
||||
}
|
||||
|
@ -1503,7 +1503,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
break;
|
||||
}
|
||||
|
||||
// TODO: It would be a lot nicer if DownloadService would send an event when this is necessary instead of updating every time
|
||||
// TODO: It would be a lot nicer if MediaPlayerController would send an event when this is necessary instead of updating every time
|
||||
displaySongRating();
|
||||
|
||||
onProgressChangedTask = null;
|
||||
|
@ -1514,8 +1514,8 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
|
||||
private void changeProgress(final int ms)
|
||||
{
|
||||
final DownloadService downloadService = getDownloadService();
|
||||
if (downloadService == null)
|
||||
final MediaPlayerController mediaPlayerController = getMediaPlayerController();
|
||||
if (mediaPlayerController == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -1529,12 +1529,12 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
@Override
|
||||
protected Void doInBackground() throws Throwable
|
||||
{
|
||||
msPlayed = Math.max(0, downloadService.getPlayerPosition());
|
||||
duration = downloadService.getPlayerDuration();
|
||||
msPlayed = Math.max(0, mediaPlayerController.getPlayerPosition());
|
||||
duration = mediaPlayerController.getPlayerDuration();
|
||||
|
||||
final int msTotal = duration;
|
||||
seekTo = msPlayed + ms > msTotal ? msTotal : msPlayed + ms;
|
||||
downloadService.seekTo(seekTo);
|
||||
mediaPlayerController.seekTo(seekTo);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1562,9 +1562,9 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
public boolean onFling(final MotionEvent e1, final MotionEvent e2, final float velocityX, final float velocityY)
|
||||
{
|
||||
|
||||
final DownloadService downloadService = getDownloadService();
|
||||
final MediaPlayerController mediaPlayerController = getMediaPlayerController();
|
||||
|
||||
if (downloadService == null || e1 == null || e2 == null)
|
||||
if (mediaPlayerController == null || e1 == null || e2 == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1582,7 +1582,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
warnIfNetworkOrStorageUnavailable();
|
||||
if (downloader.getValue().getCurrentPlayingIndex() < downloader.getValue().downloadList.size() - 1)
|
||||
{
|
||||
downloadService.next();
|
||||
mediaPlayerController.next();
|
||||
onCurrentChanged();
|
||||
onSliderProgressChanged();
|
||||
}
|
||||
|
@ -1593,7 +1593,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
if (e2X - e1X > swipeDistance && absX > swipeVelocity)
|
||||
{
|
||||
warnIfNetworkOrStorageUnavailable();
|
||||
downloadService.previous();
|
||||
mediaPlayerController.previous();
|
||||
onCurrentChanged();
|
||||
onSliderProgressChanged();
|
||||
return true;
|
||||
|
@ -1603,7 +1603,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
if (e2Y - e1Y > swipeDistance && absY > swipeVelocity)
|
||||
{
|
||||
warnIfNetworkOrStorageUnavailable();
|
||||
downloadService.seekTo(downloadService.getPlayerPosition() + 30000);
|
||||
mediaPlayerController.seekTo(mediaPlayerController.getPlayerPosition() + 30000);
|
||||
onSliderProgressChanged();
|
||||
return true;
|
||||
}
|
||||
|
@ -1612,7 +1612,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
if (e1Y - e2Y > swipeDistance && absY > swipeVelocity)
|
||||
{
|
||||
warnIfNetworkOrStorageUnavailable();
|
||||
downloadService.seekTo(downloadService.getPlayerPosition() - 8000);
|
||||
mediaPlayerController.seekTo(mediaPlayerController.getPlayerPosition() - 8000);
|
||||
onSliderProgressChanged();
|
||||
return true;
|
||||
}
|
||||
|
@ -1663,6 +1663,6 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
|
|||
return;
|
||||
|
||||
displaySongRating();
|
||||
getDownloadService().setSongRating(rating);
|
||||
getMediaPlayerController().setSongRating(rating);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,8 +32,7 @@ import android.widget.TextView;
|
|||
|
||||
import org.moire.ultrasonic.R;
|
||||
import org.moire.ultrasonic.audiofx.EqualizerController;
|
||||
import org.moire.ultrasonic.service.DownloadService;
|
||||
import org.moire.ultrasonic.service.DownloadServiceImpl;
|
||||
import org.moire.ultrasonic.service.MediaPlayerController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -56,7 +55,7 @@ public class EqualizerActivity extends ResultActivity
|
|||
private EqualizerController equalizerController;
|
||||
private Equalizer equalizer;
|
||||
|
||||
private Lazy<DownloadServiceImpl> downloadServiceImpl = inject(DownloadServiceImpl.class);
|
||||
private Lazy<MediaPlayerController> mediaPlayerControllerLazy = inject(MediaPlayerController.class);
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle)
|
||||
|
@ -129,7 +128,7 @@ public class EqualizerActivity extends ResultActivity
|
|||
|
||||
private void setup()
|
||||
{
|
||||
equalizerController = downloadServiceImpl.getValue().getEqualizerController();
|
||||
equalizerController = mediaPlayerControllerLazy.getValue().getEqualizerController();
|
||||
equalizer = equalizerController.getEqualizer();
|
||||
|
||||
initEqualizer();
|
||||
|
|
|
@ -34,11 +34,8 @@ import android.widget.ListView;
|
|||
import android.widget.TextView;
|
||||
|
||||
import org.moire.ultrasonic.R;
|
||||
import org.moire.ultrasonic.service.DownloadService;
|
||||
import org.moire.ultrasonic.service.DownloadServiceImpl;
|
||||
import org.moire.ultrasonic.service.DownloadServiceLifecycleSupport;
|
||||
import org.moire.ultrasonic.service.ExternalStorageMonitor;
|
||||
import org.moire.ultrasonic.service.MediaPlayerService;
|
||||
import org.moire.ultrasonic.service.MediaPlayerController;
|
||||
import org.moire.ultrasonic.service.MediaPlayerLifecycleSupport;
|
||||
import org.moire.ultrasonic.service.MusicService;
|
||||
import org.moire.ultrasonic.service.MusicServiceFactory;
|
||||
import org.moire.ultrasonic.util.Constants;
|
||||
|
@ -73,7 +70,7 @@ public class MainActivity extends SubsonicTabActivity
|
|||
private static boolean infoDialogDisplayed;
|
||||
private static boolean shouldUseId3;
|
||||
|
||||
private Lazy<DownloadServiceLifecycleSupport> lifecycleSupport = inject(DownloadServiceLifecycleSupport.class);
|
||||
private Lazy<MediaPlayerLifecycleSupport> lifecycleSupport = inject(MediaPlayerLifecycleSupport.class);
|
||||
|
||||
/**
|
||||
* Called when the activity is first created.
|
||||
|
@ -87,9 +84,9 @@ public class MainActivity extends SubsonicTabActivity
|
|||
{
|
||||
setResult(Constants.RESULT_CLOSE_ALL);
|
||||
|
||||
if (getDownloadService() != null)
|
||||
if (getMediaPlayerController() != null)
|
||||
{
|
||||
getDownloadService().stopJukeboxService();
|
||||
getMediaPlayerController().stopJukeboxService();
|
||||
}
|
||||
|
||||
if (getImageLoader() != null)
|
||||
|
@ -464,7 +461,7 @@ public class MainActivity extends SubsonicTabActivity
|
|||
|
||||
private void setActiveServer(final int instance)
|
||||
{
|
||||
final DownloadService service = getDownloadService();
|
||||
final MediaPlayerController service = getMediaPlayerController();
|
||||
|
||||
if (Util.getActiveServer(this) != instance)
|
||||
{
|
||||
|
|
|
@ -37,7 +37,7 @@ import org.moire.ultrasonic.domain.MusicDirectory;
|
|||
import org.moire.ultrasonic.domain.MusicDirectory.Entry;
|
||||
import org.moire.ultrasonic.domain.SearchCriteria;
|
||||
import org.moire.ultrasonic.domain.SearchResult;
|
||||
import org.moire.ultrasonic.service.DownloadService;
|
||||
import org.moire.ultrasonic.service.MediaPlayerController;
|
||||
import org.moire.ultrasonic.service.MusicService;
|
||||
import org.moire.ultrasonic.service.MusicServiceFactory;
|
||||
import org.moire.ultrasonic.util.BackgroundTask;
|
||||
|
@ -322,7 +322,7 @@ public class SearchActivity extends SubsonicTabActivity
|
|||
{
|
||||
songs.add(entry);
|
||||
Util.toast(SearchActivity.this, getResources().getQuantityString(R.plurals.select_album_n_songs_unpinned, songs.size(), songs.size()));
|
||||
getDownloadService().unpin(songs);
|
||||
getMediaPlayerController().unpin(songs);
|
||||
}
|
||||
break;
|
||||
case R.id.menu_item_share:
|
||||
|
@ -341,7 +341,7 @@ public class SearchActivity extends SubsonicTabActivity
|
|||
|
||||
private void downloadBackground(final boolean save, final List<MusicDirectory.Entry> songs)
|
||||
{
|
||||
if (getDownloadService() == null)
|
||||
if (getMediaPlayerController() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -352,7 +352,7 @@ public class SearchActivity extends SubsonicTabActivity
|
|||
public void run()
|
||||
{
|
||||
warnIfNetworkOrStorageUnavailable();
|
||||
getDownloadService().downloadBackground(songs, save);
|
||||
getMediaPlayerController().downloadBackground(songs, save);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -508,19 +508,19 @@ public class SearchActivity extends SubsonicTabActivity
|
|||
|
||||
private void onSongSelected(MusicDirectory.Entry song, boolean save, boolean append, boolean autoplay, boolean playNext)
|
||||
{
|
||||
DownloadService downloadService = getDownloadService();
|
||||
if (downloadService != null)
|
||||
MediaPlayerController mediaPlayerController = getMediaPlayerController();
|
||||
if (mediaPlayerController != null)
|
||||
{
|
||||
if (!append && !playNext)
|
||||
{
|
||||
downloadService.clear();
|
||||
mediaPlayerController.clear();
|
||||
}
|
||||
|
||||
downloadService.download(Collections.singletonList(song), save, false, playNext, false, false);
|
||||
mediaPlayerController.download(Collections.singletonList(song), save, false, playNext, false, false);
|
||||
|
||||
if (autoplay)
|
||||
{
|
||||
downloadService.play(downloader.getValue().downloadList.size() - 1);
|
||||
mediaPlayerController.play(downloader.getValue().downloadList.size() - 1);
|
||||
}
|
||||
|
||||
Util.toast(SearchActivity.this, getResources().getQuantityString(R.plurals.select_album_n_songs_added, 1, 1));
|
||||
|
|
|
@ -1010,7 +1010,7 @@ public class SelectAlbumActivity extends SubsonicTabActivity
|
|||
|
||||
private void enableButtons()
|
||||
{
|
||||
if (getDownloadService() == null)
|
||||
if (getMediaPlayerController() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -1061,7 +1061,7 @@ public class SelectAlbumActivity extends SubsonicTabActivity
|
|||
|
||||
private void downloadBackground(final boolean save, final List<MusicDirectory.Entry> songs)
|
||||
{
|
||||
if (getDownloadService() == null)
|
||||
if (getMediaPlayerController() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -1072,7 +1072,7 @@ public class SelectAlbumActivity extends SubsonicTabActivity
|
|||
public void run()
|
||||
{
|
||||
warnIfNetworkOrStorageUnavailable();
|
||||
getDownloadService().downloadBackground(songs, save);
|
||||
getMediaPlayerController().downloadBackground(songs, save);
|
||||
|
||||
if (save)
|
||||
{
|
||||
|
@ -1098,19 +1098,19 @@ public class SelectAlbumActivity extends SubsonicTabActivity
|
|||
songs = getSelectedSongs(albumListView);
|
||||
}
|
||||
|
||||
if (getDownloadService() != null)
|
||||
if (getMediaPlayerController() != null)
|
||||
{
|
||||
getDownloadService().delete(songs);
|
||||
getMediaPlayerController().delete(songs);
|
||||
}
|
||||
}
|
||||
|
||||
private void unpin()
|
||||
{
|
||||
if (getDownloadService() != null)
|
||||
if (getMediaPlayerController() != null)
|
||||
{
|
||||
List<MusicDirectory.Entry> songs = getSelectedSongs(albumListView);
|
||||
Util.toast(SelectAlbumActivity.this, getResources().getQuantityString(R.plurals.select_album_n_songs_unpinned, songs.size(), songs.size()));
|
||||
getDownloadService().unpin(songs);
|
||||
getMediaPlayerController().unpin(songs);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -76,10 +76,10 @@ public class SubsonicTabActivity extends ResultActivity implements OnClickListen
|
|||
private static final String STATE_ACTIVE_POSITION = "org.moire.ultrasonic.activePosition";
|
||||
private static final int DIALOG_ASK_FOR_SHARE_DETAILS = 102;
|
||||
|
||||
private Lazy<DownloadServiceImpl> downloadServiceImpl = inject(DownloadServiceImpl.class);
|
||||
private Lazy<DownloadServiceLifecycleSupport> lifecycleSupport = inject(DownloadServiceLifecycleSupport.class);
|
||||
private Lazy<MediaPlayerController> mediaPlayerControllerLazy = inject(MediaPlayerController.class);
|
||||
private Lazy<MediaPlayerLifecycleSupport> lifecycleSupport = inject(MediaPlayerLifecycleSupport.class);
|
||||
protected Lazy<Downloader> downloader = inject(Downloader.class);
|
||||
protected Lazy<Player> player = inject(Player.class);
|
||||
protected Lazy<LocalMediaPlayer> localMediaPlayer = inject(LocalMediaPlayer.class);
|
||||
|
||||
|
||||
public MenuDrawer menuDrawer;
|
||||
|
@ -211,11 +211,11 @@ public class SubsonicTabActivity extends ResultActivity implements OnClickListen
|
|||
boolean isVolumeDown = keyCode == KeyEvent.KEYCODE_VOLUME_DOWN;
|
||||
boolean isVolumeUp = keyCode == KeyEvent.KEYCODE_VOLUME_UP;
|
||||
boolean isVolumeAdjust = isVolumeDown || isVolumeUp;
|
||||
boolean isJukebox = getDownloadService() != null && getDownloadService().isJukeboxEnabled();
|
||||
boolean isJukebox = getMediaPlayerController() != null && getMediaPlayerController().isJukeboxEnabled();
|
||||
|
||||
if (isVolumeAdjust && isJukebox)
|
||||
{
|
||||
getDownloadService().adjustJukeboxVolume(isVolumeUp);
|
||||
getMediaPlayerController().adjustJukeboxVolume(isVolumeUp);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -265,16 +265,16 @@ public class SubsonicTabActivity extends ResultActivity implements OnClickListen
|
|||
|
||||
if (nowPlayingView != null)
|
||||
{
|
||||
PlayerState playerState = downloadServiceImpl.getValue().getPlayerState();
|
||||
PlayerState playerState = mediaPlayerControllerLazy.getValue().getPlayerState();
|
||||
|
||||
if (playerState.equals(PlayerState.PAUSED) || playerState.equals(PlayerState.STARTED))
|
||||
{
|
||||
DownloadFile file = player.getValue().currentPlaying;
|
||||
DownloadFile file = localMediaPlayer.getValue().currentPlaying;
|
||||
|
||||
if (file != null)
|
||||
{
|
||||
final Entry song = file.getSong();
|
||||
showNowPlaying(SubsonicTabActivity.this, downloadServiceImpl.getValue(), song, playerState);
|
||||
showNowPlaying(SubsonicTabActivity.this, mediaPlayerControllerLazy.getValue(), song, playerState);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -309,9 +309,9 @@ public class SubsonicTabActivity extends ResultActivity implements OnClickListen
|
|||
}
|
||||
}
|
||||
|
||||
private void showNowPlaying(final Context context, final DownloadService downloadService, final Entry song, final PlayerState playerState)
|
||||
private void showNowPlaying(final Context context, final MediaPlayerController mediaPlayerController, final Entry song, final PlayerState playerState)
|
||||
{
|
||||
if (context == null || downloadService == null || song == null || playerState == null)
|
||||
if (context == null || mediaPlayerController == null || song == null || playerState == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -390,7 +390,7 @@ public class SubsonicTabActivity extends ResultActivity implements OnClickListen
|
|||
|
||||
ImageView nowPlayingControlPlay = (ImageView) nowPlayingView.findViewById(R.id.now_playing_control_play);
|
||||
|
||||
SwipeDetector swipeDetector = new SwipeDetector(SubsonicTabActivity.this, downloadService);
|
||||
SwipeDetector swipeDetector = new SwipeDetector(SubsonicTabActivity.this, mediaPlayerController);
|
||||
setOnTouchListenerOnUiThread(nowPlayingView, swipeDetector);
|
||||
|
||||
setOnClickListenerOnUiThread(nowPlayingView, new OnClickListener()
|
||||
|
@ -406,7 +406,7 @@ public class SubsonicTabActivity extends ResultActivity implements OnClickListen
|
|||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
downloadService.togglePlayPause();
|
||||
mediaPlayerController.togglePlayPause();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -765,9 +765,9 @@ public class SubsonicTabActivity extends ResultActivity implements OnClickListen
|
|||
}
|
||||
}
|
||||
|
||||
public DownloadService getDownloadService()
|
||||
public MediaPlayerController getMediaPlayerController()
|
||||
{
|
||||
return downloadServiceImpl.getValue();
|
||||
return mediaPlayerControllerLazy.getValue();
|
||||
}
|
||||
|
||||
protected void warnIfNetworkOrStorageUnavailable()
|
||||
|
@ -818,7 +818,7 @@ public class SubsonicTabActivity extends ResultActivity implements OnClickListen
|
|||
|
||||
void download(final boolean append, final boolean save, final boolean autoPlay, final boolean playNext, final boolean shuffle, final List<Entry> songs)
|
||||
{
|
||||
if (getDownloadService() == null)
|
||||
if (getMediaPlayerController() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -830,16 +830,16 @@ public class SubsonicTabActivity extends ResultActivity implements OnClickListen
|
|||
{
|
||||
if (!append && !playNext)
|
||||
{
|
||||
getDownloadService().clear();
|
||||
getMediaPlayerController().clear();
|
||||
}
|
||||
|
||||
warnIfNetworkOrStorageUnavailable();
|
||||
getDownloadService().download(songs, save, autoPlay, playNext, shuffle, false);
|
||||
getMediaPlayerController().download(songs, save, autoPlay, playNext, shuffle, false);
|
||||
String playlistName = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME);
|
||||
|
||||
if (playlistName != null)
|
||||
{
|
||||
getDownloadService().setSuggestedPlaylistName(playlistName);
|
||||
getMediaPlayerController().setSuggestedPlaylistName(playlistName);
|
||||
}
|
||||
|
||||
if (autoPlay)
|
||||
|
@ -994,23 +994,23 @@ public class SubsonicTabActivity extends ResultActivity implements OnClickListen
|
|||
Collections.sort(songs, new EntryByDiscAndTrackComparator());
|
||||
}
|
||||
|
||||
DownloadService downloadService = getDownloadService();
|
||||
if (!songs.isEmpty() && downloadService != null)
|
||||
MediaPlayerController mediaPlayerController = getMediaPlayerController();
|
||||
if (!songs.isEmpty() && mediaPlayerController != null)
|
||||
{
|
||||
if (!append && !playNext && !unpin && !background)
|
||||
{
|
||||
downloadService.clear();
|
||||
mediaPlayerController.clear();
|
||||
}
|
||||
warnIfNetworkOrStorageUnavailable();
|
||||
if (!background)
|
||||
{
|
||||
if (unpin)
|
||||
{
|
||||
downloadService.unpin(songs);
|
||||
mediaPlayerController.unpin(songs);
|
||||
}
|
||||
else
|
||||
{
|
||||
downloadService.download(songs, save, autoplay, playNext, shuffle, false);
|
||||
mediaPlayerController.download(songs, save, autoplay, playNext, shuffle, false);
|
||||
if (!append && Util.getShouldTransitionOnPlaybackPreference(SubsonicTabActivity.this))
|
||||
{
|
||||
startActivityForResultWithoutTransition(SubsonicTabActivity.this, DownloadActivity.class);
|
||||
|
@ -1021,11 +1021,11 @@ public class SubsonicTabActivity extends ResultActivity implements OnClickListen
|
|||
{
|
||||
if (unpin)
|
||||
{
|
||||
downloadService.unpin(songs);
|
||||
mediaPlayerController.unpin(songs);
|
||||
}
|
||||
else
|
||||
{
|
||||
downloadService.downloadBackground(songs, save);
|
||||
mediaPlayerController.downloadBackground(songs, save);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1353,15 +1353,15 @@ public class SubsonicTabActivity extends ResultActivity implements OnClickListen
|
|||
|
||||
protected class SwipeDetector implements OnTouchListener
|
||||
{
|
||||
public SwipeDetector(SubsonicTabActivity activity, final DownloadService downloadService)
|
||||
public SwipeDetector(SubsonicTabActivity activity, final MediaPlayerController mediaPlayerController)
|
||||
{
|
||||
this.downloadService = downloadService;
|
||||
this.mediaPlayerController = mediaPlayerController;
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
private static final int MIN_DISTANCE = 30;
|
||||
private float downX, downY, upX, upY;
|
||||
private DownloadService downloadService;
|
||||
private MediaPlayerController mediaPlayerController;
|
||||
private SubsonicTabActivity activity;
|
||||
|
||||
@Override
|
||||
|
@ -1388,12 +1388,12 @@ public class SubsonicTabActivity extends ResultActivity implements OnClickListen
|
|||
// left or right
|
||||
if (deltaX < 0)
|
||||
{
|
||||
downloadService.previous();
|
||||
mediaPlayerController.previous();
|
||||
return false;
|
||||
}
|
||||
if (deltaX > 0)
|
||||
{
|
||||
downloadService.next();
|
||||
mediaPlayerController.next();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,7 @@ import org.moire.ultrasonic.activity.SubsonicTabActivity;
|
|||
import org.moire.ultrasonic.featureflags.Feature;
|
||||
import org.moire.ultrasonic.featureflags.FeatureStorage;
|
||||
import org.moire.ultrasonic.provider.SearchSuggestionProvider;
|
||||
import org.moire.ultrasonic.service.DownloadService;
|
||||
import org.moire.ultrasonic.service.DownloadServiceImpl;
|
||||
import org.moire.ultrasonic.service.MediaPlayerController;
|
||||
import org.moire.ultrasonic.util.*;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -66,7 +65,7 @@ public class SettingsFragment extends PreferenceFragment
|
|||
private SharedPreferences settings;
|
||||
private int activeServers;
|
||||
|
||||
private Lazy<DownloadServiceImpl> downloadServiceImpl = inject(DownloadServiceImpl.class);
|
||||
private Lazy<MediaPlayerController> mediaPlayerControllerLazy = inject(MediaPlayerController.class);
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
|
@ -407,6 +406,6 @@ public class SettingsFragment extends PreferenceFragment
|
|||
}
|
||||
|
||||
// Clear download queue.
|
||||
downloadServiceImpl.getValue().clear();
|
||||
mediaPlayerControllerLazy.getValue().clear();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import org.moire.ultrasonic.R;
|
|||
import org.moire.ultrasonic.activity.DownloadActivity;
|
||||
import org.moire.ultrasonic.activity.MainActivity;
|
||||
import org.moire.ultrasonic.domain.MusicDirectory;
|
||||
import org.moire.ultrasonic.service.DownloadService;
|
||||
import org.moire.ultrasonic.service.MediaPlayerController;
|
||||
import org.moire.ultrasonic.util.Constants;
|
||||
import org.moire.ultrasonic.util.FileUtil;
|
||||
|
||||
|
@ -67,7 +67,7 @@ public class UltraSonicAppWidgetProvider extends AppWidgetProvider
|
|||
}
|
||||
|
||||
/**
|
||||
* Handle a change notification coming over from {@link DownloadService}
|
||||
* Handle a change notification coming over from {@link MediaPlayerController}
|
||||
*/
|
||||
public void notifyChange(Context context, MusicDirectory.Entry currentSong, boolean playing, boolean setAlbum)
|
||||
{
|
||||
|
|
|
@ -5,9 +5,9 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
|
||||
import org.moire.ultrasonic.domain.MusicDirectory.Entry;
|
||||
import org.moire.ultrasonic.service.DownloadServiceImpl;
|
||||
import org.moire.ultrasonic.service.MediaPlayerController;
|
||||
import org.moire.ultrasonic.service.Downloader;
|
||||
import org.moire.ultrasonic.service.Player;
|
||||
import org.moire.ultrasonic.service.LocalMediaPlayer;
|
||||
|
||||
import kotlin.Lazy;
|
||||
|
||||
|
@ -16,19 +16,19 @@ import static org.koin.java.standalone.KoinJavaComponent.inject;
|
|||
public class A2dpIntentReceiver extends BroadcastReceiver
|
||||
{
|
||||
private static final String PLAYSTATUS_RESPONSE = "com.android.music.playstatusresponse";
|
||||
private Lazy<DownloadServiceImpl> downloadServiceImpl = inject(DownloadServiceImpl.class);
|
||||
private Lazy<MediaPlayerController> mediaPlayerControllerLazy = inject(MediaPlayerController.class);
|
||||
private Lazy<Downloader> downloader = inject(Downloader.class);
|
||||
protected Lazy<Player> player = inject(Player.class);
|
||||
protected Lazy<LocalMediaPlayer> localMediaPlayer = inject(LocalMediaPlayer.class);
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
if (player.getValue().currentPlaying == null)
|
||||
if (localMediaPlayer.getValue().currentPlaying == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Entry song = player.getValue().currentPlaying.getSong();
|
||||
Entry song = localMediaPlayer.getValue().currentPlaying.getSong();
|
||||
|
||||
if (song == null)
|
||||
{
|
||||
|
@ -38,7 +38,7 @@ public class A2dpIntentReceiver extends BroadcastReceiver
|
|||
Intent avrcpIntent = new Intent(PLAYSTATUS_RESPONSE);
|
||||
|
||||
Integer duration = song.getDuration();
|
||||
int playerPosition = downloadServiceImpl.getValue().getPlayerPosition();
|
||||
int playerPosition = mediaPlayerControllerLazy.getValue().getPlayerPosition();
|
||||
int listSize = downloader.getValue().getDownloads().size();
|
||||
|
||||
if (duration != null)
|
||||
|
@ -49,7 +49,7 @@ public class A2dpIntentReceiver extends BroadcastReceiver
|
|||
avrcpIntent.putExtra("position", (long) playerPosition);
|
||||
avrcpIntent.putExtra("ListSize", (long) listSize);
|
||||
|
||||
switch (downloadServiceImpl.getValue().getPlayerState())
|
||||
switch (mediaPlayerControllerLazy.getValue().getPlayerState())
|
||||
{
|
||||
case STARTED:
|
||||
avrcpIntent.putExtra("playing", true);
|
||||
|
|
|
@ -25,7 +25,7 @@ import android.os.Bundle;
|
|||
import android.os.Parcelable;
|
||||
import android.util.Log;
|
||||
|
||||
import org.moire.ultrasonic.service.DownloadServiceLifecycleSupport;
|
||||
import org.moire.ultrasonic.service.MediaPlayerLifecycleSupport;
|
||||
import org.moire.ultrasonic.util.Constants;
|
||||
import org.moire.ultrasonic.util.Util;
|
||||
|
||||
|
@ -39,7 +39,7 @@ import static org.koin.java.standalone.KoinJavaComponent.inject;
|
|||
public class MediaButtonIntentReceiver extends BroadcastReceiver
|
||||
{
|
||||
private static final String TAG = MediaButtonIntentReceiver.class.getSimpleName();
|
||||
private Lazy<DownloadServiceLifecycleSupport> lifecycleSupport = inject(DownloadServiceLifecycleSupport.class);
|
||||
private Lazy<MediaPlayerLifecycleSupport> lifecycleSupport = inject(MediaPlayerLifecycleSupport.class);
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
|
|
|
@ -26,29 +26,31 @@ public class Downloader
|
|||
{
|
||||
private static final String TAG = Downloader.class.getSimpleName();
|
||||
|
||||
private final ShufflePlayBuffer shufflePlayBuffer;
|
||||
private final ExternalStorageMonitor externalStorageMonitor;
|
||||
private final Player player;
|
||||
public Lazy<JukeboxService> jukeboxService = inject(JukeboxService.class);
|
||||
|
||||
public final List<DownloadFile> downloadList = new ArrayList<>();
|
||||
public final List<DownloadFile> backgroundDownloadList = new ArrayList<>();
|
||||
public DownloadFile currentDownloading;
|
||||
|
||||
private final ShufflePlayBuffer shufflePlayBuffer;
|
||||
private final ExternalStorageMonitor externalStorageMonitor;
|
||||
private final LocalMediaPlayer localMediaPlayer;
|
||||
private final Context context;
|
||||
|
||||
// TODO: This is a circular reference, try to remove
|
||||
private Lazy<JukeboxMediaPlayer> jukeboxMediaPlayer = inject(JukeboxMediaPlayer.class);
|
||||
|
||||
private final List<DownloadFile> cleanupCandidates = new ArrayList<>();
|
||||
private final LRUCache<MusicDirectory.Entry, DownloadFile> downloadFileCache = new LRUCache<>(100);
|
||||
|
||||
public DownloadFile currentDownloading;
|
||||
public static long revision;
|
||||
|
||||
private ScheduledExecutorService executorService;
|
||||
private Context context;
|
||||
private long revision;
|
||||
|
||||
|
||||
public Downloader(Context context, ShufflePlayBuffer shufflePlayBuffer, ExternalStorageMonitor externalStorageMonitor,
|
||||
Player player)
|
||||
LocalMediaPlayer localMediaPlayer)
|
||||
{
|
||||
this.context = context;
|
||||
this.shufflePlayBuffer = shufflePlayBuffer;
|
||||
this.externalStorageMonitor = externalStorageMonitor;
|
||||
this.player = player;
|
||||
this.localMediaPlayer = localMediaPlayer;
|
||||
}
|
||||
|
||||
public void onCreate()
|
||||
|
@ -78,6 +80,8 @@ public class Downloader
|
|||
public void onDestroy()
|
||||
{
|
||||
executorService.shutdown();
|
||||
clear();
|
||||
clearBackground();
|
||||
Log.i(TAG, "Downloader destroyed");
|
||||
}
|
||||
|
||||
|
@ -93,7 +97,7 @@ public class Downloader
|
|||
checkShufflePlay(context);
|
||||
}
|
||||
|
||||
if (jukeboxService.getValue().isEnabled() || !Util.isNetworkConnected(context))
|
||||
if (jukeboxMediaPlayer.getValue().isEnabled() || !Util.isNetworkConnected(context))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -104,7 +108,7 @@ public class Downloader
|
|||
}
|
||||
|
||||
// Need to download current playing?
|
||||
if (player.currentPlaying != null && player.currentPlaying != currentDownloading && !player.currentPlaying.isWorkDone())
|
||||
if (localMediaPlayer.currentPlaying != null && localMediaPlayer.currentPlaying != currentDownloading && !localMediaPlayer.currentPlaying.isWorkDone())
|
||||
{
|
||||
// Cancel current download, if necessary.
|
||||
if (currentDownloading != null)
|
||||
|
@ -112,7 +116,7 @@ public class Downloader
|
|||
currentDownloading.cancelDownload();
|
||||
}
|
||||
|
||||
currentDownloading = player.currentPlaying;
|
||||
currentDownloading = localMediaPlayer.currentPlaying;
|
||||
currentDownloading.download();
|
||||
cleanupCandidates.add(currentDownloading);
|
||||
|
||||
|
@ -138,7 +142,7 @@ public class Downloader
|
|||
|
||||
if (n != 0)
|
||||
{
|
||||
int start = player.currentPlaying == null ? 0 : getCurrentPlayingIndex();
|
||||
int start = localMediaPlayer.currentPlaying == null ? 0 : getCurrentPlayingIndex();
|
||||
if (start == -1) start = 0;
|
||||
|
||||
int i = start;
|
||||
|
@ -154,12 +158,12 @@ public class Downloader
|
|||
cleanupCandidates.add(currentDownloading);
|
||||
if (i == (start + 1))
|
||||
{
|
||||
player.setNextPlayerState(DOWNLOADING);
|
||||
localMediaPlayer.setNextPlayerState(DOWNLOADING);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (player.currentPlaying != downloadFile)
|
||||
else if (localMediaPlayer.currentPlaying != downloadFile)
|
||||
{
|
||||
preloaded++;
|
||||
}
|
||||
|
@ -201,7 +205,7 @@ public class Downloader
|
|||
|
||||
public synchronized int getCurrentPlayingIndex()
|
||||
{
|
||||
return downloadList.indexOf(player.currentPlaying);
|
||||
return downloadList.indexOf(localMediaPlayer.currentPlaying);
|
||||
}
|
||||
|
||||
public long getDownloadListDuration()
|
||||
|
@ -237,11 +241,6 @@ public class Downloader
|
|||
return temp;
|
||||
}
|
||||
|
||||
public List<DownloadFile> getBackgroundDownloads()
|
||||
{
|
||||
return backgroundDownloadList;
|
||||
}
|
||||
|
||||
public long getDownloadListUpdateRevision()
|
||||
{
|
||||
return revision;
|
||||
|
@ -258,7 +257,7 @@ public class Downloader
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized void clearBackground()
|
||||
private void clearBackground()
|
||||
{
|
||||
if (currentDownloading != null && backgroundDownloadList.contains(currentDownloading))
|
||||
{
|
||||
|
@ -337,25 +336,14 @@ public class Downloader
|
|||
public synchronized void shuffle()
|
||||
{
|
||||
Collections.shuffle(downloadList);
|
||||
if (player.currentPlaying != null)
|
||||
if (localMediaPlayer.currentPlaying != null)
|
||||
{
|
||||
downloadList.remove(getCurrentPlayingIndex());
|
||||
downloadList.add(0, player.currentPlaying);
|
||||
downloadList.add(0, localMediaPlayer.currentPlaying);
|
||||
}
|
||||
revision++;
|
||||
}
|
||||
|
||||
public synchronized void setFirstPlaying()
|
||||
{
|
||||
if (player.currentPlaying == null && downloadList.size() > 0)
|
||||
{
|
||||
player.currentPlaying = downloadList.get(0);
|
||||
player.currentPlaying.setPlaying(true);
|
||||
}
|
||||
|
||||
checkDownloads();
|
||||
}
|
||||
|
||||
public synchronized DownloadFile getDownloadFileForSong(MusicDirectory.Entry song)
|
||||
{
|
||||
for (DownloadFile downloadFile : downloadList)
|
||||
|
@ -388,7 +376,7 @@ public class Downloader
|
|||
while (iterator.hasNext())
|
||||
{
|
||||
DownloadFile downloadFile = iterator.next();
|
||||
if (downloadFile != player.currentPlaying && downloadFile != currentDownloading)
|
||||
if (downloadFile != localMediaPlayer.currentPlaying && downloadFile != currentDownloading)
|
||||
{
|
||||
if (downloadFile.cleanup())
|
||||
{
|
||||
|
@ -418,7 +406,7 @@ public class Downloader
|
|||
}
|
||||
}
|
||||
|
||||
int currIndex = player.currentPlaying == null ? 0 : getCurrentPlayingIndex();
|
||||
int currIndex = localMediaPlayer.currentPlaying == null ? 0 : getCurrentPlayingIndex();
|
||||
|
||||
// Only shift playlist if playing song #5 or later.
|
||||
if (currIndex > 4)
|
||||
|
@ -435,19 +423,19 @@ public class Downloader
|
|||
|
||||
if (revisionBefore != revision)
|
||||
{
|
||||
jukeboxService.getValue().updatePlaylist();
|
||||
jukeboxMediaPlayer.getValue().updatePlaylist();
|
||||
}
|
||||
|
||||
if (wasEmpty && !downloadList.isEmpty())
|
||||
{
|
||||
if (jukeboxService.getValue().isEnabled())
|
||||
if (jukeboxMediaPlayer.getValue().isEnabled())
|
||||
{
|
||||
jukeboxService.getValue().skip(0, 0);
|
||||
player.setPlayerState(STARTED);
|
||||
jukeboxMediaPlayer.getValue().skip(0, 0);
|
||||
localMediaPlayer.setPlayerState(STARTED);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.play(downloadList.get(0));
|
||||
localMediaPlayer.play(downloadList.get(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import android.view.View;
|
|||
import android.widget.ProgressBar;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.moire.ultrasonic.R;
|
||||
import org.moire.ultrasonic.api.subsonic.ApiNotSupportedException;
|
||||
import org.moire.ultrasonic.domain.JukeboxStatus;
|
||||
|
@ -54,9 +55,9 @@ import static org.koin.java.standalone.KoinJavaComponent.inject;
|
|||
* @author Sindre Mehus
|
||||
* @version $Id$
|
||||
*/
|
||||
public class JukeboxService
|
||||
public class JukeboxMediaPlayer
|
||||
{
|
||||
private static final String TAG = JukeboxService.class.getSimpleName();
|
||||
private static final String TAG = JukeboxMediaPlayer.class.getSimpleName();
|
||||
private static final long STATUS_UPDATE_INTERVAL_SECONDS = 5L;
|
||||
|
||||
private final TaskQueue tasks = new TaskQueue();
|
||||
|
@ -72,7 +73,7 @@ public class JukeboxService
|
|||
private Context context;
|
||||
|
||||
// TODO: These create circular references, try to refactor
|
||||
private Lazy<DownloadServiceImpl> downloadServiceImpl = inject(DownloadServiceImpl.class);
|
||||
private Lazy<MediaPlayerControllerImpl> mediaPlayerControllerLazy = inject(MediaPlayerControllerImpl.class);
|
||||
private final Downloader downloader;
|
||||
|
||||
// TODO: Report warning if queue fills up.
|
||||
|
@ -81,7 +82,7 @@ public class JukeboxService
|
|||
// TODO: Persist RC state?
|
||||
// TODO: Minimize status updates.
|
||||
|
||||
public JukeboxService(Context context, Downloader downloader)
|
||||
public JukeboxMediaPlayer(Context context, Downloader downloader)
|
||||
{
|
||||
this.context = context;
|
||||
this.downloader = downloader;
|
||||
|
@ -187,7 +188,7 @@ public class JukeboxService
|
|||
|
||||
if (index != null && index != -1 && index != downloader.getCurrentPlayingIndex())
|
||||
{
|
||||
downloadServiceImpl.getValue().setCurrentPlaying(index);
|
||||
mediaPlayerControllerLazy.getValue().setCurrentPlaying(index);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -224,7 +225,7 @@ public class JukeboxService
|
|||
}
|
||||
});
|
||||
|
||||
downloadServiceImpl.getValue().setJukeboxEnabled(false);
|
||||
mediaPlayerControllerLazy.getValue().setJukeboxEnabled(false);
|
||||
}
|
||||
|
||||
public void updatePlaylist()
|
||||
|
@ -258,7 +259,7 @@ public class JukeboxService
|
|||
}
|
||||
|
||||
tasks.add(new Skip(index, offsetSeconds));
|
||||
downloadServiceImpl.getValue().setPlayerState(PlayerState.STARTED);
|
||||
mediaPlayerControllerLazy.getValue().setPlayerState(PlayerState.STARTED);
|
||||
}
|
||||
|
||||
public void stop()
|
||||
|
@ -290,10 +291,8 @@ public class JukeboxService
|
|||
tasks.remove(SetGain.class);
|
||||
tasks.add(new SetGain(gain));
|
||||
|
||||
if (volumeToast == null)
|
||||
{
|
||||
volumeToast = new VolumeToast(context);
|
||||
}
|
||||
if (volumeToast == null) volumeToast = new VolumeToast(context);
|
||||
|
||||
volumeToast.setVolume(gain);
|
||||
}
|
||||
|
||||
|
@ -377,10 +376,11 @@ public class JukeboxService
|
|||
}
|
||||
}
|
||||
|
||||
private abstract class JukeboxTask
|
||||
private abstract static class JukeboxTask
|
||||
{
|
||||
abstract JukeboxStatus execute() throws Exception;
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
|
@ -18,6 +18,7 @@ import android.os.PowerManager;
|
|||
import android.util.Log;
|
||||
import android.widget.SeekBar;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.moire.ultrasonic.activity.DownloadActivity;
|
||||
import org.moire.ultrasonic.audiofx.EqualizerController;
|
||||
import org.moire.ultrasonic.audiofx.VisualizerController;
|
||||
|
@ -32,6 +33,7 @@ import org.moire.ultrasonic.util.Util;
|
|||
|
||||
import java.io.File;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.moire.ultrasonic.domain.PlayerState.COMPLETED;
|
||||
import static org.moire.ultrasonic.domain.PlayerState.DOWNLOADING;
|
||||
|
@ -41,37 +43,9 @@ import static org.moire.ultrasonic.domain.PlayerState.PREPARED;
|
|||
import static org.moire.ultrasonic.domain.PlayerState.PREPARING;
|
||||
import static org.moire.ultrasonic.domain.PlayerState.STARTED;
|
||||
|
||||
public class Player
|
||||
public class LocalMediaPlayer
|
||||
{
|
||||
private static final String TAG = Player.class.getSimpleName();
|
||||
private final Context context;
|
||||
|
||||
private PowerManager.WakeLock wakeLock;
|
||||
public DownloadFile currentPlaying;
|
||||
public DownloadFile nextPlaying;
|
||||
private static boolean nextSetup;
|
||||
private static CancellableTask nextPlayingTask;
|
||||
private MediaPlayer mediaPlayer;
|
||||
|
||||
private MediaPlayer nextMediaPlayer;
|
||||
private Looper mediaPlayerLooper;
|
||||
private Handler mediaPlayerHandler;
|
||||
public static int cachedPosition;
|
||||
private StreamProxy proxy;
|
||||
|
||||
public PlayerState playerState = IDLE;
|
||||
public PlayerState nextPlayerState = IDLE;
|
||||
|
||||
private AudioManager audioManager;
|
||||
public RemoteControlClient remoteControlClient;
|
||||
|
||||
public static boolean equalizerAvailable;
|
||||
public static boolean visualizerAvailable;
|
||||
private EqualizerController equalizerController;
|
||||
private VisualizerController visualizerController;
|
||||
private CancellableTask bufferTask;
|
||||
private PositionCache positionCache;
|
||||
private int secondaryProgress = -1;
|
||||
private static final String TAG = LocalMediaPlayer.class.getSimpleName();
|
||||
|
||||
public Consumer<DownloadFile> onCurrentPlayingChanged;
|
||||
public Consumer<DownloadFile> onSongCompleted;
|
||||
|
@ -79,6 +53,35 @@ public class Player
|
|||
public Runnable onPrepared;
|
||||
public Runnable onNextSongRequested;
|
||||
|
||||
public static boolean equalizerAvailable;
|
||||
public static boolean visualizerAvailable;
|
||||
|
||||
public PlayerState playerState = IDLE;
|
||||
public DownloadFile currentPlaying;
|
||||
public DownloadFile nextPlaying;
|
||||
private PlayerState nextPlayerState = IDLE;
|
||||
private boolean nextSetup;
|
||||
private CancellableTask nextPlayingTask;
|
||||
private PowerManager.WakeLock wakeLock;
|
||||
|
||||
private MediaPlayer mediaPlayer;
|
||||
private MediaPlayer nextMediaPlayer;
|
||||
private Looper mediaPlayerLooper;
|
||||
private Handler mediaPlayerHandler;
|
||||
private int cachedPosition;
|
||||
private StreamProxy proxy;
|
||||
|
||||
private AudioManager audioManager;
|
||||
private RemoteControlClient remoteControlClient;
|
||||
|
||||
private EqualizerController equalizerController;
|
||||
private VisualizerController visualizerController;
|
||||
private CancellableTask bufferTask;
|
||||
private PositionCache positionCache;
|
||||
private int secondaryProgress = -1;
|
||||
|
||||
private final Context context;
|
||||
|
||||
static
|
||||
{
|
||||
try
|
||||
|
@ -105,7 +108,7 @@ public class Player
|
|||
}
|
||||
}
|
||||
|
||||
public Player(Context context)
|
||||
public LocalMediaPlayer(Context context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
@ -134,7 +137,7 @@ public class Player
|
|||
@Override
|
||||
public boolean onError(MediaPlayer mediaPlayer, int what, int more)
|
||||
{
|
||||
handleError(new Exception(String.format("MediaPlayer error: %d (%d)", what, more)));
|
||||
handleError(new Exception(String.format(Locale.getDefault(), "MediaPlayer error: %d (%d)", what, more)));
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
@ -187,7 +190,7 @@ public class Player
|
|||
}
|
||||
}
|
||||
|
||||
Log.i(TAG, "Player created");
|
||||
Log.i(TAG, "LocalMediaPlayer created");
|
||||
}
|
||||
|
||||
public void onDestroy()
|
||||
|
@ -237,7 +240,7 @@ public class Player
|
|||
{
|
||||
}
|
||||
|
||||
Log.i(TAG, "Player destroyed");
|
||||
Log.i(TAG, "LocalMediaPlayer destroyed");
|
||||
}
|
||||
|
||||
public EqualizerController getEqualizerController()
|
||||
|
@ -452,28 +455,18 @@ public class Player
|
|||
|
||||
Log.i(TAG, String.format("In updateRemoteControl, playerState: %s [%d]", playerState, getPlayerPosition()));
|
||||
|
||||
switch (playerState)
|
||||
{
|
||||
case STARTED:
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2)
|
||||
{
|
||||
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
|
||||
}
|
||||
else
|
||||
{
|
||||
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING, getPlayerPosition(), 1.0f);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2)
|
||||
{
|
||||
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
|
||||
}
|
||||
else
|
||||
{
|
||||
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED, getPlayerPosition(), 1.0f);
|
||||
}
|
||||
break;
|
||||
if (playerState == STARTED) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
|
||||
} else {
|
||||
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING, getPlayerPosition(), 1.0f);
|
||||
}
|
||||
} else {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
|
||||
} else {
|
||||
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED, getPlayerPosition(), 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentPlaying != null)
|
||||
|
@ -486,7 +479,7 @@ public class Player
|
|||
String album = currentSong.getAlbum();
|
||||
String title = currentSong.getTitle();
|
||||
Integer currentSongDuration = currentSong.getDuration();
|
||||
Long duration = 0L;
|
||||
long duration = 0L;
|
||||
|
||||
if (currentSongDuration != null) duration = (long) currentSongDuration * 1000;
|
||||
|
||||
|
@ -653,7 +646,8 @@ public class Player
|
|||
proxy.start();
|
||||
}
|
||||
|
||||
dataSource = String.format("http://127.0.0.1:%d/%s", proxy.getPort(), URLEncoder.encode(dataSource, Constants.UTF_8));
|
||||
dataSource = String.format(Locale.getDefault(), "http://127.0.0.1:%d/%s",
|
||||
proxy.getPort(), URLEncoder.encode(dataSource, Constants.UTF_8));
|
||||
Log.i(TAG, String.format("Data Source: %s", dataSource));
|
||||
}
|
||||
else if (proxy != null)
|
||||
|
@ -708,7 +702,7 @@ public class Player
|
|||
DownloadActivity.getProgressBar().setSecondaryProgress(100 * progressBar.getMax());
|
||||
}
|
||||
|
||||
synchronized (Player.this)
|
||||
synchronized (LocalMediaPlayer.this)
|
||||
{
|
||||
if (position != 0)
|
||||
{
|
||||
|
@ -856,15 +850,11 @@ public class Player
|
|||
|
||||
if (Util.getGaplessPlaybackPreference(context) && nextPlaying != null && nextPlayerState == PlayerState.PREPARED)
|
||||
{
|
||||
if (!nextSetup)
|
||||
{
|
||||
playNext();
|
||||
}
|
||||
else
|
||||
if (nextSetup)
|
||||
{
|
||||
nextSetup = false;
|
||||
playNext();
|
||||
}
|
||||
playNext();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -978,6 +968,7 @@ public class Player
|
|||
return completeFileAvailable || size >= expectedFileSize;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
@ -1041,6 +1032,7 @@ public class Player
|
|||
return completeFileAvailable && (playerState == PlayerState.STARTED || playerState == PlayerState.PAUSED);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
|
@ -30,7 +30,7 @@ import java.util.List;
|
|||
* @author Sindre Mehus
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface DownloadService
|
||||
public interface MediaPlayerController
|
||||
{
|
||||
|
||||
void download(List<Entry> songs, boolean save, boolean autoplay, boolean playNext, boolean shuffle, boolean newPlaylist);
|
||||
|
@ -53,10 +53,6 @@ public interface DownloadService
|
|||
|
||||
boolean getShowVisualization();
|
||||
|
||||
boolean getEqualizerAvailable();
|
||||
|
||||
boolean getVisualizerAvailable();
|
||||
|
||||
void setShowVisualization(boolean showVisualization);
|
||||
|
||||
void clear();
|
||||
|
@ -103,8 +99,6 @@ public interface DownloadService
|
|||
|
||||
boolean isJukeboxAvailable();
|
||||
|
||||
boolean isSharingAvailable();
|
||||
|
||||
void setJukeboxEnabled(boolean b);
|
||||
|
||||
void adjustJukeboxVolume(boolean up);
|
||||
|
@ -113,14 +107,10 @@ public interface DownloadService
|
|||
|
||||
void setVolume(float volume);
|
||||
|
||||
void swap(boolean mainList, int from, int to);
|
||||
|
||||
void restore(List<Entry> songs, int currentPlayingIndex, int currentPlayingPosition, boolean autoPlay, boolean newPlaylist);
|
||||
|
||||
void stopJukeboxService();
|
||||
|
||||
void startJukeboxService();
|
||||
|
||||
void updateNotification();
|
||||
|
||||
void setSongRating(final int rating);
|
|
@ -20,7 +20,6 @@ package org.moire.ultrasonic.service;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
|
||||
import org.koin.java.standalone.KoinJavaComponent;
|
||||
|
@ -47,9 +46,9 @@ import static org.koin.java.standalone.KoinJavaComponent.inject;
|
|||
* @author Sindre Mehus, Joshua Bahnsen
|
||||
* @version $Id$
|
||||
*/
|
||||
public class DownloadServiceImpl implements DownloadService
|
||||
public class MediaPlayerControllerImpl implements MediaPlayerController
|
||||
{
|
||||
private static final String TAG = DownloadServiceImpl.class.getSimpleName();
|
||||
private static final String TAG = MediaPlayerControllerImpl.class.getSimpleName();
|
||||
|
||||
private String suggestedPlaylistName;
|
||||
private boolean keepScreenOn;
|
||||
|
@ -58,20 +57,20 @@ public class DownloadServiceImpl implements DownloadService
|
|||
private boolean autoPlayStart;
|
||||
|
||||
private Context context;
|
||||
public Lazy<JukeboxService> jukeboxService = inject(JukeboxService.class);
|
||||
private Lazy<JukeboxMediaPlayer> jukeboxMediaPlayer = inject(JukeboxMediaPlayer.class);
|
||||
private Lazy<DownloadQueueSerializer> downloadQueueSerializer = inject(DownloadQueueSerializer.class);
|
||||
private Lazy<ExternalStorageMonitor> externalStorageMonitor = inject(ExternalStorageMonitor.class);
|
||||
private final Downloader downloader;
|
||||
private final ShufflePlayBuffer shufflePlayBuffer;
|
||||
private final Player player;
|
||||
private final LocalMediaPlayer localMediaPlayer;
|
||||
|
||||
public DownloadServiceImpl(Context context, Downloader downloader, ShufflePlayBuffer shufflePlayBuffer,
|
||||
Player player)
|
||||
public MediaPlayerControllerImpl(Context context, Downloader downloader, ShufflePlayBuffer shufflePlayBuffer,
|
||||
LocalMediaPlayer localMediaPlayer)
|
||||
{
|
||||
this.context = context;
|
||||
this.downloader = downloader;
|
||||
this.shufflePlayBuffer = shufflePlayBuffer;
|
||||
this.player = player;
|
||||
this.localMediaPlayer = localMediaPlayer;
|
||||
|
||||
externalStorageMonitor.getValue().onCreate(new Runnable() {
|
||||
@Override
|
||||
|
@ -83,14 +82,14 @@ public class DownloadServiceImpl implements DownloadService
|
|||
int instance = Util.getActiveServer(context);
|
||||
setJukeboxEnabled(Util.getJukeboxEnabled(context, instance));
|
||||
|
||||
Log.i(TAG, "DownloadServiceImpl created");
|
||||
Log.i(TAG, "MediaPlayerControllerImpl created");
|
||||
}
|
||||
|
||||
public void onDestroy()
|
||||
{
|
||||
externalStorageMonitor.getValue().onDestroy();
|
||||
context.stopService(new Intent(context, MediaPlayerService.class));
|
||||
Log.i(TAG, "DownloadServiceImpl destroyed");
|
||||
Log.i(TAG, "MediaPlayerControllerImpl destroyed");
|
||||
}
|
||||
|
||||
private void executeOnStartedMediaPlayerService(final Consumer<MediaPlayerService> taskToExecute)
|
||||
|
@ -120,20 +119,20 @@ public class DownloadServiceImpl implements DownloadService
|
|||
}
|
||||
});
|
||||
|
||||
if (player.currentPlaying != null)
|
||||
if (localMediaPlayer.currentPlaying != null)
|
||||
{
|
||||
if (autoPlay && jukeboxService.getValue().isEnabled())
|
||||
if (autoPlay && jukeboxMediaPlayer.getValue().isEnabled())
|
||||
{
|
||||
jukeboxService.getValue().skip(downloader.getCurrentPlayingIndex(), currentPlayingPosition / 1000);
|
||||
jukeboxMediaPlayer.getValue().skip(downloader.getCurrentPlayingIndex(), currentPlayingPosition / 1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (player.currentPlaying.isCompleteFileAvailable())
|
||||
if (localMediaPlayer.currentPlaying.isCompleteFileAvailable())
|
||||
{
|
||||
executeOnStartedMediaPlayerService(new Consumer<MediaPlayerService>() {
|
||||
@Override
|
||||
public void accept(MediaPlayerService mediaPlayerService) {
|
||||
player.doPlay(player.currentPlaying, currentPlayingPosition, autoPlay);
|
||||
localMediaPlayer.doPlay(localMediaPlayer.currentPlaying, currentPlayingPosition, autoPlay);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -167,7 +166,7 @@ public class DownloadServiceImpl implements DownloadService
|
|||
@Override
|
||||
public synchronized void togglePlayPause()
|
||||
{
|
||||
if (player.playerState == PlayerState.IDLE) autoPlayStart = true;
|
||||
if (localMediaPlayer.playerState == PlayerState.IDLE) autoPlayStart = true;
|
||||
executeOnStartedMediaPlayerService(new Consumer<MediaPlayerService>() {
|
||||
@Override
|
||||
public void accept(MediaPlayerService mediaPlayerService) {
|
||||
|
@ -224,7 +223,7 @@ public class DownloadServiceImpl implements DownloadService
|
|||
public synchronized void download(List<MusicDirectory.Entry> songs, boolean save, boolean autoPlay, boolean playNext, boolean shuffle, boolean newPlaylist)
|
||||
{
|
||||
downloader.download(songs, save, autoPlay, playNext, newPlaylist);
|
||||
jukeboxService.getValue().updatePlaylist();
|
||||
jukeboxMediaPlayer.getValue().updatePlaylist();
|
||||
|
||||
if (shuffle) shuffle();
|
||||
|
||||
|
@ -240,7 +239,13 @@ public class DownloadServiceImpl implements DownloadService
|
|||
}
|
||||
else
|
||||
{
|
||||
downloader.setFirstPlaying();
|
||||
if (localMediaPlayer.currentPlaying == null && downloader.downloadList.size() > 0)
|
||||
{
|
||||
localMediaPlayer.currentPlaying = downloader.downloadList.get(0);
|
||||
localMediaPlayer.currentPlaying.setPlaying(true);
|
||||
}
|
||||
|
||||
downloader.checkDownloads();
|
||||
}
|
||||
|
||||
downloadQueueSerializer.getValue().serializeDownloadQueue(downloader.downloadList, downloader.getCurrentPlayingIndex(), getPlayerPosition());
|
||||
|
@ -256,7 +261,7 @@ public class DownloadServiceImpl implements DownloadService
|
|||
public synchronized void setCurrentPlaying(DownloadFile currentPlaying)
|
||||
{
|
||||
MediaPlayerService mediaPlayerService = MediaPlayerService.getRunningInstance();
|
||||
if (mediaPlayerService != null) player.setCurrentPlaying(currentPlaying);
|
||||
if (mediaPlayerService != null) localMediaPlayer.setCurrentPlaying(currentPlaying);
|
||||
}
|
||||
|
||||
public synchronized void setCurrentPlaying(int index)
|
||||
|
@ -268,19 +273,13 @@ public class DownloadServiceImpl implements DownloadService
|
|||
public synchronized void setPlayerState(PlayerState state)
|
||||
{
|
||||
MediaPlayerService mediaPlayerService = MediaPlayerService.getRunningInstance();
|
||||
if (mediaPlayerService != null) player.setPlayerState(state);
|
||||
if (mediaPlayerService != null) localMediaPlayer.setPlayerState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopJukeboxService()
|
||||
{
|
||||
jukeboxService.getValue().stopJukeboxService();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startJukeboxService()
|
||||
{
|
||||
jukeboxService.getValue().startJukeboxService();
|
||||
jukeboxMediaPlayer.getValue().stopJukeboxService();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -306,7 +305,7 @@ public class DownloadServiceImpl implements DownloadService
|
|||
downloader.shuffle();
|
||||
|
||||
downloadQueueSerializer.getValue().serializeDownloadQueue(downloader.downloadList, downloader.getCurrentPlayingIndex(), getPlayerPosition());
|
||||
jukeboxService.getValue().updatePlaylist();
|
||||
jukeboxMediaPlayer.getValue().updatePlaylist();
|
||||
|
||||
MediaPlayerService mediaPlayerService = MediaPlayerService.getRunningInstance();
|
||||
if (mediaPlayerService != null) mediaPlayerService.setNextPlaying();
|
||||
|
@ -361,7 +360,7 @@ public class DownloadServiceImpl implements DownloadService
|
|||
MediaPlayerService mediaPlayerService = MediaPlayerService.getRunningInstance();
|
||||
if (mediaPlayerService != null) mediaPlayerService.clear(serialize);
|
||||
|
||||
jukeboxService.getValue().updatePlaylist();
|
||||
jukeboxMediaPlayer.getValue().updatePlaylist();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -380,13 +379,13 @@ public class DownloadServiceImpl implements DownloadService
|
|||
}
|
||||
|
||||
downloadQueueSerializer.getValue().serializeDownloadQueue(downloader.downloadList, downloader.getCurrentPlayingIndex(), getPlayerPosition());
|
||||
jukeboxService.getValue().updatePlaylist();
|
||||
jukeboxMediaPlayer.getValue().updatePlaylist();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void remove(DownloadFile downloadFile)
|
||||
{
|
||||
if (downloadFile == player.currentPlaying)
|
||||
if (downloadFile == localMediaPlayer.currentPlaying)
|
||||
{
|
||||
reset();
|
||||
setCurrentPlaying(null);
|
||||
|
@ -395,9 +394,9 @@ public class DownloadServiceImpl implements DownloadService
|
|||
downloader.removeDownloadFile(downloadFile);
|
||||
|
||||
downloadQueueSerializer.getValue().serializeDownloadQueue(downloader.downloadList, downloader.getCurrentPlayingIndex(), getPlayerPosition());
|
||||
jukeboxService.getValue().updatePlaylist();
|
||||
jukeboxMediaPlayer.getValue().updatePlaylist();
|
||||
|
||||
if (downloadFile == player.nextPlaying)
|
||||
if (downloadFile == localMediaPlayer.nextPlaying)
|
||||
{
|
||||
MediaPlayerService mediaPlayerService = MediaPlayerService.getRunningInstance();
|
||||
if (mediaPlayerService != null) mediaPlayerService.setNextPlaying();
|
||||
|
@ -456,7 +455,7 @@ public class DownloadServiceImpl implements DownloadService
|
|||
public synchronized void reset()
|
||||
{
|
||||
MediaPlayerService mediaPlayerService = MediaPlayerService.getRunningInstance();
|
||||
if (mediaPlayerService != null) player.reset();
|
||||
if (mediaPlayerService != null) localMediaPlayer.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -470,9 +469,9 @@ public class DownloadServiceImpl implements DownloadService
|
|||
@Override
|
||||
public synchronized int getPlayerDuration()
|
||||
{
|
||||
if (player.currentPlaying != null)
|
||||
if (localMediaPlayer.currentPlaying != null)
|
||||
{
|
||||
Integer duration = player.currentPlaying.getSong().getDuration();
|
||||
Integer duration = localMediaPlayer.currentPlaying.getSong().getDuration();
|
||||
if (duration != null)
|
||||
{
|
||||
return duration * 1000;
|
||||
|
@ -485,7 +484,7 @@ public class DownloadServiceImpl implements DownloadService
|
|||
}
|
||||
|
||||
@Override
|
||||
public PlayerState getPlayerState() { return player.playerState; }
|
||||
public PlayerState getPlayerState() { return localMediaPlayer.playerState; }
|
||||
|
||||
@Override
|
||||
public void setSuggestedPlaylistName(String name)
|
||||
|
@ -499,21 +498,12 @@ public class DownloadServiceImpl implements DownloadService
|
|||
return suggestedPlaylistName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getEqualizerAvailable() { return player.equalizerAvailable; }
|
||||
|
||||
@Override
|
||||
public boolean getVisualizerAvailable()
|
||||
{
|
||||
return player.visualizerAvailable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EqualizerController getEqualizerController()
|
||||
{
|
||||
MediaPlayerService mediaPlayerService = MediaPlayerService.getRunningInstance();
|
||||
if (mediaPlayerService == null) return null;
|
||||
return player.getEqualizerController();
|
||||
return localMediaPlayer.getEqualizerController();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -521,13 +511,13 @@ public class DownloadServiceImpl implements DownloadService
|
|||
{
|
||||
MediaPlayerService mediaPlayerService = MediaPlayerService.getRunningInstance();
|
||||
if (mediaPlayerService == null) return null;
|
||||
return player.getVisualizerController();
|
||||
return localMediaPlayer.getVisualizerController();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJukeboxEnabled()
|
||||
{
|
||||
return jukeboxService.getValue().isEnabled();
|
||||
return jukeboxMediaPlayer.getValue().isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -547,32 +537,15 @@ public class DownloadServiceImpl implements DownloadService
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSharingAvailable()
|
||||
{
|
||||
try
|
||||
{
|
||||
String username = Util.getUserName(context, Util.getActiveServer(context));
|
||||
UserInfo user = MusicServiceFactory.getMusicService(context).getUser(username, context, null);
|
||||
return user.getShareRole();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.w(TAG, "Error getting user information", e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setJukeboxEnabled(boolean jukeboxEnabled)
|
||||
{
|
||||
jukeboxService.getValue().setEnabled(jukeboxEnabled);
|
||||
jukeboxMediaPlayer.getValue().setEnabled(jukeboxEnabled);
|
||||
setPlayerState(PlayerState.IDLE);
|
||||
|
||||
if (jukeboxEnabled)
|
||||
{
|
||||
jukeboxService.getValue().startJukeboxService();
|
||||
jukeboxMediaPlayer.getValue().startJukeboxService();
|
||||
|
||||
reset();
|
||||
|
||||
|
@ -584,59 +557,28 @@ public class DownloadServiceImpl implements DownloadService
|
|||
}
|
||||
else
|
||||
{
|
||||
jukeboxService.getValue().stopJukeboxService();
|
||||
jukeboxMediaPlayer.getValue().stopJukeboxService();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void adjustJukeboxVolume(boolean up)
|
||||
{
|
||||
jukeboxService.getValue().adjustVolume(up);
|
||||
jukeboxMediaPlayer.getValue().adjustVolume(up);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVolume(float volume)
|
||||
{
|
||||
MediaPlayerService mediaPlayerService = MediaPlayerService.getRunningInstance();
|
||||
if (mediaPlayerService != null) player.setVolume(volume);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void swap(boolean mainList, int from, int to)
|
||||
{
|
||||
List<DownloadFile> list = mainList ? downloader.downloadList : downloader.backgroundDownloadList;
|
||||
int max = list.size();
|
||||
|
||||
if (to >= max)
|
||||
{
|
||||
to = max - 1;
|
||||
}
|
||||
else if (to < 0)
|
||||
{
|
||||
to = 0;
|
||||
}
|
||||
|
||||
int currentPlayingIndex = downloader.getCurrentPlayingIndex();
|
||||
DownloadFile movedSong = list.remove(from);
|
||||
list.add(to, movedSong);
|
||||
|
||||
if (jukeboxService.getValue().isEnabled() && mainList)
|
||||
{
|
||||
jukeboxService.getValue().updatePlaylist();
|
||||
}
|
||||
else if (mainList && (movedSong == player.nextPlaying || (currentPlayingIndex + 1) == to))
|
||||
{
|
||||
// Moving next playing or moving a song to be next playing
|
||||
MediaPlayerService mediaPlayerService = MediaPlayerService.getRunningInstance();
|
||||
if (mediaPlayerService != null) mediaPlayerService.setNextPlaying();
|
||||
}
|
||||
if (mediaPlayerService != null) localMediaPlayer.setVolume(volume);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateNotification()
|
||||
{
|
||||
MediaPlayerService mediaPlayerService = MediaPlayerService.getRunningInstance();
|
||||
if (mediaPlayerService != null) mediaPlayerService.updateNotification(player.playerState, player.currentPlaying);
|
||||
if (mediaPlayerService != null) mediaPlayerService.updateNotification(localMediaPlayer.playerState, localMediaPlayer.currentPlaying);
|
||||
}
|
||||
|
||||
public void setSongRating(final int rating)
|
||||
|
@ -644,10 +586,10 @@ public class DownloadServiceImpl implements DownloadService
|
|||
if (!KoinJavaComponent.get(FeatureStorage.class).isFeatureEnabled(Feature.FIVE_STAR_RATING))
|
||||
return;
|
||||
|
||||
if (player.currentPlaying == null)
|
||||
if (localMediaPlayer.currentPlaying == null)
|
||||
return;
|
||||
|
||||
final Entry song = player.currentPlaying.getSong();
|
||||
final Entry song = localMediaPlayer.currentPlaying.getSong();
|
||||
song.setUserRating(rating);
|
||||
|
||||
new Thread(new Runnable()
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.moire.ultrasonic.service;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
@ -43,20 +42,20 @@ import static org.koin.java.standalone.KoinJavaComponent.inject;
|
|||
/**
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public class DownloadServiceLifecycleSupport
|
||||
public class MediaPlayerLifecycleSupport
|
||||
{
|
||||
private static final String TAG = DownloadServiceLifecycleSupport.class.getSimpleName();
|
||||
private static final String TAG = MediaPlayerLifecycleSupport.class.getSimpleName();
|
||||
|
||||
private Lazy<DownloadQueueSerializer> downloadQueueSerializer = inject(DownloadQueueSerializer.class);
|
||||
private final DownloadServiceImpl downloadService; // From DI
|
||||
private final MediaPlayerControllerImpl mediaPlayerController; // From DI
|
||||
private final Downloader downloader; // From DI
|
||||
|
||||
private BroadcastReceiver headsetEventReceiver;
|
||||
private Context context;
|
||||
|
||||
public DownloadServiceLifecycleSupport(Context context, final DownloadServiceImpl downloadService, final Downloader downloader)
|
||||
private BroadcastReceiver headsetEventReceiver;
|
||||
|
||||
public MediaPlayerLifecycleSupport(Context context, final MediaPlayerControllerImpl mediaPlayerController, final Downloader downloader)
|
||||
{
|
||||
this.downloadService = downloadService;
|
||||
this.mediaPlayerController = mediaPlayerController;
|
||||
this.context = context;
|
||||
this.downloader = downloader;
|
||||
|
||||
|
@ -80,11 +79,11 @@ public class DownloadServiceLifecycleSupport
|
|||
@Override
|
||||
public void accept(State state) {
|
||||
// TODO: here the autoPlay = false creates problems when Ultrasonic is started by a Play MediaButton as the player won't start this way.
|
||||
downloadService.restore(state.songs, state.currentPlayingIndex, state.currentPlayingPosition, false, false);
|
||||
mediaPlayerController.restore(state.songs, state.currentPlayingIndex, state.currentPlayingPosition, false, false);
|
||||
|
||||
// Work-around: Serialize again, as the restore() method creates a serialization without current playing info.
|
||||
downloadQueueSerializer.getValue().serializeDownloadQueue(downloader.downloadList,
|
||||
downloader.getCurrentPlayingIndex(), downloadService.getPlayerPosition());
|
||||
downloader.getCurrentPlayingIndex(), mediaPlayerController.getPlayerPosition());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -94,13 +93,26 @@ public class DownloadServiceLifecycleSupport
|
|||
|
||||
public void onDestroy()
|
||||
{
|
||||
downloadService.clear(false);
|
||||
mediaPlayerController.clear(false);
|
||||
context.unregisterReceiver(headsetEventReceiver);
|
||||
context.unregisterReceiver(intentReceiver);
|
||||
downloadService.onDestroy();
|
||||
mediaPlayerController.onDestroy();
|
||||
Log.i(TAG, "LifecycleSupport destroyed");
|
||||
}
|
||||
|
||||
public void receiveIntent(Intent intent)
|
||||
{
|
||||
Log.i(TAG, "Received intent");
|
||||
if (intent != null && intent.getExtras() != null)
|
||||
{
|
||||
KeyEvent event = (KeyEvent) intent.getExtras().get(Intent.EXTRA_KEY_EVENT);
|
||||
if (event != null)
|
||||
{
|
||||
handleKeyEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void registerHeadsetReceiver() {
|
||||
// Pause when headset is unplugged.
|
||||
final SharedPreferences sp = Util.getPreferences(context);
|
||||
|
@ -119,38 +131,32 @@ public class DownloadServiceLifecycleSupport
|
|||
Log.i(TAG, String.format("Headset event for: %s", extras.get("name")));
|
||||
final int state = extras.getInt("state");
|
||||
if (state == 0) {
|
||||
if (!downloadService.isJukeboxEnabled()) {
|
||||
downloadService.pause();
|
||||
if (!mediaPlayerController.isJukeboxEnabled()) {
|
||||
mediaPlayerController.pause();
|
||||
}
|
||||
} else if (state == 1) {
|
||||
if (!downloadService.isJukeboxEnabled() &&
|
||||
if (!mediaPlayerController.isJukeboxEnabled() &&
|
||||
sp.getBoolean(spKey, false) &&
|
||||
downloadService.getPlayerState() == PlayerState.PAUSED) {
|
||||
downloadService.start();
|
||||
mediaPlayerController.getPlayerState() == PlayerState.PAUSED) {
|
||||
mediaPlayerController.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@SuppressLint("InlinedApi")
|
||||
IntentFilter headsetIntentFilter = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) ?
|
||||
new IntentFilter(AudioManager.ACTION_HEADSET_PLUG) :
|
||||
new IntentFilter(Intent.ACTION_HEADSET_PLUG);
|
||||
|
||||
|
||||
IntentFilter headsetIntentFilter;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
|
||||
{
|
||||
headsetIntentFilter = new IntentFilter(AudioManager.ACTION_HEADSET_PLUG);
|
||||
}
|
||||
else
|
||||
{
|
||||
headsetIntentFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
|
||||
}
|
||||
context.registerReceiver(headsetEventReceiver, headsetIntentFilter);
|
||||
}
|
||||
|
||||
public void receiveIntent(Intent intent)
|
||||
{
|
||||
Log.i(TAG, "Received intent");
|
||||
if (intent != null && intent.getExtras() != null)
|
||||
{
|
||||
KeyEvent event = (KeyEvent) intent.getExtras().get(Intent.EXTRA_KEY_EVENT);
|
||||
if (event != null)
|
||||
{
|
||||
handleKeyEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleKeyEvent(KeyEvent event)
|
||||
{
|
||||
if (event.getAction() != KeyEvent.ACTION_DOWN || event.getRepeatCount() > 0)
|
||||
|
@ -162,47 +168,47 @@ public class DownloadServiceLifecycleSupport
|
|||
{
|
||||
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
|
||||
case KeyEvent.KEYCODE_HEADSETHOOK:
|
||||
downloadService.togglePlayPause();
|
||||
mediaPlayerController.togglePlayPause();
|
||||
break;
|
||||
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
|
||||
downloadService.previous();
|
||||
mediaPlayerController.previous();
|
||||
break;
|
||||
case KeyEvent.KEYCODE_MEDIA_NEXT:
|
||||
if (downloader.getCurrentPlayingIndex() < downloader.downloadList.size() - 1)
|
||||
{
|
||||
downloadService.next();
|
||||
mediaPlayerController.next();
|
||||
}
|
||||
break;
|
||||
case KeyEvent.KEYCODE_MEDIA_STOP:
|
||||
downloadService.stop();
|
||||
mediaPlayerController.stop();
|
||||
break;
|
||||
case KeyEvent.KEYCODE_MEDIA_PLAY:
|
||||
if (downloadService.getPlayerState() == PlayerState.IDLE)
|
||||
if (mediaPlayerController.getPlayerState() == PlayerState.IDLE)
|
||||
{
|
||||
downloadService.play();
|
||||
mediaPlayerController.play();
|
||||
}
|
||||
else if (downloadService.getPlayerState() != PlayerState.STARTED)
|
||||
else if (mediaPlayerController.getPlayerState() != PlayerState.STARTED)
|
||||
{
|
||||
downloadService.start();
|
||||
mediaPlayerController.start();
|
||||
}
|
||||
break;
|
||||
case KeyEvent.KEYCODE_MEDIA_PAUSE:
|
||||
downloadService.pause();
|
||||
mediaPlayerController.pause();
|
||||
break;
|
||||
case KeyEvent.KEYCODE_1:
|
||||
downloadService.setSongRating(1);
|
||||
mediaPlayerController.setSongRating(1);
|
||||
break;
|
||||
case KeyEvent.KEYCODE_2:
|
||||
downloadService.setSongRating(2);
|
||||
mediaPlayerController.setSongRating(2);
|
||||
break;
|
||||
case KeyEvent.KEYCODE_3:
|
||||
downloadService.setSongRating(3);
|
||||
mediaPlayerController.setSongRating(3);
|
||||
break;
|
||||
case KeyEvent.KEYCODE_4:
|
||||
downloadService.setSongRating(4);
|
||||
mediaPlayerController.setSongRating(4);
|
||||
break;
|
||||
case KeyEvent.KEYCODE_5:
|
||||
downloadService.setSongRating(5);
|
||||
mediaPlayerController.setSongRating(5);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -224,20 +230,20 @@ public class DownloadServiceLifecycleSupport
|
|||
switch(action)
|
||||
{
|
||||
case Constants.CMD_PLAY:
|
||||
downloadService.play();
|
||||
mediaPlayerController.play();
|
||||
break;
|
||||
case Constants.CMD_NEXT:
|
||||
downloadService.next();
|
||||
mediaPlayerController.next();
|
||||
break;
|
||||
case Constants.CMD_PREVIOUS:
|
||||
downloadService.previous();
|
||||
mediaPlayerController.previous();
|
||||
break;
|
||||
case Constants.CMD_TOGGLEPAUSE:
|
||||
downloadService.togglePlayPause();
|
||||
mediaPlayerController.togglePlayPause();
|
||||
break;
|
||||
case Constants.CMD_STOP:
|
||||
downloadService.pause();
|
||||
downloadService.seekTo(0);
|
||||
mediaPlayerController.pause();
|
||||
mediaPlayerController.seekTo(0);
|
||||
break;
|
||||
case Constants.CMD_PROCESS_KEYCODE:
|
||||
receiveIntent(intent);
|
|
@ -59,12 +59,12 @@ public class MediaPlayerService extends Service
|
|||
private final IBinder binder = new SimpleServiceBinder<>(this);
|
||||
private final Scrobbler scrobbler = new Scrobbler();
|
||||
|
||||
public Lazy<JukeboxService> jukeboxService = inject(JukeboxService.class);
|
||||
public Lazy<JukeboxMediaPlayer> jukeboxMediaPlayer = inject(JukeboxMediaPlayer.class);
|
||||
private Lazy<DownloadQueueSerializer> downloadQueueSerializer = inject(DownloadQueueSerializer.class);
|
||||
private Lazy<ShufflePlayBuffer> shufflePlayBufferLazy = inject(ShufflePlayBuffer.class);
|
||||
private Lazy<Downloader> downloaderLazy = inject(Downloader.class);
|
||||
private Lazy<Player> playerLazy = inject(Player.class);
|
||||
private Player player;
|
||||
private Lazy<LocalMediaPlayer> localMediaPlayerLazy = inject(LocalMediaPlayer.class);
|
||||
private LocalMediaPlayer localMediaPlayer;
|
||||
private Downloader downloader;
|
||||
private ShufflePlayBuffer shufflePlayBuffer;
|
||||
|
||||
|
@ -112,24 +112,24 @@ public class MediaPlayerService extends Service
|
|||
super.onCreate();
|
||||
|
||||
downloader = downloaderLazy.getValue();
|
||||
player = playerLazy.getValue();
|
||||
localMediaPlayer = localMediaPlayerLazy.getValue();
|
||||
shufflePlayBuffer = shufflePlayBufferLazy.getValue();
|
||||
|
||||
downloader.onCreate();
|
||||
shufflePlayBuffer.onCreate();
|
||||
|
||||
player.onCreate();
|
||||
localMediaPlayer.onCreate();
|
||||
setupOnCurrentPlayingChangedHandler();
|
||||
setupOnPlayerStateChangedHandler();
|
||||
setupOnSongCompletedHandler();
|
||||
player.onPrepared = new Runnable() {
|
||||
localMediaPlayer.onPrepared = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
downloadQueueSerializer.getValue().serializeDownloadQueue(downloader.downloadList,
|
||||
downloader.getCurrentPlayingIndex(), getPlayerPosition());
|
||||
}
|
||||
};
|
||||
player.onNextSongRequested = new Runnable() {
|
||||
localMediaPlayer.onNextSongRequested = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setNextPlaying();
|
||||
|
@ -171,7 +171,7 @@ public class MediaPlayerService extends Service
|
|||
|
||||
try
|
||||
{
|
||||
player.onDestroy();
|
||||
localMediaPlayer.onDestroy();
|
||||
shufflePlayBuffer.onDestroy();
|
||||
downloader.onDestroy();
|
||||
}
|
||||
|
@ -184,37 +184,37 @@ public class MediaPlayerService extends Service
|
|||
|
||||
public synchronized void seekTo(int position)
|
||||
{
|
||||
if (jukeboxService.getValue().isEnabled())
|
||||
if (jukeboxMediaPlayer.getValue().isEnabled())
|
||||
{
|
||||
jukeboxService.getValue().skip(downloader.getCurrentPlayingIndex(), position / 1000);
|
||||
jukeboxMediaPlayer.getValue().skip(downloader.getCurrentPlayingIndex(), position / 1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.seekTo(position);
|
||||
localMediaPlayer.seekTo(position);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized int getPlayerPosition()
|
||||
{
|
||||
if (player.playerState == IDLE || player.playerState == DOWNLOADING || player.playerState == PREPARING)
|
||||
if (localMediaPlayer.playerState == IDLE || localMediaPlayer.playerState == DOWNLOADING || localMediaPlayer.playerState == PREPARING)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return jukeboxService.getValue().isEnabled() ? jukeboxService.getValue().getPositionSeconds() * 1000 :
|
||||
player.getPlayerPosition();
|
||||
return jukeboxMediaPlayer.getValue().isEnabled() ? jukeboxMediaPlayer.getValue().getPositionSeconds() * 1000 :
|
||||
localMediaPlayer.getPlayerPosition();
|
||||
}
|
||||
|
||||
public synchronized int getPlayerDuration()
|
||||
{
|
||||
return player.getPlayerDuration();
|
||||
return localMediaPlayer.getPlayerDuration();
|
||||
}
|
||||
|
||||
public synchronized void setCurrentPlaying(int currentPlayingIndex)
|
||||
{
|
||||
try
|
||||
{
|
||||
player.setCurrentPlaying(downloader.downloadList.get(currentPlayingIndex));
|
||||
localMediaPlayer.setCurrentPlaying(downloader.downloadList.get(currentPlayingIndex));
|
||||
}
|
||||
catch (IndexOutOfBoundsException x)
|
||||
{
|
||||
|
@ -224,7 +224,7 @@ public class MediaPlayerService extends Service
|
|||
|
||||
public void setupOnCurrentPlayingChangedHandler()
|
||||
{
|
||||
player.onCurrentPlayingChanged = new Consumer<DownloadFile>() {
|
||||
localMediaPlayer.onCurrentPlayingChanged = new Consumer<DownloadFile>() {
|
||||
@Override
|
||||
public void accept(DownloadFile currentPlaying) {
|
||||
if (currentPlaying != null)
|
||||
|
@ -241,7 +241,7 @@ public class MediaPlayerService extends Service
|
|||
}
|
||||
|
||||
// Update widget
|
||||
PlayerState playerState = player.playerState;
|
||||
PlayerState playerState = localMediaPlayer.playerState;
|
||||
MusicDirectory.Entry song = currentPlaying == null? null : currentPlaying.getSong();
|
||||
UltraSonicAppWidgetProvider4x1.getInstance().notifyChange(MediaPlayerService.this, song, playerState == PlayerState.STARTED, false);
|
||||
UltraSonicAppWidgetProvider4x2.getInstance().notifyChange(MediaPlayerService.this, song, playerState == PlayerState.STARTED, true);
|
||||
|
@ -253,7 +253,7 @@ public class MediaPlayerService extends Service
|
|||
if (currentPlaying != null)
|
||||
{
|
||||
if (tabInstance != null) {
|
||||
updateNotification(player.playerState, currentPlaying);
|
||||
updateNotification(localMediaPlayer.playerState, currentPlaying);
|
||||
tabInstance.showNowPlaying();
|
||||
}
|
||||
}
|
||||
|
@ -263,7 +263,7 @@ public class MediaPlayerService extends Service
|
|||
{
|
||||
tabInstance.hideNowPlaying();
|
||||
stopForeground(true);
|
||||
player.clearRemoteControl();
|
||||
localMediaPlayer.clearRemoteControl();
|
||||
isInForeground = false;
|
||||
stopSelf();
|
||||
}
|
||||
|
@ -278,7 +278,7 @@ public class MediaPlayerService extends Service
|
|||
|
||||
if (!gaplessPlayback)
|
||||
{
|
||||
player.setNextPlaying(null);
|
||||
localMediaPlayer.setNextPlaying(null);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -295,35 +295,34 @@ public class MediaPlayerService extends Service
|
|||
index = (index + 1) % downloader.downloadList.size();
|
||||
break;
|
||||
case SINGLE:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
player.clearNextPlaying();
|
||||
localMediaPlayer.clearNextPlaying();
|
||||
|
||||
if (index < downloader.downloadList.size() && index != -1)
|
||||
{
|
||||
player.setNextPlaying(downloader.downloadList.get(index));
|
||||
localMediaPlayer.setNextPlaying(downloader.downloadList.get(index));
|
||||
}
|
||||
else
|
||||
{
|
||||
player.setNextPlaying(null);
|
||||
localMediaPlayer.setNextPlaying(null);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void togglePlayPause()
|
||||
{
|
||||
if (player.playerState == PAUSED || player.playerState == COMPLETED || player.playerState == STOPPED)
|
||||
if (localMediaPlayer.playerState == PAUSED || localMediaPlayer.playerState == COMPLETED || localMediaPlayer.playerState == STOPPED)
|
||||
{
|
||||
start();
|
||||
}
|
||||
else if (player.playerState == IDLE)
|
||||
else if (localMediaPlayer.playerState == IDLE)
|
||||
{
|
||||
play();
|
||||
}
|
||||
else if (player.playerState == STARTED)
|
||||
else if (localMediaPlayer.playerState == STARTED)
|
||||
{
|
||||
pause();
|
||||
}
|
||||
|
@ -361,14 +360,14 @@ public class MediaPlayerService extends Service
|
|||
{
|
||||
if (start)
|
||||
{
|
||||
if (jukeboxService.getValue().isEnabled())
|
||||
if (jukeboxMediaPlayer.getValue().isEnabled())
|
||||
{
|
||||
jukeboxService.getValue().skip(index, 0);
|
||||
player.setPlayerState(STARTED);
|
||||
jukeboxMediaPlayer.getValue().skip(index, 0);
|
||||
localMediaPlayer.setPlayerState(STARTED);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.play(downloader.downloadList.get(index));
|
||||
localMediaPlayer.play(downloader.downloadList.get(index));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -379,60 +378,60 @@ public class MediaPlayerService extends Service
|
|||
|
||||
private synchronized void resetPlayback()
|
||||
{
|
||||
player.reset();
|
||||
player.setCurrentPlaying(null);
|
||||
localMediaPlayer.reset();
|
||||
localMediaPlayer.setCurrentPlaying(null);
|
||||
downloadQueueSerializer.getValue().serializeDownloadQueue(downloader.downloadList,
|
||||
downloader.getCurrentPlayingIndex(), getPlayerPosition());
|
||||
}
|
||||
|
||||
public synchronized void pause()
|
||||
{
|
||||
if (player.playerState == STARTED)
|
||||
if (localMediaPlayer.playerState == STARTED)
|
||||
{
|
||||
if (jukeboxService.getValue().isEnabled())
|
||||
if (jukeboxMediaPlayer.getValue().isEnabled())
|
||||
{
|
||||
jukeboxService.getValue().stop();
|
||||
jukeboxMediaPlayer.getValue().stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
player.pause();
|
||||
localMediaPlayer.pause();
|
||||
}
|
||||
player.setPlayerState(PAUSED);
|
||||
localMediaPlayer.setPlayerState(PAUSED);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void stop()
|
||||
{
|
||||
if (player.playerState == STARTED)
|
||||
if (localMediaPlayer.playerState == STARTED)
|
||||
{
|
||||
if (jukeboxService.getValue().isEnabled())
|
||||
if (jukeboxMediaPlayer.getValue().isEnabled())
|
||||
{
|
||||
jukeboxService.getValue().stop();
|
||||
jukeboxMediaPlayer.getValue().stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
player.pause();
|
||||
localMediaPlayer.pause();
|
||||
}
|
||||
}
|
||||
player.setPlayerState(STOPPED);
|
||||
localMediaPlayer.setPlayerState(STOPPED);
|
||||
}
|
||||
|
||||
public synchronized void start()
|
||||
{
|
||||
if (jukeboxService.getValue().isEnabled())
|
||||
if (jukeboxMediaPlayer.getValue().isEnabled())
|
||||
{
|
||||
jukeboxService.getValue().start();
|
||||
jukeboxMediaPlayer.getValue().start();
|
||||
}
|
||||
else
|
||||
{
|
||||
player.start();
|
||||
localMediaPlayer.start();
|
||||
}
|
||||
player.setPlayerState(STARTED);
|
||||
localMediaPlayer.setPlayerState(STARTED);
|
||||
}
|
||||
|
||||
public void setupOnPlayerStateChangedHandler()
|
||||
{
|
||||
player.onPlayerStateChanged = new BiConsumer<PlayerState, DownloadFile>() {
|
||||
localMediaPlayer.onPlayerStateChanged = new BiConsumer<PlayerState, DownloadFile>() {
|
||||
@Override
|
||||
public void accept(PlayerState playerState, DownloadFile currentPlaying) {
|
||||
if (playerState == PAUSED)
|
||||
|
@ -442,13 +441,13 @@ public class MediaPlayerService extends Service
|
|||
|
||||
boolean showWhenPaused = (playerState != PlayerState.STOPPED && Util.isNotificationAlwaysEnabled(MediaPlayerService.this));
|
||||
boolean show = playerState == PlayerState.STARTED || showWhenPaused;
|
||||
MusicDirectory.Entry song = currentPlaying == null? null : currentPlaying.getSong();
|
||||
|
||||
Util.broadcastPlaybackStatusChange(MediaPlayerService.this, playerState);
|
||||
Util.broadcastA2dpPlayStatusChange(MediaPlayerService.this, playerState, currentPlaying.getSong(),
|
||||
Util.broadcastA2dpPlayStatusChange(MediaPlayerService.this, playerState, song,
|
||||
downloader.downloadList.size() + downloader.backgroundDownloadList.size(),
|
||||
downloader.downloadList.indexOf(currentPlaying) + 1, getPlayerPosition());
|
||||
|
||||
MusicDirectory.Entry song = currentPlaying.getSong();
|
||||
// Update widget
|
||||
UltraSonicAppWidgetProvider4x1.getInstance().notifyChange(MediaPlayerService.this, song, playerState == PlayerState.STARTED, false);
|
||||
UltraSonicAppWidgetProvider4x2.getInstance().notifyChange(MediaPlayerService.this, song, playerState == PlayerState.STARTED, true);
|
||||
|
@ -460,7 +459,7 @@ public class MediaPlayerService extends Service
|
|||
{
|
||||
if (tabInstance != null)
|
||||
{
|
||||
// Only update notification is player state is one that will change the icon
|
||||
// Only update notification is localMediaPlayer state is one that will change the icon
|
||||
if (playerState == PlayerState.STARTED || playerState == PlayerState.PAUSED)
|
||||
{
|
||||
updateNotification(playerState, currentPlaying);
|
||||
|
@ -473,7 +472,7 @@ public class MediaPlayerService extends Service
|
|||
if (tabInstance != null)
|
||||
{
|
||||
stopForeground(true);
|
||||
player.clearRemoteControl();
|
||||
localMediaPlayer.clearRemoteControl();
|
||||
isInForeground = false;
|
||||
tabInstance.hideNowPlaying();
|
||||
stopSelf();
|
||||
|
@ -494,7 +493,7 @@ public class MediaPlayerService extends Service
|
|||
|
||||
private void setupOnSongCompletedHandler()
|
||||
{
|
||||
player.onSongCompleted = new Consumer<DownloadFile>() {
|
||||
localMediaPlayer.onSongCompleted = new Consumer<DownloadFile>() {
|
||||
@Override
|
||||
public void accept(DownloadFile currentPlaying) {
|
||||
int index = downloader.getCurrentPlayingIndex();
|
||||
|
@ -527,7 +526,7 @@ public class MediaPlayerService extends Service
|
|||
if (Util.getShouldClearPlaylist(MediaPlayerService.this))
|
||||
{
|
||||
clear(true);
|
||||
jukeboxService.getValue().updatePlaylist();
|
||||
jukeboxMediaPlayer.getValue().updatePlaylist();
|
||||
}
|
||||
|
||||
resetPlayback();
|
||||
|
@ -552,9 +551,9 @@ public class MediaPlayerService extends Service
|
|||
|
||||
public synchronized void clear(boolean serialize)
|
||||
{
|
||||
player.reset();
|
||||
localMediaPlayer.reset();
|
||||
downloader.clear();
|
||||
player.setCurrentPlaying(null);
|
||||
localMediaPlayer.setCurrentPlaying(null);
|
||||
|
||||
setNextPlaying();
|
||||
|
||||
|
@ -567,7 +566,7 @@ public class MediaPlayerService extends Service
|
|||
public void updateNotification(PlayerState playerState, DownloadFile currentPlaying)
|
||||
{
|
||||
if (Util.isNotificationEnabled(this)) {
|
||||
if (isInForeground == true) {
|
||||
if (isInForeground) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
notificationManager.notify(NOTIFICATION_ID, buildForegroundNotification(playerState, currentPlaying));
|
||||
|
|
|
@ -54,11 +54,7 @@ import org.moire.ultrasonic.domain.*;
|
|||
import org.moire.ultrasonic.domain.MusicDirectory.Entry;
|
||||
import org.moire.ultrasonic.receiver.MediaButtonIntentReceiver;
|
||||
import org.moire.ultrasonic.service.DownloadFile;
|
||||
import org.moire.ultrasonic.service.DownloadService;
|
||||
import org.moire.ultrasonic.service.DownloadServiceImpl;
|
||||
import org.moire.ultrasonic.service.DownloadServiceLifecycleSupport;
|
||||
import org.moire.ultrasonic.service.Downloader;
|
||||
import org.moire.ultrasonic.service.MediaPlayerService;
|
||||
import org.moire.ultrasonic.service.MediaPlayerController;
|
||||
import org.moire.ultrasonic.service.MusicServiceFactory;
|
||||
|
||||
import java.io.*;
|
||||
|
@ -1183,22 +1179,22 @@ public class Util extends DownloadActivity
|
|||
@Override
|
||||
public void onAudioFocusChange(int focusChange)
|
||||
{
|
||||
DownloadService downloadService = (DownloadService) context;
|
||||
if ((focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) && !downloadService.isJukeboxEnabled())
|
||||
MediaPlayerController mediaPlayerController = (MediaPlayerController) context;
|
||||
if ((focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) && !mediaPlayerController.isJukeboxEnabled())
|
||||
{
|
||||
if (downloadService.getPlayerState() == PlayerState.STARTED)
|
||||
if (mediaPlayerController.getPlayerState() == PlayerState.STARTED)
|
||||
{
|
||||
SharedPreferences preferences = getPreferences(context);
|
||||
int lossPref = Integer.parseInt(preferences.getString(Constants.PREFERENCES_KEY_TEMP_LOSS, "1"));
|
||||
if (lossPref == 2 || (lossPref == 1 && focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK))
|
||||
{
|
||||
lowerFocus = true;
|
||||
downloadService.setVolume(0.1f);
|
||||
mediaPlayerController.setVolume(0.1f);
|
||||
}
|
||||
else if (lossPref == 0 || (lossPref == 1))
|
||||
{
|
||||
pauseFocus = true;
|
||||
downloadService.pause();
|
||||
mediaPlayerController.pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1207,18 +1203,18 @@ public class Util extends DownloadActivity
|
|||
if (pauseFocus)
|
||||
{
|
||||
pauseFocus = false;
|
||||
downloadService.start();
|
||||
mediaPlayerController.start();
|
||||
}
|
||||
else if (lowerFocus)
|
||||
{
|
||||
lowerFocus = false;
|
||||
downloadService.setVolume(1.0f);
|
||||
mediaPlayerController.setVolume(1.0f);
|
||||
}
|
||||
}
|
||||
else if (focusChange == AudioManager.AUDIOFOCUS_LOSS && !downloadService.isJukeboxEnabled())
|
||||
else if (focusChange == AudioManager.AUDIOFOCUS_LOSS && !mediaPlayerController.isJukeboxEnabled())
|
||||
{
|
||||
hasFocus = false;
|
||||
downloadService.pause();
|
||||
mediaPlayerController.pause();
|
||||
audioManager.abandonAudioFocus(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public enum VideoPlayerType
|
|||
public void playVideo(final Activity activity, MusicDirectory.Entry entry) throws Exception
|
||||
{
|
||||
|
||||
// Check if MX Player is installed.
|
||||
// Check if MX LocalMediaPlayer is installed.
|
||||
boolean installedAd = Util.isPackageInstalled(activity, PACKAGE_NAME_MX_AD);
|
||||
boolean installedPro = Util.isPackageInstalled(activity, PACKAGE_NAME_MX_PRO);
|
||||
|
||||
|
|
|
@ -37,12 +37,10 @@ import org.moire.ultrasonic.domain.MusicDirectory.Entry;
|
|||
import org.moire.ultrasonic.featureflags.Feature;
|
||||
import org.moire.ultrasonic.featureflags.FeatureStorage;
|
||||
import org.moire.ultrasonic.service.DownloadFile;
|
||||
import org.moire.ultrasonic.service.DownloadService;
|
||||
import org.moire.ultrasonic.service.DownloadServiceImpl;
|
||||
import org.moire.ultrasonic.service.Downloader;
|
||||
import org.moire.ultrasonic.service.MusicService;
|
||||
import org.moire.ultrasonic.service.MusicServiceFactory;
|
||||
import org.moire.ultrasonic.service.Player;
|
||||
import org.moire.ultrasonic.service.LocalMediaPlayer;
|
||||
import org.moire.ultrasonic.util.Util;
|
||||
import org.moire.ultrasonic.util.VideoPlayerType;
|
||||
|
||||
|
@ -85,7 +83,7 @@ public class SongView extends UpdateView implements Checkable
|
|||
private boolean useFiveStarRating;
|
||||
|
||||
private Lazy<Downloader> downloader = inject(Downloader.class);
|
||||
protected Lazy<Player> player = inject(Player.class);
|
||||
protected Lazy<LocalMediaPlayer> localMediaPlayer = inject(LocalMediaPlayer.class);
|
||||
|
||||
public SongView(Context context)
|
||||
{
|
||||
|
@ -413,7 +411,7 @@ public class SongView extends UpdateView implements Checkable
|
|||
viewHolder.fiveStar4.setImageDrawable(rating > 3 ? starDrawable : starHollowDrawable);
|
||||
viewHolder.fiveStar5.setImageDrawable(rating > 4 ? starDrawable : starHollowDrawable);
|
||||
|
||||
boolean playing = player.getValue().currentPlaying == downloadFile;
|
||||
boolean playing = localMediaPlayer.getValue().currentPlaying == downloadFile;
|
||||
|
||||
if (playing)
|
||||
{
|
||||
|
|
|
@ -27,8 +27,7 @@ import android.view.View;
|
|||
|
||||
import org.moire.ultrasonic.audiofx.VisualizerController;
|
||||
import org.moire.ultrasonic.domain.PlayerState;
|
||||
import org.moire.ultrasonic.service.DownloadService;
|
||||
import org.moire.ultrasonic.service.DownloadServiceImpl;
|
||||
import org.moire.ultrasonic.service.MediaPlayerController;
|
||||
|
||||
import kotlin.Lazy;
|
||||
|
||||
|
@ -51,7 +50,7 @@ public class VisualizerView extends View
|
|||
private float[] points;
|
||||
private boolean active;
|
||||
|
||||
private Lazy<DownloadServiceImpl> downloadServiceImpl = inject(DownloadServiceImpl.class);
|
||||
private Lazy<MediaPlayerController> mediaPlayerControllerLazy = inject(MediaPlayerController.class);
|
||||
|
||||
public VisualizerView(Context context)
|
||||
{
|
||||
|
@ -104,7 +103,7 @@ public class VisualizerView extends View
|
|||
|
||||
private Visualizer getVizualizer()
|
||||
{
|
||||
VisualizerController visualizerController = downloadServiceImpl.getValue().getVisualizerController();
|
||||
VisualizerController visualizerController = mediaPlayerControllerLazy.getValue().getVisualizerController();
|
||||
return visualizerController == null ? null : visualizerController.getVisualizer();
|
||||
}
|
||||
|
||||
|
@ -124,7 +123,7 @@ public class VisualizerView extends View
|
|||
return;
|
||||
}
|
||||
|
||||
if (downloadServiceImpl.getValue().getPlayerState() != PlayerState.STARTED)
|
||||
if (mediaPlayerControllerLazy.getValue().getPlayerState() != PlayerState.STARTED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -113,12 +113,13 @@ val musicServiceModule = module(MUSIC_SERVICE_CONTEXT) {
|
|||
|
||||
single { SubsonicImageLoader(getProperty(DiProperties.APP_CONTEXT), get()) }
|
||||
|
||||
single { DownloadServiceImpl(androidContext(), get(), get(), get()) }
|
||||
single { JukeboxService(androidContext(), get()) }
|
||||
single { DownloadServiceLifecycleSupport(androidContext(), get(), get()) }
|
||||
single<MediaPlayerController> { MediaPlayerControllerImpl(androidContext(), get(), get(), get()) }
|
||||
single { MediaPlayerControllerImpl(androidContext(), get(), get(), get()) }
|
||||
single { JukeboxMediaPlayer(androidContext(), get()) }
|
||||
single { MediaPlayerLifecycleSupport(androidContext(), get(), get()) }
|
||||
single { DownloadQueueSerializer(androidContext()) }
|
||||
single { ExternalStorageMonitor(androidContext()) }
|
||||
single { ShufflePlayBuffer(androidContext()) }
|
||||
single { Downloader(androidContext(), get(), get(), get()) }
|
||||
single { Player(androidContext()) }
|
||||
single { LocalMediaPlayer(androidContext()) }
|
||||
}
|
||||
|
|
|
@ -334,7 +334,7 @@
|
|||
<string name="util.bytes_format.megabyte">0.00 MB</string>
|
||||
<string name="util.no_time">-:--</string>
|
||||
<string name="util.zero_time">0:00</string>
|
||||
<string name="video.get_mx_player_text">O player MX não está instalado. Baixe da graça pela Play Store ou modifique as configurações de vídeo.</string>
|
||||
<string name="video.get_mx_player_text">O localMediaPlayer MX não está instalado. Baixe da graça pela Play Store ou modifique as configurações de vídeo.</string>
|
||||
<string name="video.get_mx_player_button">Baixar Player MX</string>
|
||||
<string name="widget.initial_text">Toque para selecionar a música</string>
|
||||
<string name="widget.sdcard_busy">Cartão SD indisponível</string>
|
||||
|
|
|
@ -334,7 +334,7 @@
|
|||
<string name="util.bytes_format.megabyte">0.00 MB</string>
|
||||
<string name="util.no_time">—:——</string>
|
||||
<string name="util.zero_time">0:00</string>
|
||||
<string name="video.get_mx_player_text">O player MX não está instalado. Descarregue da graça pela Play Store ou modifique as configurações de vídeo.</string>
|
||||
<string name="video.get_mx_player_text">O localMediaPlayer MX não está instalado. Descarregue da graça pela Play Store ou modifique as configurações de vídeo.</string>
|
||||
<string name="video.get_mx_player_button">Descarregar Player MX</string>
|
||||
<string name="widget.initial_text">Toque para selecionar a música</string>
|
||||
<string name="widget.sdcard_busy">Cartão SD indisponível</string>
|
||||
|
|
|
@ -314,7 +314,7 @@
|
|||
<string name="settings.use_id3">Browse Using ID3 Tags</string>
|
||||
<string name="settings.use_id3_summary">Use ID3 tag methods instead of file system based methods</string>
|
||||
<string name="settings.video_title">Video</string>
|
||||
<string name="settings.video_player">Video player</string>
|
||||
<string name="settings.video_player">Video localMediaPlayer</string>
|
||||
<string name="settings.view_refresh">View Refresh</string>
|
||||
<string name="settings.view_refresh_500">.5 seconds</string>
|
||||
<string name="settings.view_refresh_1000">1 second</string>
|
||||
|
|
Loading…
Reference in New Issue