use of org.moire.ultrasonic.service.DownloadFile in project ultrasonic by ultrasonic.
the class Util method broadcastA2dpMetaDataChange.
public static void broadcastA2dpMetaDataChange(Context context, DownloadService downloadService) {
if (!Util.getShouldSendBluetoothNotifications(context)) {
return;
}
Entry song = null;
Intent avrcpIntent = new Intent(CM_AVRCP_METADATA_CHANGED);
if (downloadService != null) {
DownloadFile entry = downloadService.getCurrentPlaying();
if (entry != null) {
song = entry.getSong();
}
}
if (downloadService == null || song == null) {
avrcpIntent.putExtra("track", "");
avrcpIntent.putExtra("track_name", "");
avrcpIntent.putExtra("artist", "");
avrcpIntent.putExtra("artist_name", "");
avrcpIntent.putExtra("album", "");
avrcpIntent.putExtra("album_name", "");
avrcpIntent.putExtra("album_artist", "");
avrcpIntent.putExtra("album_artist_name", "");
if (Util.getShouldSendBluetoothAlbumArt(context)) {
avrcpIntent.putExtra("coverart", (Parcelable) null);
avrcpIntent.putExtra("cover", (Parcelable) null);
}
avrcpIntent.putExtra("ListSize", (long) 0);
avrcpIntent.putExtra("id", (long) 0);
avrcpIntent.putExtra("duration", (long) 0);
avrcpIntent.putExtra("position", (long) 0);
} else {
if (song != currentSong) {
currentSong = song;
}
String title = song.getTitle();
String artist = song.getArtist();
String album = song.getAlbum();
Integer duration = song.getDuration();
Integer listSize = downloadService.getDownloads().size();
Integer id = downloadService.getCurrentPlayingIndex() + 1;
Integer playerPosition = downloadService.getPlayerPosition();
avrcpIntent.putExtra("track", title);
avrcpIntent.putExtra("track_name", title);
avrcpIntent.putExtra("artist", artist);
avrcpIntent.putExtra("artist_name", artist);
avrcpIntent.putExtra("album", album);
avrcpIntent.putExtra("album_name", album);
avrcpIntent.putExtra("album_artist", artist);
avrcpIntent.putExtra("album_artist_name", artist);
if (Util.getShouldSendBluetoothAlbumArt(context)) {
File albumArtFile = FileUtil.getAlbumArtFile(context, song);
avrcpIntent.putExtra("coverart", albumArtFile.getAbsolutePath());
avrcpIntent.putExtra("cover", albumArtFile.getAbsolutePath());
}
avrcpIntent.putExtra("position", (long) playerPosition);
avrcpIntent.putExtra("id", (long) id);
avrcpIntent.putExtra("ListSize", (long) listSize);
if (duration != null) {
avrcpIntent.putExtra("duration", (long) duration);
}
}
context.sendBroadcast(avrcpIntent);
}
use of org.moire.ultrasonic.service.DownloadFile in project ultrasonic by ultrasonic.
the class Util method broadcastA2dpPlayStatusChange.
public static void broadcastA2dpPlayStatusChange(Context context, PlayerState state, DownloadService downloadService) {
if (!Util.getShouldSendBluetoothNotifications(context) || downloadService == null) {
return;
}
DownloadFile currentPlaying = downloadService.getCurrentPlaying();
if (currentPlaying != null) {
Intent avrcpIntent = new Intent(CM_AVRCP_PLAYSTATE_CHANGED);
Entry song = currentPlaying.getSong();
if (song == null) {
return;
}
if (song != currentSong) {
currentSong = song;
}
String title = song.getTitle();
String artist = song.getArtist();
String album = song.getAlbum();
Integer duration = song.getDuration();
Integer listSize = downloadService.getDownloads().size();
Integer id = downloadService.getCurrentPlayingIndex() + 1;
Integer playerPosition = downloadService.getPlayerPosition();
avrcpIntent.putExtra("track", title);
avrcpIntent.putExtra("track_name", title);
avrcpIntent.putExtra("artist", artist);
avrcpIntent.putExtra("artist_name", artist);
avrcpIntent.putExtra("album", album);
avrcpIntent.putExtra("album_name", album);
avrcpIntent.putExtra("album_artist", artist);
avrcpIntent.putExtra("album_artist_name", artist);
if (Util.getShouldSendBluetoothAlbumArt(context)) {
File albumArtFile = FileUtil.getAlbumArtFile(context, song);
avrcpIntent.putExtra("coverart", albumArtFile.getAbsolutePath());
avrcpIntent.putExtra("cover", albumArtFile.getAbsolutePath());
}
avrcpIntent.putExtra("position", (long) playerPosition);
avrcpIntent.putExtra("id", (long) id);
avrcpIntent.putExtra("ListSize", (long) listSize);
if (duration != null) {
avrcpIntent.putExtra("duration", (long) duration);
}
switch(state) {
case STARTED:
avrcpIntent.putExtra("playing", true);
break;
case STOPPED:
avrcpIntent.putExtra("playing", false);
break;
case PAUSED:
avrcpIntent.putExtra("playing", false);
break;
case COMPLETED:
avrcpIntent.putExtra("playing", false);
break;
default:
// No need to broadcast.
return;
}
context.sendBroadcast(avrcpIntent);
}
}
use of org.moire.ultrasonic.service.DownloadFile in project ultrasonic by ultrasonic.
the class SubsonicTabActivity method showNowPlaying.
public void showNowPlaying() {
this.runOnUiThread(new Runnable() {
@Override
public void run() {
new SilentBackgroundTask<Void>(SubsonicTabActivity.this) {
@Override
protected Void doInBackground() throws Throwable {
if (!Util.getShowNowPlayingPreference(SubsonicTabActivity.this)) {
hideNowPlaying();
return null;
}
nowPlayingView = findViewById(R.id.now_playing);
if (nowPlayingView != null) {
final DownloadService downloadService = DownloadServiceImpl.getInstance();
if (downloadService != null) {
PlayerState playerState = downloadService.getPlayerState();
if (playerState.equals(PlayerState.PAUSED) || playerState.equals(PlayerState.STARTED)) {
DownloadFile file = downloadService.getCurrentPlaying();
if (file != null) {
final Entry song = file.getSong();
showNowPlaying(SubsonicTabActivity.this, downloadService, song, playerState);
}
} else {
hideNowPlaying();
}
}
}
return null;
}
@Override
protected void done(Void result) {
}
}.execute();
}
});
}
use of org.moire.ultrasonic.service.DownloadFile in project ultrasonic by ultrasonic.
the class CacheCleaner method findFilesToNotDelete.
private Set<File> findFilesToNotDelete() {
Set<File> filesToNotDelete = new HashSet<File>(5);
for (DownloadFile downloadFile : downloadService.getDownloads()) {
filesToNotDelete.add(downloadFile.getPartialFile());
filesToNotDelete.add(downloadFile.getCompleteFile());
}
filesToNotDelete.add(FileUtil.getMusicDirectory(context));
return filesToNotDelete;
}
use of org.moire.ultrasonic.service.DownloadFile in project ultrasonic by ultrasonic.
the class DownloadActivity method menuItemSelected.
private boolean menuItemSelected(final int menuItemId, final DownloadFile song) {
Entry entry = null;
if (song != null) {
entry = song.getSong();
}
switch(menuItemId) {
case R.id.menu_show_artist:
if (entry == null) {
return false;
}
if (Util.getShouldUseId3Tags(DownloadActivity.this)) {
Intent intent = new Intent(DownloadActivity.this, SelectAlbumActivity.class);
intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, entry.getArtistId());
intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, entry.getArtist());
intent.putExtra(Constants.INTENT_EXTRA_NAME_PARENT_ID, entry.getArtistId());
intent.putExtra(Constants.INTENT_EXTRA_NAME_ARTIST, true);
startActivityForResultWithoutTransition(DownloadActivity.this, intent);
}
return true;
case R.id.menu_show_album:
if (entry == null) {
return false;
}
Intent intent = new Intent(this, SelectAlbumActivity.class);
intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, entry.getParent());
intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, entry.getAlbum());
startActivityForResultWithoutTransition(this, intent);
return true;
case R.id.menu_lyrics:
if (entry == null) {
return false;
}
intent = new Intent(this, LyricsActivity.class);
intent.putExtra(Constants.INTENT_EXTRA_NAME_ARTIST, entry.getArtist());
intent.putExtra(Constants.INTENT_EXTRA_NAME_TITLE, entry.getTitle());
startActivityForResultWithoutTransition(this, intent);
return true;
case R.id.menu_remove:
getDownloadService().remove(song);
onDownloadListChanged();
return true;
case R.id.menu_item_screen_on_off:
if (getDownloadService().getKeepScreenOn()) {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getDownloadService().setKeepScreenOn(false);
} else {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getDownloadService().setKeepScreenOn(true);
}
return true;
case R.id.menu_shuffle:
getDownloadService().shuffle();
Util.toast(this, R.string.download_menu_shuffle_notification);
return true;
case R.id.menu_item_equalizer:
startActivity(new Intent(DownloadActivity.this, EqualizerActivity.class));
return true;
case R.id.menu_item_visualizer:
final boolean active = !visualizerView.isActive();
visualizerView.setActive(active);
if (!visualizerView.isActive()) {
visualizerViewLayout.setVisibility(View.GONE);
} else {
visualizerViewLayout.setVisibility(View.VISIBLE);
}
getDownloadService().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);
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();
onDownloadListChanged();
return true;
case R.id.menu_item_save_playlist:
if (!getDownloadService().getSongs().isEmpty()) {
showDialog(DIALOG_SAVE_PLAYLIST);
}
return true;
case R.id.menu_item_star:
if (currentSong == null) {
return true;
}
final boolean isStarred = currentSong.getStarred();
final String id = currentSong.getId();
if (isStarred) {
starMenuItem.setIcon(Util.getDrawableFromAttribute(SubsonicTabActivity.getInstance(), R.attr.star_hollow));
currentSong.setStarred(false);
} else {
starMenuItem.setIcon(Util.getDrawableFromAttribute(SubsonicTabActivity.getInstance(), R.attr.star_full));
currentSong.setStarred(true);
}
new Thread(new Runnable() {
@Override
public void run() {
final MusicService musicService = MusicServiceFactory.getMusicService(DownloadActivity.this);
try {
if (isStarred) {
musicService.unstar(id, null, null, DownloadActivity.this, null);
} else {
musicService.star(id, null, null, DownloadActivity.this, null);
}
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
}
}
}).start();
return true;
case R.id.menu_item_bookmark_set:
if (currentSong == null) {
return true;
}
final String songId = currentSong.getId();
final int playerPosition = getDownloadService().getPlayerPosition();
currentSong.setBookmarkPosition(playerPosition);
String bookmarkTime = Util.formatTotalDuration(playerPosition, true);
new Thread(new Runnable() {
@Override
public void run() {
final MusicService musicService = MusicServiceFactory.getMusicService(DownloadActivity.this);
try {
musicService.createBookmark(songId, playerPosition, DownloadActivity.this, null);
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
}
}
}).start();
String msg = getResources().getString(R.string.download_bookmark_set_at_position, bookmarkTime);
Util.toast(DownloadActivity.this, msg);
return true;
case R.id.menu_item_bookmark_delete:
if (currentSong == null) {
return true;
}
final String bookmarkSongId = currentSong.getId();
currentSong.setBookmarkPosition(0);
new Thread(new Runnable() {
@Override
public void run() {
final MusicService musicService = MusicServiceFactory.getMusicService(DownloadActivity.this);
try {
musicService.deleteBookmark(bookmarkSongId, DownloadActivity.this, null);
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
}
}
}).start();
Util.toast(DownloadActivity.this, R.string.download_bookmark_removed);
return true;
case R.id.menu_item_share:
DownloadService downloadService = getDownloadService();
List<Entry> entries = new ArrayList<Entry>();
if (downloadService != null) {
List<DownloadFile> downloadServiceSongs = downloadService.getSongs();
if (downloadServiceSongs != null) {
for (DownloadFile downloadFile : downloadServiceSongs) {
if (downloadFile != null) {
Entry playlistEntry = downloadFile.getSong();
if (playlistEntry != null) {
entries.add(playlistEntry);
}
}
}
}
}
createShare(entries);
return true;
default:
return false;
}
}
Aggregations