use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.
the class MusicService method handleChangeInternal.
private void handleChangeInternal(@NonNull final String what) {
switch(what) {
case PLAY_STATE_CHANGED:
updateNotification();
updateMediaSessionPlaybackState();
final boolean isPlaying = isPlaying();
if (!isPlaying && getSongProgressMillis() > 0) {
savePositionInTrack();
}
songPlayCountHelper.notifyPlayStateChanged(isPlaying);
break;
case META_CHANGED:
updateNotification();
updateMediaSessionMetaData();
savePosition();
savePositionInTrack();
final Song currentSong = getCurrentSong();
HistoryStore.getInstance(this).addSongId(currentSong.id);
if (songPlayCountHelper.shouldBumpPlayCount()) {
SongPlayCountStore.getInstance(this).bumpPlayCount(songPlayCountHelper.getSong().id);
}
songPlayCountHelper.notifySongChanged(currentSong);
break;
case QUEUE_CHANGED:
// because playing queue size might have changed
updateMediaSessionMetaData();
saveState();
if (playingQueue.size() > 0) {
prepareNext();
} else {
playingNotification.stop();
}
break;
}
}
use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.
the class MusicService method restoreQueuesAndPositionIfNecessary.
private synchronized void restoreQueuesAndPositionIfNecessary() {
if (!queuesRestored && playingQueue.isEmpty()) {
List<Song> restoredQueue = MusicPlaybackQueueStore.getInstance(this).getSavedPlayingQueue();
List<Song> restoredOriginalQueue = MusicPlaybackQueueStore.getInstance(this).getSavedOriginalPlayingQueue();
int restoredPosition = PreferenceManager.getDefaultSharedPreferences(this).getInt(SAVED_POSITION, -1);
int restoredPositionInTrack = PreferenceManager.getDefaultSharedPreferences(this).getInt(SAVED_POSITION_IN_TRACK, -1);
if (restoredQueue.size() > 0 && restoredQueue.size() == restoredOriginalQueue.size() && restoredPosition != -1) {
this.originalPlayingQueue = restoredOriginalQueue;
this.playingQueue = restoredQueue;
position = restoredPosition;
openCurrent();
prepareNext();
if (restoredPositionInTrack > 0)
seek(restoredPositionInTrack);
notHandledMetaChangedForCurrentTrack = true;
sendChangeInternal(META_CHANGED);
sendChangeInternal(QUEUE_CHANGED);
}
}
queuesRestored = true;
}
use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.
the class MusicService method updateMediaSessionMetaData.
private void updateMediaSessionMetaData() {
final Song song = getCurrentSong();
if (song.id == -1) {
mediaSession.setMetadata(null);
return;
}
final MediaMetadataCompat.Builder metaData = new MediaMetadataCompat.Builder().putString(MediaMetadataCompat.METADATA_KEY_ARTIST, song.artistName).putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, song.artistName).putString(MediaMetadataCompat.METADATA_KEY_ALBUM, song.albumName).putString(MediaMetadataCompat.METADATA_KEY_TITLE, song.title).putLong(MediaMetadataCompat.METADATA_KEY_DURATION, song.duration).putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, getPosition() + 1).putLong(MediaMetadataCompat.METADATA_KEY_YEAR, song.year).putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, null);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
metaData.putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, getPlayingQueue().size());
}
if (PreferenceUtil.getInstance(this).albumArtOnLockscreen()) {
final Point screenSize = Util.getScreenSize(MusicService.this);
final BitmapRequestBuilder<?, Bitmap> request = SongGlideRequest.Builder.from(Glide.with(MusicService.this), song).checkIgnoreMediaStore(MusicService.this).asBitmap().build();
if (PreferenceUtil.getInstance(this).blurredAlbumArt()) {
request.transform(new BlurTransformation.Builder(MusicService.this).build());
}
runOnUiThread(new Runnable() {
@Override
public void run() {
request.into(new SimpleTarget<Bitmap>(screenSize.x, screenSize.y) {
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
mediaSession.setMetadata(metaData.build());
}
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
metaData.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, copy(resource));
mediaSession.setMetadata(metaData.build());
}
});
}
});
} else {
mediaSession.setMetadata(metaData.build());
}
}
use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.
the class MusicPlaybackQueueStore method saveQueue.
/**
* Clears the existing database and saves the queue into the db so that when the
* app is restarted, the tracks you were listening to is restored
*
* @param queue the queue to save
*/
private synchronized void saveQueue(final String tableName, @NonNull final ArrayList<Song> queue) {
final SQLiteDatabase database = getWritableDatabase();
database.beginTransaction();
try {
database.delete(tableName, null, null);
database.setTransactionSuccessful();
} finally {
database.endTransaction();
}
final int NUM_PROCESS = 20;
int position = 0;
while (position < queue.size()) {
database.beginTransaction();
try {
for (int i = position; i < queue.size() && i < position + NUM_PROCESS; i++) {
Song song = queue.get(i);
ContentValues values = new ContentValues(4);
values.put(BaseColumns._ID, song.id);
values.put(AudioColumns.TITLE, song.title);
values.put(AudioColumns.TRACK, song.trackNumber);
values.put(AudioColumns.YEAR, song.year);
values.put(AudioColumns.DURATION, song.duration);
values.put(AudioColumns.DATA, song.data);
values.put(AudioColumns.DATE_MODIFIED, song.dateModified);
values.put(AudioColumns.ALBUM_ID, song.albumId);
values.put(AudioColumns.ALBUM, song.albumName);
values.put(AudioColumns.ARTIST_ID, song.artistId);
values.put(AudioColumns.ARTIST, song.artistName);
database.insert(tableName, null, values);
}
database.setTransactionSuccessful();
} finally {
database.endTransaction();
position += NUM_PROCESS;
}
}
}
use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.
the class ArtistDetailActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
int id = item.getItemId();
final List<Song> songs = songAdapter.getDataSet();
switch(id) {
case R.id.action_sleep_timer:
new SleepTimerDialog().show(getSupportFragmentManager(), "SET_SLEEP_TIMER");
return true;
case R.id.action_equalizer:
NavigationUtil.openEqualizer(this);
return true;
case R.id.action_shuffle_artist:
MusicPlayerRemote.openAndShuffleQueue(songs, true);
return true;
case R.id.action_play_next:
MusicPlayerRemote.playNext(songs);
return true;
case R.id.action_add_to_current_playing:
MusicPlayerRemote.enqueue(songs);
return true;
case R.id.action_add_to_playlist:
AddToPlaylistDialog.create(songs).show(getSupportFragmentManager(), "ADD_PLAYLIST");
return true;
case android.R.id.home:
super.onBackPressed();
return true;
case R.id.action_biography:
if (biographyDialog == null) {
biographyDialog = new MaterialDialog.Builder(this).title(artist.getName()).positiveText(android.R.string.ok).build();
}
if (PreferenceUtil.isAllowedToDownloadMetadata(ArtistDetailActivity.this)) {
// wiki should've been already downloaded
if (biography != null) {
biographyDialog.setContent(biography);
biographyDialog.show();
} else {
Toast.makeText(ArtistDetailActivity.this, getResources().getString(R.string.biography_unavailable), Toast.LENGTH_SHORT).show();
}
} else {
// force download
biographyDialog.show();
loadBiography();
}
return true;
case R.id.action_set_artist_image:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, getString(R.string.pick_from_local_storage)), REQUEST_CODE_SELECT_IMAGE);
return true;
case R.id.action_reset_artist_image:
Toast.makeText(ArtistDetailActivity.this, getResources().getString(R.string.updating), Toast.LENGTH_SHORT).show();
CustomArtistImageUtil.getInstance(ArtistDetailActivity.this).resetCustomArtistImage(artist);
return true;
case R.id.action_colored_footers:
item.setChecked(!item.isChecked());
setUsePalette(item.isChecked());
return true;
}
return super.onOptionsItemSelected(item);
}
Aggregations