Example usage for android.media MediaMetadataRetriever METADATA_KEY_YEAR

List of usage examples for android.media MediaMetadataRetriever METADATA_KEY_YEAR

Introduction

In this page you can find the example usage for android.media MediaMetadataRetriever METADATA_KEY_YEAR.

Prototype

int METADATA_KEY_YEAR

To view the source code for android.media MediaMetadataRetriever METADATA_KEY_YEAR.

Click Source Link

Document

The metadata key to retrieve the year when the data source was created or modified.

Usage

From source file:com.twistedequations.rotor.MediaMetadataCompat.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private static void fillEditorKeyMapping() {
    EDITOR_KEY_MAPPING = new SparseArray<String>();
    EDITOR_KEY_MAPPING.put(MediaMetadataEditor.BITMAP_KEY_ARTWORK, METADATA_KEY_ART);
    EDITOR_KEY_MAPPING.put(MediaMetadataEditor.RATING_KEY_BY_OTHERS, METADATA_KEY_RATING);
    EDITOR_KEY_MAPPING.put(MediaMetadataEditor.RATING_KEY_BY_USER, METADATA_KEY_USER_RATING);
    EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_ALBUM, METADATA_KEY_ALBUM);
    EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, METADATA_KEY_ALBUM_ARTIST);
    EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_ARTIST, METADATA_KEY_ARTIST);
    EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_AUTHOR, METADATA_KEY_AUTHOR);
    EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER, METADATA_KEY_TRACK_NUMBER);
    EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_COMPOSER, METADATA_KEY_COMPOSER);
    EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_COMPILATION, METADATA_KEY_COMPILATION);
    EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_DATE, METADATA_KEY_DATE);
    EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_DISC_NUMBER, METADATA_KEY_DISC_NUMBER);
    EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_DURATION, METADATA_KEY_DURATION);
    EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_GENRE, METADATA_KEY_GENRE);
    EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_NUM_TRACKS, METADATA_KEY_NUM_TRACKS);
    EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_TITLE, METADATA_KEY_TITLE);
    EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_WRITER, METADATA_KEY_WRITER);
    EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_YEAR, METADATA_KEY_YEAR);
}

From source file:com.twistedequations.rotor.MediaMetadataCompat.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private static void fillEditorTypeMapping() {
    EDITOR_KEYS_TYPE = new SparseArray<Integer>(26);
    EDITOR_KEYS_TYPE.put(MediaMetadataEditor.BITMAP_KEY_ARTWORK, METADATA_TYPE_BITMAP);
    EDITOR_KEYS_TYPE.put(MediaMetadataEditor.RATING_KEY_BY_OTHERS, METADATA_TYPE_RATING);
    EDITOR_KEYS_TYPE.put(MediaMetadataEditor.RATING_KEY_BY_USER, METADATA_TYPE_RATING);
    EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_ALBUM, METADATA_TYPE_TEXT);
    EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, METADATA_TYPE_TEXT);
    EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_ARTIST, METADATA_TYPE_TEXT);
    EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_AUTHOR, METADATA_TYPE_TEXT);
    EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER, METADATA_TYPE_LONG);
    EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_COMPOSER, METADATA_TYPE_TEXT);
    EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_COMPILATION, METADATA_TYPE_TEXT);
    EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_DATE, METADATA_TYPE_TEXT);
    EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_DISC_NUMBER, METADATA_TYPE_LONG);
    EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_DURATION, METADATA_TYPE_LONG);
    EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_YEAR, METADATA_TYPE_LONG);
    EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_GENRE, METADATA_TYPE_TEXT);
    EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_TITLE, METADATA_TYPE_TEXT);
    EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_WRITER, METADATA_TYPE_TEXT);
}

From source file:github.daneren2005.dsub.fragments.SubsonicFragment.java

