List of usage examples for android.media MediaMetadataRetriever METADATA_KEY_ARTIST
int METADATA_KEY_ARTIST
To view the source code for android.media MediaMetadataRetriever METADATA_KEY_ARTIST.
Click Source Link
From source file:org.videolan.vlc.PlaybackService.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void updateRemoteControlClientMetadata() { if (!AndroidUtil.isICSOrLater()) // NOP check return;//from www . j ava 2s . 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:org.moire.ultrasonic.service.DownloadServiceImpl.java
private void updateRemoteControl() { if (!Util.isLockScreenEnabled(this)) { clearRemoteControl();/* w w w . jav a 2 s . co m*/ return; } if (remoteControlClient != null) { audioManager.unregisterRemoteControlClient(remoteControlClient); audioManager.registerRemoteControlClient(remoteControlClient); } else { setUpRemoteControlClient(); } Log.i(TAG, String.format("In updateRemoteControl, playerState: %s [%d]", playerState, getPlayerPosition())); switch (playerState) { case STARTED: if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); } else { remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING, getPlayerPosition(), 1.0f); } break; default: if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED); } else { remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED, getPlayerPosition(), 1.0f); } break; } if (currentPlaying != null) { MusicDirectory.Entry currentSong = currentPlaying.getSong(); Bitmap lockScreenBitmap = FileUtil.getAlbumArtBitmap(this, currentSong, Util.getMinDisplayMetric(this), true); String artist = currentSong.getArtist(); String album = currentSong.getAlbum(); String title = currentSong.getTitle(); Integer currentSongDuration = currentSong.getDuration(); Long duration = 0L; if (currentSongDuration != null) duration = (long) currentSongDuration * 1000; remoteControlClient.editMetadata(true).putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, artist) .putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, artist) .putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, album) .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, title) .putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, duration) .putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, lockScreenBitmap).apply(); } }
From source file:com.adityarathi.muo.services.AudioPlaybackService.java
/** * Updates all remote control clients (including the lockscreen controls). *//*from www . j a v a 2s. c o m*/ public void updateRemoteControlClients(SongHelper songHelper) { try { //Update the remote controls mRemoteControlClientCompat.editMetadata(true) .putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, getCurrentSong().getArtist()) .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, getCurrentSong().getTitle()) .putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, getCurrentSong().getAlbum()) .putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, getCurrentMediaPlayer().getDuration()) .putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, getCurrentSong().getAlbumArt()) .apply(); if (mRemoteControlClientCompat != null) { if (getCurrentMediaPlayer().isPlaying()) mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); else mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.Duo.music.player.Services.AudioPlaybackService.java
/** * Updates all remote control clients (including the lockscreen controls). *///from w ww. j a v a 2s .c o m public void updateRemoteControlClients(SongHelper songHelper) { try { //Update the remote controls mRemoteControlClientCompat.editMetadata(true) .putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, getCurrentSong().getArtist()) .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, getCurrentSong().getTitle()) .putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, getCurrentSong().getAlbum()) .putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, getCurrentMediaPlayer().getDuration()) .putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, getCurrentSong().getAlbumArt()) .apply(); if (mRemoteControlClientCompat != null) { if (getCurrentMediaPlayer().isPlaying()) mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); else mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.adityarathi.muo.services.AudioPlaybackService.java
/** * This method combines the current cursor with the specified playlist cursor. * @param newCursor//from w w w .j a v a2s . 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(); }
From source file:org.tomahawk.tomahawk_android.services.PlaybackService.java
/** * Update the playback controls/views which are being shown on the lockscreen */// w w w. ja v a 2 s.c om @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void updateLockscreenControls() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { Log.d(TAG, "updateLockscreenControls()"); // Use the media button APIs (if available) to register ourselves for media button // events MediaButtonHelper.registerMediaButtonEventReceiverCompat(mAudioManager, mMediaButtonReceiverComponent); if (mRemoteControlClientCompat == null) { Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON); intent.setComponent(mMediaButtonReceiverComponent); mRemoteControlClientCompat = new RemoteControlClientCompat( PendingIntent.getBroadcast(PlaybackService.this /*context*/, 0 /*requestCode, ignored*/, intent /*intent*/, 0 /*flags*/)); RemoteControlHelper.registerRemoteControlClient(mAudioManager, mRemoteControlClientCompat); } // Use the remote control APIs (if available) to set the playback state if (isPlaying()) { mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); } else { mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED); } int flags = RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE; if (hasNextEntry()) { flags |= RemoteControlClient.FLAG_KEY_MEDIA_NEXT; } if (hasPreviousEntry()) { flags |= RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS; } mRemoteControlClientCompat.setTransportControlFlags(flags); // Update the remote controls synchronized (this) { RemoteControlClientCompat.MetadataEditorCompat editor = mRemoteControlClientCompat .editMetadata(true); editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, getCurrentQuery().getArtist().getPrettyName()) .putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, getCurrentQuery().getArtist().getPrettyName()) .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, getCurrentQuery().getPrettyName()) .putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, getCurrentQuery().getPreferredTrack().getDuration()); if (!TextUtils.isEmpty(getCurrentQuery().getAlbum().getPrettyName())) { editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, getCurrentQuery().getAlbum().getPrettyName()); } editor.apply(); Log.d(TAG, "Setting lockscreen metadata to: " + getCurrentQuery().getArtist().getPrettyName() + ", " + getCurrentQuery().getPrettyName()); } Picasso.with(TomahawkApp.getContext()).cancelRequest(mLockscreenTarget); ImageUtils.loadImageIntoBitmap(TomahawkApp.getContext(), getCurrentQuery().getImage(), mLockscreenTarget, Image.getLargeImageSize(), getCurrentQuery().hasArtistImage()); } }
From source file:com.andrew.apollo.MusicPlaybackService.java
private static void changeRemoteControlClientTask(MusicPlaybackService musicPlaybackService, int playState, long position) { // background portion Bitmap albumArt = musicPlaybackService.getAlbumArt(); // RemoteControlClient wants to recycle the bitmaps thrown at it, so we need // to make sure not to hand out our cache copy Bitmap.Config config = null;/* w w w. j a v a 2 s.c o m*/ if (albumArt != null) { config = albumArt.getConfig(); } if (config == null) { config = Bitmap.Config.ARGB_8888; } Bitmap bmpCopy = null; try { if (albumArt != null) { bmpCopy = albumArt.copy(config, false); } } catch (OutOfMemoryError e) { // ignore, can't do anything meaningful here } final Bitmap albumArtCopy = bmpCopy; final String artistName = musicPlaybackService.getArtistName(); final String albumName = musicPlaybackService.getAlbumName(); final String trackName = musicPlaybackService.getTrackName(); final String albumArtistName = musicPlaybackService.getAlbumArtistName(); final long duration = musicPlaybackService.duration(); // MusicPlayerHandler thread portion, we can't put this as a PostContextTask // in Async.async. final WeakReference<MusicPlaybackService> musicPlaybackServiceRef = Ref.weak(musicPlaybackService); Runnable postExecute = () -> { if (!Ref.alive(musicPlaybackServiceRef)) { return; } MusicPlaybackService musicPlaybackService1 = musicPlaybackServiceRef.get(); try { RemoteControlClient.MetadataEditor editor = musicPlaybackService1.mRemoteControlClient .editMetadata(true).putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, artistName) .putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, albumArtistName) .putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, albumName) .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, trackName) .putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, duration); if (albumArtCopy != null) { editor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, albumArtCopy); } editor.apply(); } catch (Throwable t) { // possible NPE on android.media.RemoteControlClient$MetadataEditor.apply() } musicPlaybackService1.mRemoteControlClient.setPlaybackState(playState, position, 1.0f); }; musicPlaybackService.mPlayerHandler.post(postExecute); }
From source file:androidx.media.widget.VideoView2.java
@SuppressWarnings("deprecation") private void extractAudioMetadata() { if (!mIsMusicMediaType) { return;/*from w ww . j a va2s . com*/ } mResources = getResources(); mManager = (WindowManager) getContext().getApplicationContext().getSystemService(Context.WINDOW_SERVICE); byte[] album = mRetriever.getEmbeddedPicture(); if (album != null) { Bitmap bitmap = BitmapFactory.decodeByteArray(album, 0, album.length); mMusicAlbumDrawable = new BitmapDrawable(bitmap); // TODO: replace with visualizer Palette.Builder builder = Palette.from(bitmap); builder.generate(new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { // TODO: add dominant color for default album image. mDominantColor = palette.getDominantColor(0); if (mMusicView != null) { mMusicView.setBackgroundColor(mDominantColor); } } }); } else { mMusicAlbumDrawable = mResources.getDrawable(R.drawable.ic_default_album_image); } String title = mRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE); if (title != null) { mMusicTitleText = title; } else { mMusicTitleText = mResources.getString(R.string.mcv2_music_title_unknown_text); } String artist = mRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST); if (artist != null) { mMusicArtistText = artist; } else { mMusicArtistText = mResources.getString(R.string.mcv2_music_artist_unknown_text); } // Send title and artist string to MediaControlView2 MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder(); builder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, mMusicTitleText); builder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, mMusicArtistText); mMediaSession.setMetadata(builder.build()); // Display Embedded mode as default removeView(mSurfaceView); removeView(mTextureView); inflateMusicView(R.layout.embedded_music); }