Example usage for android.media MediaMetadataRetriever METADATA_KEY_GENRE

List of usage examples for android.media MediaMetadataRetriever METADATA_KEY_GENRE

Introduction

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

Prototype

int METADATA_KEY_GENRE

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

Click Source Link

Document

The metadata key to retrieve the content type or genre of the data source.

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:org.videolan.vlc.AudioService.java

@TargetApi(14)
private void updateRemoteControlClientMetadata() {
    if (!Util.isICSOrLater()) // NOP check
        return;//from  w w w. jav  a2 s  . c  om

    if (mRemoteControlClient != null) {
        MetadataEditor editor = mRemoteControlClient.editMetadata(true);
        editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, mCurrentMedia.getAlbum());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, mCurrentMedia.getArtist());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_GENRE, mCurrentMedia.getGenre());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, mCurrentMedia.getTitle());
        editor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, mCurrentMedia.getLength());
        editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, getCover());
        editor.apply();
    }
}

From source file:com.yamin.kk.service.AudioService.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void updateRemoteControlClientMetadata() {
    if (!Util.isICSOrLater()) // NOP check
        return;/*from ww w  . j  ava  2s. c o m*/

    if (mRemoteControlClient != null) {
        MetadataEditor editor = mRemoteControlClient.editMetadata(true);
        editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, getCurrentMedia().getAlbum());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, getCurrentMedia().getArtist());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_GENRE, getCurrentMedia().getGenre());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, getCurrentMedia().getTitle());
        editor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, getCurrentMedia().getLength());
        editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, getCover());
        editor.apply();
    }
}

From source file:org.videolan.myvlc.core.mediaController.AudioService.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void updateRemoteControlClientMetadata() {
    if (!Util.isICSOrLater()) // NOP check
        return;/*from  ww  w  .ja  va  2 s  .co m*/

    if (mRemoteControlClient != null) {
        MetadataEditor editor = mRemoteControlClient.editMetadata(true);
        editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, mCurrentMedia.getAlbum());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, mCurrentMedia.getArtist());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_GENRE, mCurrentMedia.getGenre());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, mCurrentMedia.getTitle());
        editor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, mCurrentMedia.getLength());
        editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, getCover());
        editor.apply();
    }
}

From source file:org.videolan.vlc.audio.AudioService.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void updateRemoteControlClientMetadata() {
    if (!LibVlcUtil.isICSOrLater()) // NOP check
        return;//from  w  w w  . j a  v a2  s.c  o  m

    Media media = getCurrentMedia();
    if (mRemoteControlClient != null && media != null) {
        MetadataEditor editor = mRemoteControlClient.editMetadata(true);
        editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, media.getAlbum());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, media.getArtist());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_GENRE, media.getGenre());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, media.getTitle());
        editor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, media.getLength());
        // Copy the cover bitmap because the RemonteControlClient can recycle its artwork bitmap.
        Bitmap cover = getCover();
        editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK,
                ((cover != null) ? cover.copy(cover.getConfig(), false) : null));
        editor.apply();
    }
}

From source file:org.videolan.vlc2.audio.AudioService.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void updateRemoteControlClientMetadata() {
    if (!LibVlcUtil.isICSOrLater()) // NOP check
        return;/*  w  w w . j ava 2  s.com*/

    Media media = getCurrentMedia();
    if (mRemoteControlClient != null && media != null) {
        MetadataEditor editor = mRemoteControlClient.editMetadata(true);
        editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, media.getAlbum());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, media.getArtist());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, media.getArtist());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_GENRE, media.getGenre());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, media.getTitle());
        editor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, media.getLength());
        // Copy the cover bitmap because the RemonteControlClient can recycle its artwork bitmap.
        Bitmap cover = getCover();
        editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK,
                ((cover != null) ? cover.copy(cover.getConfig(), false) : null));
        editor.apply();
    }
}

From source file:com.dzt.musicplay.player.AudioService.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void updateRemoteControlClientMetadata() {
    if (!LibVlcUtil.isICSOrLater()) // NOP check
        return;/*from w  ww.j  a  va 2 s .c  o  m*/

    Media media = getCurrentMedia();
    if (mRemoteControlClient != null && media != null) {
        MetadataEditor editor = mRemoteControlClient.editMetadata(true);
        editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, media.getAlbum());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, media.getArtist());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_GENRE, media.getGenre());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, media.getTitle());
        editor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, media.getLength());
        // Copy the cover bitmap because the RemonteControlClient can
        // recycle its artwork bitmap.
        Bitmap cover = getCover();
        editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK,
                ((cover != null) ? cover.copy(cover.getConfig(), false) : null));
        editor.apply();
    }
}