public void displaySongInfo(final Entry song) {
    Integer duration = null;/*w  ww  .  j a  v  a2  s .  co  m*/
    Integer bitrate = null;
    String format = null;
    long size = 0;
    if (!song.isDirectory()) {
        try {
            DownloadFile downloadFile = new DownloadFile(context, song, false);
            File file = downloadFile.getCompleteFile();
            if (file.exists()) {
                MediaMetadataRetriever metadata = new MediaMetadataRetriever();
                metadata.setDataSource(file.getAbsolutePath());

                String tmp = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
                duration = Integer.parseInt((tmp != null) ? tmp : "0") / 1000;
                format = FileUtil.getExtension(file.getName());
                size = file.length();

                // If no duration try to read bitrate tag
                if (duration == null) {
                    tmp = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE);
                    bitrate = Integer.parseInt((tmp != null) ? tmp : "0") / 1000;
                } else {
                    // Otherwise do a calculation for it
                    // Divide by 1000 so in kbps
                    bitrate = (int) (size / duration) / 1000 * 8;
                }

                if (Util.isOffline(context)) {
                    song.setGenre(metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE));
                    String year = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR);
                    song.setYear(Integer.parseInt((year != null) ? year : "0"));
                }
            }
        } catch (Exception e) {
            Log.i(TAG, "Device doesn't properly support MediaMetadataRetreiver");
        }
    }
    if (duration == null) {
        duration = song.getDuration();
    }

    List<Integer> headers = new ArrayList<>();
    List<String> details = new ArrayList<>();

    if (!song.isDirectory()) {
        headers.add(R.string.details_title);
        details.add(song.getTitle());
    }

    if (song instanceof PodcastEpisode) {
        headers.add(R.string.details_podcast);
        details.add(song.getArtist());

        headers.add(R.string.details_status);
        details.add(((PodcastEpisode) song).getStatus());
    } else if (!song.isVideo()) {
        if (song.getArtist() != null && !"".equals(song.getArtist())) {
            headers.add(R.string.details_artist);
            details.add(song.getArtist());
        }
        if (song.getAlbum() != null && !"".equals(song.getAlbum())) {
            headers.add(R.string.details_album);
            details.add(song.getAlbum());
        }
    }
    if (song.getTrack() != null && song.getTrack() != 0) {
        headers.add(R.string.details_track);
        details.add(Integer.toString(song.getTrack()));
    }
    if (song.getGenre() != null && !"".equals(song.getGenre())) {
        headers.add(R.string.details_genre);
        details.add(song.getGenre());
    }
    if (song.getYear() != null && song.getYear() != 0) {
        headers.add(R.string.details_year);
        details.add(Integer.toString(song.getYear()));
    }
    if (!Util.isOffline(context) && song.getSuffix() != null) {
        headers.add(R.string.details_server_format);
        details.add(song.getSuffix());

        if (song.getBitRate() != null && song.getBitRate() != 0) {
            headers.add(R.string.details_server_bitrate);
            details.add(song.getBitRate() + " kbps");
        }
    }
    if (format != null && !"".equals(format)) {
        headers.add(R.string.details_cached_format);
        details.add(format);
    }
    if (bitrate != null && bitrate != 0) {
        headers.add(R.string.details_cached_bitrate);
        details.add(bitrate + " kbps");
    }
    if (size != 0) {
        headers.add(R.string.details_size);
        details.add(Util.formatLocalizedBytes(size, context));
    }
    if (duration != null && duration != 0) {
        headers.add(R.string.details_length);
        details.add(Util.formatDuration(duration));
    }
    if (song.getBookmark() != null) {
        headers.add(R.string.details_bookmark_position);
        details.add(Util.formatDuration(song.getBookmark().getPosition() / 1000));
    }
    if (song.getRating() != 0) {
        headers.add(R.string.details_rating);
        details.add(song.getRating() + " stars");
    }

    headers.add(R.string.details_starred);
    details.add(Util.formatBoolean(context, song.isStarred()));

    if (song instanceof PodcastEpisode) {
        headers.add(R.string.details_description);
        details.add(song.getAlbum());
    }

    int title;
    if (song.isDirectory()) {
        title = R.string.details_title_album;
    } else if (song instanceof PodcastEpisode) {
        title = R.string.details_title_podcast;
    } else {
        title = R.string.details_title_song;
    }
    Util.showDetailsDialog(context, title, headers, details);
}

From source file:github.popeen.dsub.fragments.SubsonicFragment.java

