Search in sources :

Example 1 with Song

use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.

the class SongDetailDialog method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Activity context = getActivity();
    final Song song = getArguments().getParcelable("song");
    MaterialDialog dialog = new MaterialDialog.Builder(context).customView(R.layout.dialog_file_details, true).title(context.getResources().getString(R.string.label_details)).positiveText(android.R.string.ok).build();
    View dialogView = dialog.getCustomView();
    final TextView fileName = dialogView.findViewById(R.id.file_name);
    final TextView filePath = dialogView.findViewById(R.id.file_path);
    final TextView fileSize = dialogView.findViewById(R.id.file_size);
    final TextView fileFormat = dialogView.findViewById(R.id.file_format);
    final TextView trackLength = dialogView.findViewById(R.id.track_length);
    final TextView bitRate = dialogView.findViewById(R.id.bitrate);
    final TextView samplingRate = dialogView.findViewById(R.id.sampling_rate);
    fileName.setText(makeTextWithTitle(context, R.string.label_file_name, "-"));
    filePath.setText(makeTextWithTitle(context, R.string.label_file_path, "-"));
    fileSize.setText(makeTextWithTitle(context, R.string.label_file_size, "-"));
    fileFormat.setText(makeTextWithTitle(context, R.string.label_file_format, "-"));
    trackLength.setText(makeTextWithTitle(context, R.string.label_track_length, "-"));
    bitRate.setText(makeTextWithTitle(context, R.string.label_bit_rate, "-"));
    samplingRate.setText(makeTextWithTitle(context, R.string.label_sampling_rate, "-"));
    if (song != null) {
        final File songFile = new File(song.data);
        if (songFile.exists()) {
            fileName.setText(makeTextWithTitle(context, R.string.label_file_name, songFile.getName()));
            filePath.setText(makeTextWithTitle(context, R.string.label_file_path, songFile.getAbsolutePath()));
            fileSize.setText(makeTextWithTitle(context, R.string.label_file_size, getFileSizeString(songFile.length())));
            try {
                AudioFile audioFile = AudioFileIO.read(songFile);
                AudioHeader audioHeader = audioFile.getAudioHeader();
                fileFormat.setText(makeTextWithTitle(context, R.string.label_file_format, audioHeader.getFormat()));
                trackLength.setText(makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(audioHeader.getTrackLength() * 1000)));
                bitRate.setText(makeTextWithTitle(context, R.string.label_bit_rate, audioHeader.getBitRate() + " kb/s"));
                samplingRate.setText(makeTextWithTitle(context, R.string.label_sampling_rate, audioHeader.getSampleRate() + " Hz"));
            } catch (@NonNull CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
                Log.e(TAG, "error while reading the song file", e);
                // fallback
                trackLength.setText(makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(song.duration)));
            }
        } else {
            // fallback
            fileName.setText(makeTextWithTitle(context, R.string.label_file_name, song.title));
            trackLength.setText(makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(song.duration)));
        }
    }
    return dialog;
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) AudioHeader(org.jaudiotagger.audio.AudioHeader) CannotReadException(org.jaudiotagger.audio.exceptions.CannotReadException) InvalidAudioFrameException(org.jaudiotagger.audio.exceptions.InvalidAudioFrameException) Activity(android.app.Activity) IOException(java.io.IOException) TextView(android.widget.TextView) View(android.view.View) AudioFile(org.jaudiotagger.audio.AudioFile) Song(com.kabouzeid.gramophone.model.Song) TagException(org.jaudiotagger.tag.TagException) ReadOnlyFileException(org.jaudiotagger.audio.exceptions.ReadOnlyFileException) TextView(android.widget.TextView) File(java.io.File) AudioFile(org.jaudiotagger.audio.AudioFile) NonNull(androidx.annotation.NonNull)

Example 2 with Song

use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.

the class SongShareDialog method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Song song = getArguments().getParcelable("song");
    final String currentlyListening = getString(R.string.currently_listening_to_x_by_x, song.title, song.artistName);
    return new MaterialDialog.Builder(getActivity()).title(R.string.what_do_you_want_to_share).items(getString(R.string.the_audio_file), "\u201C" + currentlyListening + "\u201D").itemsCallback((materialDialog, view, i, charSequence) -> {
        switch(i) {
            case 0:
                startActivity(Intent.createChooser(MusicUtil.createShareSongFileIntent(song, getContext()), null));
                break;
            case 1:
                getActivity().startActivity(Intent.createChooser(new Intent().setAction(Intent.ACTION_SEND).putExtra(Intent.EXTRA_TEXT, currentlyListening).setType("text/plain"), null));
                break;
        }
    }).build();
}
Also used : MusicUtil(com.kabouzeid.gramophone.util.MusicUtil) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) Song(com.kabouzeid.gramophone.model.Song) Dialog(android.app.Dialog) Intent(android.content.Intent) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) R(com.kabouzeid.gramophone.R) DialogFragment(androidx.fragment.app.DialogFragment) Song(com.kabouzeid.gramophone.model.Song) Intent(android.content.Intent) NonNull(androidx.annotation.NonNull)

Example 3 with Song

use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.

the class ShuffleHelper method makeShuffleList.