From source file:org.videolan.vlc.PlaybackService.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void updateRemoteControlClientMetadata() {
    if (!AndroidUtil.isICSOrLater()) // NOP check
        return;//www.ja v  a  2 s.  c o  m

    MediaWrapper media = getCurrentMedia();
    if (mRemoteControlClient != null && media != null) {
        MetadataEditor editor = mRemoteControlClient.editMetadata(true);
        if (media.getNowPlaying() != null) {
            editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, "");
            editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, "");
            editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, media.getNowPlaying());
        } else {
            editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, "");
            editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, Util.getMediaAlbum(this, media));
            editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, Util.getMediaArtist(this, media));
        }
        editor.putString(MediaMetadataRetriever.METADATA_KEY_GENRE, Util.getMediaGenre(this, media));
        editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, media.getTitle());
        editor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, media.getLength());

        // Copy the cover bitmap because the RemonteControlClient can recycle its artwork bitmap.
        Bitmap cover = AudioUtil.getCover(this, media, 512);
        if (cover != null && cover.getConfig() != null) //In case of format not supported
            editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, (cover.copy(cover.getConfig(), false)));

        editor.apply();
    }

    //Send metadata to Pebble watch
    if (media != null && mPebbleEnabled) {
        final Intent i = new Intent("com.getpebble.action.NOW_PLAYING");
        i.putExtra("artist", Util.getMediaArtist(this, media));
        i.putExtra("album", Util.getMediaAlbum(this, media));
        i.putExtra("track", media.getTitle());
        sendBroadcast(i);
    }
}

From source file:com.adityarathi.muo.services.AudioPlaybackService.java

/**
 * This method combines the current cursor with the specified playlist cursor.
 * @param newCursor/*from ww  w  .ja va  2  s  . c  o  m*/
 */
public void enqueuePlaylistCursor(Cursor newCursor) {

    String[] matrixCursorColumns = { DBAccessHelper.SONG_ARTIST, DBAccessHelper.SONG_ALBUM,
            DBAccessHelper.SONG_TITLE, DBAccessHelper.SONG_FILE_PATH, DBAccessHelper.SONG_DURATION,
            DBAccessHelper.SONG_GENRE, DBAccessHelper.SONG_ID, DBAccessHelper.SONG_ALBUM_ART_PATH,
            DBAccessHelper.SONG_SOURCE };

    //Create an empty matrix getCursor() with the specified columns.
    MatrixCursor mMatrixCursor = new MatrixCursor(matrixCursorColumns);

    //Make a copy of the old getCursor() and copy it's contents over to the matrix getCursor().
    Cursor tempCursor = getCursor();

    tempCursor.moveToFirst();
    MediaMetadataRetriever mMMDR = new MediaMetadataRetriever();
    for (int i = 0; i < tempCursor.getCount(); i++) {
        tempCursor.moveToPosition(i);

        //Check which type of getCursor() the service currently has.
        if (getCursor().getColumnIndex(DBAccessHelper.SONG_FILE_PATH) == -1) {

            //We'll have to manually extract the info from the audio file.
            /*            String songFilePath = tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.PLAYLIST_SONG_FILE_PATH));
                                
                        try {
                           mMMDR.setDataSource(songFilePath);
                        } catch (Exception e) {
                           //Skip the song if there's a problem with reading it.
                           continue;
                        }*/

            String songArtist = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
            String songAlbum = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
            String songTitle = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
            String songDuration = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
            String songGenre = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE);

            mMatrixCursor
                    .addRow(new Object[] { songArtist, songAlbum, songTitle, "", songDuration, songGenre });

        } else {

            mMatrixCursor.addRow(
                    new Object[] { tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_ARTIST)),
                            tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_ALBUM)),
                            tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_TITLE)),
                            tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_FILE_PATH)),
                            tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_DURATION)),
                            tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_GENRE)),
                            tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_ID)),
                            tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_ALBUM_ART_PATH)),
                            tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_SOURCE)) });

        }

    }

    tempCursor.close();

    //Copy the contents of the new getCursor() over to the MatrixCursor.
    if (newCursor.getCount() > 0) {

        String songArtist = "";
        String songAlbum = "";
        String songTitle = "";
        String filePath = "";
        String songDuration = "";
        for (int j = 0; j < newCursor.getCount(); j++) {
            /*            newCursor.moveToPosition(j);
                        filePath = newCursor.getString(newCursor.getColumnIndex(DBAccessHelper.PLAYLIST_SONG_FILE_PATH));
                                
                        try {
                           mMMDR.setDataSource(filePath);
                        } catch (Exception e) {
                           continue;
                        }*/

            //Get the metadata from the song file.
            songArtist = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
            songAlbum = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
            songTitle = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
            songDuration = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
            String songGenre = mMMDR.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE);

            mMatrixCursor.addRow(
                    new Object[] { songArtist, songAlbum, songTitle, filePath, songDuration, songGenre });

        }

    }

    mEnqueuePerformed = true;
    newCursor.close();
    mCursor = (Cursor) mMatrixCursor;
    mMatrixCursor.close();

}