public void displaySongInfo(final Entry song) {
    Integer duration = null;//from  ww w. j a v  a  2s .  com
    Integer bitrate = null;
    String format = null;
    long size = 0;
    if (!song.isDirectory()) {
        try {
            DownloadFile downloadFile = new DownloadFile(context, song, false);
            File file = downloadFile.getCompleteFile();
            if (file.exists()) {
                MediaMetadataRetriever metadata = new MediaMetadataRetriever();
                metadata.setDataSource(file.getAbsolutePath());

                String tmp = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
                duration = Integer.parseInt((tmp != null) ? tmp : "0") / 1000;
                format = FileUtil.getExtension(file.getName());
                size = file.length();

                // If no duration try to read bitrate tag
                if (duration == null) {
                    tmp = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE);
                    bitrate = Integer.parseInt((tmp != null) ? tmp : "0") / 1000;
                } else {
                    // Otherwise do a calculation for it
                    // Divide by 1000 so in kbps
                    bitrate = (int) (size / duration) / 1000 * 8;
                }

                if (Util.isOffline(context)) {
                    song.setGenre(metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE));
                    String year = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR);
                    song.setYear(Integer.parseInt((year != null) ? year : "0"));
                }
            }
        } catch (Exception e) {
            Log.i(TAG, "Device doesn't properly support MediaMetadataRetreiver");
        }
    }
    if (duration == null) {
        duration = song.getDuration();
    }

    List<Integer> headers = new ArrayList<>();
    List<String> details = new ArrayList<>();

    if (!song.isDirectory()) {
        headers.add(R.string.details_title);
        details.add(song.getTitle());
    }

    if (song instanceof PodcastEpisode) {
        headers.add(R.string.details_podcast);
        details.add(song.getArtist());

        headers.add(R.string.details_status);
        details.add(((PodcastEpisode) song).getStatus());
    } else if (!song.isVideo()) {
        if (song.getArtist() != null && !"".equals(song.getArtist())) {
            headers.add(R.string.details_artist);
            details.add(song.getArtist());
        }
        if (song.getAlbum() != null && !"".equals(song.getAlbum())) {
            headers.add(R.string.details_album);
            details.add(song.getAlbum());
        }
    }
    if (song.getTrack() != null && song.getTrack() != 0) {
        headers.add(R.string.details_track);
        details.add(Integer.toString(song.getTrack()));
    }
    if (song.getGenre() != null && !"".equals(song.getGenre())) {
        headers.add(R.string.details_genre);
        details.add(song.getGenre());
    }
    if (song.getYear() != null && song.getYear() != 0) {
        headers.add(R.string.details_year);
        details.add(Integer.toString(song.getYear()));
    }
    if (!Util.isOffline(context) && song.getSuffix() != null) {
        headers.add(R.string.details_server_format);
        details.add(song.getSuffix());

        if (song.getBitRate() != null && song.getBitRate() != 0) {
            headers.add(R.string.details_server_bitrate);
            details.add(song.getBitRate() + " kbps");
        }
    }
    if (format != null && !"".equals(format)) {
        headers.add(R.string.details_cached_format);
        details.add(format);
    }
    if (bitrate != null && bitrate != 0) {
        headers.add(R.string.details_cached_bitrate);
        details.add(bitrate + " kbps");
    }
    if (size != 0) {
        headers.add(R.string.details_size);
        details.add(Util.formatLocalizedBytes(size, context));
    }
    if (duration != null && duration != 0) {
        headers.add(R.string.details_length);
        details.add(Util.formatDuration(duration));
    }
    if (song.getBookmark() != null) {
        headers.add(R.string.details_bookmark_position);
        details.add(Util.formatDuration(song.getBookmark().getPosition() / 1000));
    }
    if (song.getRating() != 0) {
        headers.add(R.string.details_rating);
        details.add(song.getRating() + " stars");
    }

    headers.add(R.string.details_starred);
    details.add(Util.formatBoolean(context, song.isStarred()));

    try {
        Long[] dates = SongDBHandler.getHandler(context).getLastPlayed(song);
        if (dates != null && dates[0] != null && dates[0] > 0) {
            headers.add(R.string.details_last_played);
            details.add(Util.formatDate((dates[1] != null && dates[1] > dates[0]) ? dates[1] : dates[0]));
        }
    } catch (Exception e) {
        Log.e(TAG, "Failed to get last played", e);
    }

    if (song instanceof PodcastEpisode) {
        headers.add(R.string.details_description);
        details.add(song.getAlbum());
    }

    int title;
    if (song.isDirectory()) {
        title = R.string.details_title_album;
    } else if (song instanceof PodcastEpisode) {
        title = R.string.details_title_podcast;
    } else {
        title = R.string.details_title_song;
    }
    Util.showDetailsDialog(context, title, headers, details);
}