public static void makeShuffleList(@NonNull List<Song> listToShuffle, final int current) {
    if (listToShuffle.isEmpty())
        return;
    if (current >= 0) {
        Song song = listToShuffle.remove(current);
        Collections.shuffle(listToShuffle);
        listToShuffle.add(0, song);
    } else {
        Collections.shuffle(listToShuffle);
    }
}
Also used : Song(com.kabouzeid.gramophone.model.Song)

Example 4 with Song

use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.

the class AlbumLoader method getAlbum.

@NonNull
public static Album getAlbum(@NonNull final Context context, long albumId) {
    List<Song> songs = SongLoader.getSongs(SongLoader.makeSongCursor(context, AudioColumns.ALBUM_ID + "=?", new String[] { String.valueOf(albumId) }, getSongLoaderSortOrder(context)));
    Album album = new Album(songs);
    sortSongsByTrackNumber(album);
    return album;
}
Also used : Song(com.kabouzeid.gramophone.model.Song) Album(com.kabouzeid.gramophone.model.Album) NonNull(androidx.annotation.NonNull)

Example 5 with Song

use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.

the class AppWidgetCard method performUpdate.

/**
 * Update all active widget instances by pushing changes
 */
public void performUpdate(final MusicService service, final int[] appWidgetIds) {
    final RemoteViews appWidgetView = new RemoteViews(service.getPackageName(), R.layout.app_widget_card);
    final boolean isPlaying = service.isPlaying();
    final Song song = service.getCurrentSong();
    // Set the titles and artwork
    if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
        appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
    } else {
        appWidgetView.setViewVisibility(R.id.media_titles, View.VISIBLE);
        appWidgetView.setTextViewText(R.id.title, song.title);
        appWidgetView.setTextViewText(R.id.text, getSongArtistAndAlbum(song));
    }
    // Set correct drawable for pause state
    int playPauseRes = isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp;
    appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, playPauseRes, MaterialValueHelper.getSecondaryTextColor(service, true))));
    // Set prev/next button drawables
    appWidgetView.setImageViewBitmap(R.id.button_next, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getSecondaryTextColor(service, true))));
    appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getSecondaryTextColor(service, true))));
    // Link actions buttons to intents
    linkButtons(service, appWidgetView);
    if (imageSize == 0)
        imageSize = service.getResources().getDimensionPixelSize(R.dimen.app_widget_card_image_size);
    if (cardRadius == 0f)
        cardRadius = service.getResources().getDimension(R.dimen.app_widget_card_radius);
    // Load the album cover async and push the update on completion
    service.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            if (target != null) {
                Glide.clear(target);
            }
            target = SongGlideRequest.Builder.from(Glide.with(service), song).checkIgnoreMediaStore(service).generatePalette(service).build().centerCrop().into(new SimpleTarget<BitmapPaletteWrapper>(imageSize, imageSize) {

                @Override
                public void onResourceReady(BitmapPaletteWrapper resource, GlideAnimation<? super BitmapPaletteWrapper> glideAnimation) {
                    Palette palette = resource.getPalette();
                    update(resource.getBitmap(), palette.getVibrantColor(palette.getMutedColor(MaterialValueHelper.getSecondaryTextColor(service, true))));
                }

                @Override
                public void onLoadFailed(Exception e, Drawable errorDrawable) {
                    super.onLoadFailed(e, errorDrawable);
                    update(null, MaterialValueHelper.getSecondaryTextColor(service, true));
                }

                private void update(@Nullable Bitmap bitmap, int color) {
                    // Set correct drawable for pause state
                    int playPauseRes = isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp;
                    appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, playPauseRes, color)));
                    // Set prev/next button drawables
                    appWidgetView.setImageViewBitmap(R.id.button_next, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, color)));
                    appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, color)));
                    final Drawable image = getAlbumArtDrawable(service.getResources(), bitmap);
                    final Bitmap roundedBitmap = createRoundedBitmap(image, imageSize, imageSize, cardRadius, 0, cardRadius, 0);
                    appWidgetView.setImageViewBitmap(R.id.image, roundedBitmap);
                    pushUpdate(service, appWidgetIds, appWidgetView);
                }
            });
        }
    });
}
Also used : Palette(androidx.palette.graphics.Palette) BitmapPaletteWrapper(com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper) Drawable(android.graphics.drawable.Drawable) RemoteViews(android.widget.RemoteViews) Song(com.kabouzeid.gramophone.model.Song) Bitmap(android.graphics.Bitmap)

Aggregations

Song (com.kabouzeid.gramophone.model.Song)37 Drawable (android.graphics.drawable.Drawable)11 Intent (android.content.Intent)8 Bitmap (android.graphics.Bitmap)7 Point (android.graphics.Point)6 NonNull (androidx.annotation.NonNull)6 Activity (android.app.Activity)5 RemoteViews (android.widget.RemoteViews)5 BitmapPaletteWrapper (com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper)5 AbsSlidingMusicPanelActivity (com.kabouzeid.gramophone.ui.activities.base.AbsSlidingMusicPanelActivity)5 Context (android.content.Context)4 AsyncTask (android.os.AsyncTask)4 TextView (android.widget.TextView)4 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)4 Palette (androidx.palette.graphics.Palette)4 PendingIntent (android.app.PendingIntent)3 View (android.view.View)3 SleepTimerDialog (com.kabouzeid.gramophone.dialogs.SleepTimerDialog)3 ArrayList (java.util.ArrayList)3 ContentValues (android.content.ContentValues)2