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:com.aniruddhc.acemusic.player.NowPlayingActivity.PlaylistPagerFlippedFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_playlist_pager_flipped, container, false);/* ww w . j av a 2 s.c o m*/ mContext = getActivity().getApplicationContext(); mApp = (Common) mContext; ratingBar = (RatingBar) rootView.findViewById(R.id.playlist_pager_flipped_rating_bar); lyricsRelativeLayout = (RelativeLayout) rootView.findViewById(R.id.lyricsRelativeLayout); lyricsTextView = (TextView) rootView.findViewById(R.id.playlist_pager_flipped_lyrics); headerTextView = (TextView) rootView.findViewById(R.id.playlist_pager_flipped_title); noLyricsFoundText = (TextView) rootView.findViewById(R.id.no_embedded_lyrics_found_text); lyricsTextView.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light")); lyricsTextView .setPaintFlags(lyricsTextView.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); headerTextView.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light")); headerTextView .setPaintFlags(headerTextView.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); noLyricsFoundText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light")); noLyricsFoundText.setPaintFlags( noLyricsFoundText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); lyricsRelativeLayout.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { //Fire a broadcast that notifies the PlaylistPager to update flip back to the album art. Intent intent = new Intent(broadcastMessage); intent.putExtra("MESSAGE", broadcastMessage); //Initialize the local broadcast manager. localBroadcastManager = LocalBroadcastManager.getInstance(mContext); localBroadcastManager.sendBroadcast(intent); return true; } }); //Get the file path of the current song. String updatedSongTitle = ""; String updatedSongArtist = ""; String songFilePath = ""; String songId = ""; MediaMetadataRetriever mmdr = new MediaMetadataRetriever(); tempCursor = mApp.getService().getCursor(); tempCursor.moveToPosition( mApp.getService().getPlaybackIndecesList().get(mApp.getService().getCurrentSongIndex())); if (tempCursor.getColumnIndex(DBAccessHelper.SONG_FILE_PATH) == -1) { //Retrieve the info from the file's metadata. songFilePath = tempCursor.getString(tempCursor.getColumnIndex(null)); mmdr.setDataSource(songFilePath); updatedSongTitle = mmdr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE); updatedSongArtist = mmdr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST); } else { /* Check if the cursor has the SONG_FILE_PATH column. If it does, we're dealing * with the SONGS table. If not, we're dealing with the PLAYLISTS table. We'll * retrieve data from the appropriate columns using this info. */ if (tempCursor.getColumnIndex(DBAccessHelper.SONG_FILE_PATH) == -1) { //We're dealing with the Playlists table. songFilePath = tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.PLAYLIST_FILE_PATH)); mmdr.setDataSource(songFilePath); updatedSongTitle = mmdr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE); updatedSongArtist = mmdr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST); } else { //We're dealing with the songs table. songFilePath = tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_FILE_PATH)); updatedSongTitle = tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_TITLE)); updatedSongArtist = tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_ARTIST)); songId = tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_ID)); } } headerTextView.setText(updatedSongTitle + " - " + updatedSongArtist); ratingBar.setStepSize(1); int rating = mApp.getDBAccessHelper().getSongRating(songId); ratingBar.setRating(rating); //Get the rating value for the song. AudioFile audioFile = null; File file = null; try { audioFile = null; file = new File(songFilePath); try { audioFile = AudioFileIO.read(file); } catch (CannotReadException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (org.jaudiotagger.tag.TagException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (ReadOnlyFileException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (InvalidAudioFrameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } try { final AudioFile finalizedAudioFile = audioFile; final String finalSongFilePath = songFilePath; final String finalSongId = songId; ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() { @Override public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { //Change the rating in the DB and the actual audio file itself. Log.e("DEBUG", ">>>>>RATING: " + rating); try { Tag tag = finalizedAudioFile.getTag(); tag.addField(FieldKey.RATING, "" + ((int) rating)); } catch (KeyNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FieldDataInvalidException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); Log.e("DEBUG", ">>>>>>>RATING FIELD NOT FOUND"); } try { finalizedAudioFile.commit(); } catch (CannotWriteException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } mApp.getDBAccessHelper().setSongRating(finalSongId, (int) rating); } }); //Check if the audio file has any embedded lyrics. String lyrics = null; try { Tag tag = audioFile.getTag(); lyrics = tag.getFirst(FieldKey.LYRICS); if (lyrics == null || lyrics.isEmpty()) { lyricsTextView.setVisibility(View.GONE); noLyricsFoundText.setVisibility(View.VISIBLE); return rootView; } //Since the song has embedded lyrics, display them in the layout. lyricsTextView.setVisibility(View.VISIBLE); noLyricsFoundText.setVisibility(View.GONE); lyricsTextView.setText(lyrics); } catch (Exception e) { e.printStackTrace(); lyricsTextView.setVisibility(View.GONE); noLyricsFoundText.setVisibility(View.VISIBLE); return rootView; } } catch (Exception e) { e.printStackTrace(); //Can't do much here. } return rootView; }
From source file:org.gateshipone.odyssey.utils.FileExplorerHelper.java
/** * create a TrackModel for the given File * if no entry in the mediadb is found a dummy TrackModel will be created *//*from w w w . j a v a 2 s . c o m*/ public TrackModel getTrackModelForFile(Context context, FileModel file) { TrackModel track = null; String urlString = file.getURLString(); if (mTrackHash.isEmpty()) { // lookup the current file in the media db String whereVal[] = { urlString }; String where = MediaStore.Audio.Media.DATA + "=?"; Cursor cursor = PermissionHelper.query(context, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, MusicLibraryHelper.projectionTracks, where, whereVal, MediaStore.Audio.Media.TRACK); if (cursor != null) { if (cursor.moveToFirst()) { String title = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE)); long duration = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media.DURATION)); int no = cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media.TRACK)); String artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST)); String album = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM)); String url = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA)); String albumKey = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_KEY)); long id = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media._ID)); track = new TrackModel(title, artist, album, albumKey, duration, no, url, id); } cursor.close(); } } else { // use pre built hash to lookup the file track = mTrackHash.get(urlString); } if (track == null) { // no entry in the media db was found so create a custom track try { // try to read the file metadata MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setDataSource(context, Uri.parse(FormatHelper.encodeFileURI(urlString))); String title = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE); if (title == null) { title = file.getName(); } String durationString = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); long duration = 0; if (durationString != null) { try { duration = Long.valueOf(durationString); } catch (NumberFormatException e) { duration = 0; } } String noString = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER); int no = -1; if (noString != null) { try { if (noString.contains("/")) { // if string has the format (trackNumber / numberOfTracks) String[] components = noString.split("/"); if (components.length > 0) { no = Integer.valueOf(components[0]); } } else { no = Integer.valueOf(noString); } } catch (NumberFormatException e) { no = -1; } } String artist = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST); String album = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM); String albumKey = "" + ((artist == null ? "" : artist) + (album == null ? "" : album)).hashCode(); track = new TrackModel(title, artist, album, albumKey, duration, no, urlString, -1); } catch (Exception e) { String albumKey = "" + file.getName().hashCode(); track = new TrackModel(file.getName(), "", "", albumKey, 0, -1, urlString, -1); } } return track; }
From source file:com.b44t.messenger.MusicPlayerService.java
@SuppressLint("NewApi") private void createNotification(MessageObject messageObject) { AudioInfo audioInfo = MediaController.getInstance().getAudioInfo(); MrPoortext pt = MrMailbox.getMsg(messageObject.getId()).getMediainfo(); String authorName = pt.getText1(); String songName = pt.getText2(); if (songName == null || songName.length() == 0) { TLRPC.Document document = messageObject.messageOwner.media.document; for (int i = 0; i < document.attributes.size(); i++) { TLRPC.DocumentAttribute attr = document.attributes.get(i); if (attr instanceof TLRPC.TL_documentAttributeAudio) { authorName = attr.performer; songName = attr.title;/*from ww w . j a va 2 s. co m*/ break; } } } if (songName == null || songName.length() == 0) { // preview of just recorded and not send voice messages authorName = ApplicationLoader.applicationContext.getString(R.string.FromSelf); songName = ApplicationLoader.applicationContext.getString(R.string.AttachVoiceMessage); } RemoteViews simpleContentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.player_small_notification); //Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class); //intent.setAction("com.b44t.messenger.openchat"+messageObject.getDialogId()); //intent.setFlags(32768); //PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, 0); Notification notification = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.drawable.notification_player) //.setContentIntent(contentIntent) .setContentTitle(songName).build(); notification.contentView = simpleContentView; setListeners(simpleContentView); Bitmap albumArt = audioInfo != null ? audioInfo.getSmallCover() : null; if (albumArt != null) { notification.contentView.setImageViewBitmap(R.id.player_album_art, albumArt); notification.contentView.setViewVisibility(R.id.player_album_art, View.VISIBLE); } else { notification.contentView.setViewVisibility(R.id.player_album_art, View.GONE); } { notification.contentView.setViewVisibility(R.id.player_next, View.VISIBLE); notification.contentView.setViewVisibility(R.id.player_previous, View.VISIBLE); if (MediaController.getInstance().isAudioPaused()) { notification.contentView.setViewVisibility(R.id.player_pause, View.GONE); notification.contentView.setViewVisibility(R.id.player_play, View.VISIBLE); } else { notification.contentView.setViewVisibility(R.id.player_pause, View.VISIBLE); notification.contentView.setViewVisibility(R.id.player_play, View.GONE); } } notification.contentView.setTextViewText(R.id.player_song_name, songName); notification.contentView.setTextViewText(R.id.player_author_name, authorName); notification.flags |= Notification.FLAG_ONGOING_EVENT; startForeground(5, notification); if (remoteControlClient != null) { RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, authorName); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, songName); if (audioInfo != null && audioInfo.getCover() != null) { try { metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, audioInfo.getCover()); } catch (Throwable e) { FileLog.e("messenger", e); } } metadataEditor.apply(); } }
From source file:com.achep.acdisplay.services.media.MediaController2KitKat.java
/** * Updates {@link #mMetadata metadata} from given remote metadata class. * This also updates play state.//from w ww . jav a 2 s.c om * * @param data Object of metadata to update from, or {@code null} to clear local metadata. * @see #clearMetadata() */ private void updateMetadata(@Nullable RemoteController.MetadataEditor data) { if (data == null) { if (mMetadata.isEmpty()) return; mMetadata.clear(); } else { mMetadata.title = data.getString(MediaMetadataRetriever.METADATA_KEY_TITLE, null); mMetadata.artist = data.getString(MediaMetadataRetriever.METADATA_KEY_ARTIST, null); mMetadata.album = data.getString(MediaMetadataRetriever.METADATA_KEY_ALBUM, null); mMetadata.duration = data.getLong(MediaMetadataRetriever.METADATA_KEY_DURATION, -1); mMetadata.bitmap = data.getBitmap(MediaMetadataEditor.BITMAP_KEY_ARTWORK, null); mMetadata.generateSubtitle(); } notifyOnMetadataChanged(); }
From source file:com.ferdi2005.secondgram.MusicPlayerService.java
@SuppressLint("NewApi") private void createNotification(MessageObject messageObject) { String songName = messageObject.getMusicTitle(); String authorName = messageObject.getMusicAuthor(); AudioInfo audioInfo = MediaController.getInstance().getAudioInfo(); RemoteViews simpleContentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.player_small_notification); RemoteViews expandedView = null;//from w ww.ja v a 2 s. c o m if (supportBigNotifications) { expandedView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.player_big_notification); } Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class); intent.setAction("com.tmessages.openplayer"); intent.setFlags(32768); PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, 0); Notification notification = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.drawable.player).setContentIntent(contentIntent).setContentTitle(songName).build(); notification.contentView = simpleContentView; if (supportBigNotifications) { notification.bigContentView = expandedView; } setListeners(simpleContentView); if (supportBigNotifications) { setListeners(expandedView); } Bitmap albumArt = audioInfo != null ? audioInfo.getSmallCover() : null; if (albumArt != null) { notification.contentView.setImageViewBitmap(R.id.player_album_art, albumArt); if (supportBigNotifications) { notification.bigContentView.setImageViewBitmap(R.id.player_album_art, albumArt); } } else { notification.contentView.setImageViewResource(R.id.player_album_art, R.drawable.nocover_small); if (supportBigNotifications) { notification.bigContentView.setImageViewResource(R.id.player_album_art, R.drawable.nocover_big); } } if (MediaController.getInstance().isDownloadingCurrentMessage()) { notification.contentView.setViewVisibility(R.id.player_pause, View.GONE); notification.contentView.setViewVisibility(R.id.player_play, View.GONE); notification.contentView.setViewVisibility(R.id.player_next, View.GONE); notification.contentView.setViewVisibility(R.id.player_previous, View.GONE); notification.contentView.setViewVisibility(R.id.player_progress_bar, View.VISIBLE); if (supportBigNotifications) { notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE); notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE); notification.bigContentView.setViewVisibility(R.id.player_next, View.GONE); notification.bigContentView.setViewVisibility(R.id.player_previous, View.GONE); notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.VISIBLE); } } else { notification.contentView.setViewVisibility(R.id.player_progress_bar, View.GONE); notification.contentView.setViewVisibility(R.id.player_next, View.VISIBLE); notification.contentView.setViewVisibility(R.id.player_previous, View.VISIBLE); if (supportBigNotifications) { notification.bigContentView.setViewVisibility(R.id.player_next, View.VISIBLE); notification.bigContentView.setViewVisibility(R.id.player_previous, View.VISIBLE); notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.GONE); } if (MediaController.getInstance().isAudioPaused()) { notification.contentView.setViewVisibility(R.id.player_pause, View.GONE); notification.contentView.setViewVisibility(R.id.player_play, View.VISIBLE); if (supportBigNotifications) { notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE); notification.bigContentView.setViewVisibility(R.id.player_play, View.VISIBLE); } } else { notification.contentView.setViewVisibility(R.id.player_pause, View.VISIBLE); notification.contentView.setViewVisibility(R.id.player_play, View.GONE); if (supportBigNotifications) { notification.bigContentView.setViewVisibility(R.id.player_pause, View.VISIBLE); notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE); } } } notification.contentView.setTextViewText(R.id.player_song_name, songName); notification.contentView.setTextViewText(R.id.player_author_name, authorName); if (supportBigNotifications) { notification.bigContentView.setTextViewText(R.id.player_song_name, songName); notification.bigContentView.setTextViewText(R.id.player_author_name, authorName); } notification.flags |= Notification.FLAG_ONGOING_EVENT; startForeground(5, notification); if (remoteControlClient != null) { RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, authorName); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, songName); if (audioInfo != null && audioInfo.getCover() != null) { try { metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, audioInfo.getCover()); } catch (Throwable e) { FileLog.e(e); } } metadataEditor.apply(); } }
From source file:com.panahit.telegramma.MusicPlayerService.java
@SuppressLint("NewApi") private void createNotification(MessageObject messageObject) { String songName = messageObject.getMusicTitle(); String authorName = messageObject.getMusicAuthor(); AudioInfo audioInfo = MediaController.getInstance().getAudioInfo(); RemoteViews simpleContentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.player_small_notification); RemoteViews expandedView = null;/* w w w . j a v a2 s. c o m*/ if (supportBigNotifications) { expandedView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.player_big_notification); } Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class); intent.setAction("com.tmessages.openplayer"); intent.setFlags(32768); PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, 0); Notification notification = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.drawable.player).setContentIntent(contentIntent).setContentTitle(songName).build(); notification.contentView = simpleContentView; if (supportBigNotifications) { notification.bigContentView = expandedView; } setListeners(simpleContentView); if (supportBigNotifications) { setListeners(expandedView); } Bitmap albumArt = audioInfo != null ? audioInfo.getSmallCover() : null; if (albumArt != null) { notification.contentView.setImageViewBitmap(R.id.player_album_art, albumArt); if (supportBigNotifications) { notification.bigContentView.setImageViewBitmap(R.id.player_album_art, albumArt); } } else { notification.contentView.setImageViewResource(R.id.player_album_art, R.drawable.nocover_small); if (supportBigNotifications) { notification.bigContentView.setImageViewResource(R.id.player_album_art, R.drawable.nocover_big); } } if (MediaController.getInstance().isDownloadingCurrentMessage()) { notification.contentView.setViewVisibility(R.id.player_pause, View.GONE); notification.contentView.setViewVisibility(R.id.player_play, View.GONE); notification.contentView.setViewVisibility(R.id.player_next, View.GONE); notification.contentView.setViewVisibility(R.id.player_previous, View.GONE); notification.contentView.setViewVisibility(R.id.player_progress_bar, View.VISIBLE); if (supportBigNotifications) { notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE); notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE); notification.bigContentView.setViewVisibility(R.id.player_next, View.GONE); notification.bigContentView.setViewVisibility(R.id.player_previous, View.GONE); notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.VISIBLE); } } else { notification.contentView.setViewVisibility(R.id.player_progress_bar, View.GONE); notification.contentView.setViewVisibility(R.id.player_next, View.VISIBLE); notification.contentView.setViewVisibility(R.id.player_previous, View.VISIBLE); if (supportBigNotifications) { notification.bigContentView.setViewVisibility(R.id.player_next, View.VISIBLE); notification.bigContentView.setViewVisibility(R.id.player_previous, View.VISIBLE); notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.GONE); } if (MediaController.getInstance().isAudioPaused()) { notification.contentView.setViewVisibility(R.id.player_pause, View.GONE); notification.contentView.setViewVisibility(R.id.player_play, View.VISIBLE); if (supportBigNotifications) { notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE); notification.bigContentView.setViewVisibility(R.id.player_play, View.VISIBLE); } } else { notification.contentView.setViewVisibility(R.id.player_pause, View.VISIBLE); notification.contentView.setViewVisibility(R.id.player_play, View.GONE); if (supportBigNotifications) { notification.bigContentView.setViewVisibility(R.id.player_pause, View.VISIBLE); notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE); } } } notification.contentView.setTextViewText(R.id.player_song_name, songName); notification.contentView.setTextViewText(R.id.player_author_name, authorName); if (supportBigNotifications) { notification.bigContentView.setTextViewText(R.id.player_song_name, songName); notification.bigContentView.setTextViewText(R.id.player_author_name, authorName); } notification.flags |= Notification.FLAG_ONGOING_EVENT; startForeground(5, notification); if (remoteControlClient != null) { RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, authorName); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, songName); if (audioInfo != null && audioInfo.getCover() != null) { metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, audioInfo.getCover()); } metadataEditor.apply(); } }
From source file:ir.besteveryeverapp.telegram.MusicPlayerService.java
@SuppressLint("NewApi") private void createNotification(MessageObject messageObject) { String songName = messageObject.getMusicTitle(); String authorName = messageObject.getMusicAuthor(); AudioInfo audioInfo = MediaController.getInstance().getAudioInfo(); RemoteViews simpleContentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.player_small_notification); RemoteViews expandedView = null;/* w ww .j a v a 2 s .c o m*/ if (supportBigNotifications) { expandedView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.player_big_notification); } Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class); intent.setAction("com.tmessages.openplayer"); intent.setFlags(32768); PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, 0); Notification notification = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.drawable.player).setContentIntent(contentIntent).setContentTitle(songName).build(); notification.contentView = simpleContentView; if (supportBigNotifications) { notification.bigContentView = expandedView; } setListeners(simpleContentView); if (supportBigNotifications) { setListeners(expandedView); } Bitmap albumArt = audioInfo != null ? audioInfo.getSmallCover() : null; if (albumArt != null) { notification.contentView.setImageViewBitmap(R.id.player_album_art, albumArt); if (supportBigNotifications) { notification.bigContentView.setImageViewBitmap(R.id.player_album_art, albumArt); } } else { notification.contentView.setImageViewResource(R.id.player_album_art, R.drawable.nocover_small); if (supportBigNotifications) { notification.bigContentView.setImageViewResource(R.id.player_album_art, R.drawable.nocover_big); } } if (MediaController.getInstance().isDownloadingCurrentMessage()) { notification.contentView.setViewVisibility(R.id.player_pause, View.GONE); notification.contentView.setViewVisibility(R.id.player_play, View.GONE); notification.contentView.setViewVisibility(R.id.player_next, View.GONE); notification.contentView.setViewVisibility(R.id.player_previous, View.GONE); notification.contentView.setViewVisibility(R.id.player_progress_bar, View.VISIBLE); if (supportBigNotifications) { notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE); notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE); notification.bigContentView.setViewVisibility(R.id.player_next, View.GONE); notification.bigContentView.setViewVisibility(R.id.player_previous, View.GONE); notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.VISIBLE); } } else { notification.contentView.setViewVisibility(R.id.player_progress_bar, View.GONE); notification.contentView.setViewVisibility(R.id.player_next, View.VISIBLE); notification.contentView.setViewVisibility(R.id.player_previous, View.VISIBLE); if (supportBigNotifications) { notification.bigContentView.setViewVisibility(R.id.player_next, View.VISIBLE); notification.bigContentView.setViewVisibility(R.id.player_previous, View.VISIBLE); notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.GONE); } if (MediaController.getInstance().isAudioPaused()) { notification.contentView.setViewVisibility(R.id.player_pause, View.GONE); notification.contentView.setViewVisibility(R.id.player_play, View.VISIBLE); if (supportBigNotifications) { notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE); notification.bigContentView.setViewVisibility(R.id.player_play, View.VISIBLE); } } else { notification.contentView.setViewVisibility(R.id.player_pause, View.VISIBLE); notification.contentView.setViewVisibility(R.id.player_play, View.GONE); if (supportBigNotifications) { notification.bigContentView.setViewVisibility(R.id.player_pause, View.VISIBLE); notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE); } } } notification.contentView.setTextViewText(R.id.player_song_name, songName); notification.contentView.setTextViewText(R.id.player_author_name, authorName); if (supportBigNotifications) { notification.bigContentView.setTextViewText(R.id.player_song_name, songName); notification.bigContentView.setTextViewText(R.id.player_author_name, authorName); } notification.flags |= Notification.FLAG_ONGOING_EVENT; startForeground(5, notification); if (remoteControlClient != null) { RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, authorName); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, songName); if (audioInfo != null && audioInfo.getCover() != null) { try { metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, audioInfo.getCover()); } catch (Throwable e) { FileLog.e("tmessages", e); } } metadataEditor.apply(); } }
From source file:com.dmplayer.manager.MusicPlayerService.java
@SuppressLint("NewApi") private void createNotification(SongDetail mSongDetail) { try {//w w w . j a v a 2 s. c o m String songName = mSongDetail.getTitle(); String authorName = mSongDetail.getArtist(); SongDetail audioInfo = MediaController.getInstance().getPlayingSongDetail(); RemoteViews simpleContentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.player_small_notification); RemoteViews expandedView = null; if (supportBigNotifications) { expandedView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.player_big_notification); } Intent intent = new Intent(ApplicationDMPlayer.applicationContext, DMPlayerBaseActivity.class); intent.setAction("openplayer"); intent.setFlags(32768); PendingIntent contentIntent = PendingIntent.getActivity(ApplicationDMPlayer.applicationContext, 0, intent, 0); Notification notification = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.drawable.player).setContentIntent(contentIntent).setContentTitle(songName) .build(); notification.contentView = simpleContentView; if (supportBigNotifications) { notification.bigContentView = expandedView; } setListeners(simpleContentView); if (supportBigNotifications) { setListeners(expandedView); } Bitmap albumArt = audioInfo != null ? audioInfo.getSmallCover(ApplicationDMPlayer.applicationContext) : null; if (albumArt != null) { notification.contentView.setImageViewBitmap(R.id.player_album_art, albumArt); if (supportBigNotifications) { notification.bigContentView.setImageViewBitmap(R.id.player_album_art, albumArt); } } else { notification.contentView.setImageViewResource(R.id.player_album_art, R.drawable.bg_default_album_art); if (supportBigNotifications) { notification.bigContentView.setImageViewResource(R.id.player_album_art, R.drawable.bg_default_album_art); } } notification.contentView.setViewVisibility(R.id.player_progress_bar, View.GONE); notification.contentView.setViewVisibility(R.id.player_next, View.VISIBLE); notification.contentView.setViewVisibility(R.id.player_previous, View.VISIBLE); if (supportBigNotifications) { notification.bigContentView.setViewVisibility(R.id.player_next, View.VISIBLE); notification.bigContentView.setViewVisibility(R.id.player_previous, View.VISIBLE); notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.GONE); } if (MediaController.getInstance().isAudioPaused()) { notification.contentView.setViewVisibility(R.id.player_pause, View.GONE); notification.contentView.setViewVisibility(R.id.player_play, View.VISIBLE); if (supportBigNotifications) { notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE); notification.bigContentView.setViewVisibility(R.id.player_play, View.VISIBLE); } } else { notification.contentView.setViewVisibility(R.id.player_pause, View.VISIBLE); notification.contentView.setViewVisibility(R.id.player_play, View.GONE); if (supportBigNotifications) { notification.bigContentView.setViewVisibility(R.id.player_pause, View.VISIBLE); notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE); } } notification.contentView.setTextViewText(R.id.player_song_name, songName); notification.contentView.setTextViewText(R.id.player_author_name, authorName); if (supportBigNotifications) { notification.bigContentView.setTextViewText(R.id.player_song_name, songName); notification.bigContentView.setTextViewText(R.id.player_author_name, authorName); } notification.flags |= Notification.FLAG_ONGOING_EVENT; startForeground(5, notification); if (remoteControlClient != null) { RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, authorName); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, songName); if (audioInfo != null && audioInfo.getCover(ApplicationDMPlayer.applicationContext) != null) { metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, audioInfo.getCover(ApplicationDMPlayer.applicationContext)); } metadataEditor.apply(); audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.mantraideas.androidaudio.manager.MusicPlayerService.java
@SuppressLint("NewApi") private void createNotification(SongDetail mSongDetail) { try {/*from w w w . j a v a2s . c om*/ String songName = mSongDetail.getTitle(); String authorName = mSongDetail.getArtist(); SongDetail audioInfo = MediaController.getInstance().getPlayingSongDetail(); RemoteViews simpleContentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.player_small_notification); RemoteViews expandedView = null; if (supportBigNotifications) { expandedView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.player_big_notification); } Intent intent = new Intent(MyApplication.applicationContext, MainActivity.class); intent.setAction("openplayer"); intent.setFlags(32768); PendingIntent contentIntent = PendingIntent.getActivity(MyApplication.applicationContext, 0, intent, 0); Notification notification = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.drawable.player).setContentIntent(contentIntent).setContentTitle(songName) .build(); notification.contentView = simpleContentView; if (supportBigNotifications) { notification.bigContentView = expandedView; } setListeners(simpleContentView); if (supportBigNotifications) { setListeners(expandedView); } Bitmap albumArt = audioInfo != null ? audioInfo.getSmallCover(MyApplication.applicationContext) : null; if (albumArt != null) { notification.contentView.setImageViewBitmap(R.id.player_album_art, albumArt); if (supportBigNotifications) { notification.bigContentView.setImageViewBitmap(R.id.player_album_art, albumArt); } } else { notification.contentView.setImageViewResource(R.id.player_album_art, R.drawable.bg_default_album_art); if (supportBigNotifications) { notification.bigContentView.setImageViewResource(R.id.player_album_art, R.drawable.bg_default_album_art); } } notification.contentView.setViewVisibility(R.id.player_progress_bar, View.GONE); notification.contentView.setViewVisibility(R.id.player_next, View.VISIBLE); notification.contentView.setViewVisibility(R.id.player_previous, View.VISIBLE); if (supportBigNotifications) { notification.bigContentView.setViewVisibility(R.id.player_next, View.VISIBLE); notification.bigContentView.setViewVisibility(R.id.player_previous, View.VISIBLE); notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.GONE); } if (MediaController.getInstance().isAudioPaused()) { notification.contentView.setViewVisibility(R.id.player_pause, View.GONE); notification.contentView.setViewVisibility(R.id.player_play, View.VISIBLE); if (supportBigNotifications) { notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE); notification.bigContentView.setViewVisibility(R.id.player_play, View.VISIBLE); } } else { notification.contentView.setViewVisibility(R.id.player_pause, View.VISIBLE); notification.contentView.setViewVisibility(R.id.player_play, View.GONE); if (supportBigNotifications) { notification.bigContentView.setViewVisibility(R.id.player_pause, View.VISIBLE); notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE); } } notification.contentView.setTextViewText(R.id.player_song_name, songName); notification.contentView.setTextViewText(R.id.player_author_name, authorName); if (supportBigNotifications) { notification.bigContentView.setTextViewText(R.id.player_song_name, songName); notification.bigContentView.setTextViewText(R.id.player_author_name, authorName); } notification.flags |= Notification.FLAG_ONGOING_EVENT; startForeground(5, notification); if (remoteControlClient != null) { RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, authorName); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, songName); if (audioInfo != null && audioInfo.getCover(MyApplication.applicationContext) != null) { metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, audioInfo.getCover(MyApplication.applicationContext)); } metadataEditor.apply(); audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); } } catch (Exception e) { e.printStackTrace(); } }
From source file:kz.qobyzbook.manager.MusicPlayerService.java
@SuppressLint("NewApi") private void createNotification(SongDetail mSongDetail) { try {//from ww w.j a va 2 s . co m String songName = mSongDetail.getTitle(); String authorName = mSongDetail.getArtist(); String songImage = mSongDetail.getImage_url(); SongDetail audioInfo = MediaController.getInstance().getPlayingSongDetail(); RemoteViews simpleContentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.player_small_notification); RemoteViews expandedView = null; if (supportBigNotifications) { expandedView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.player_big_notification); } Intent intent = new Intent(ApplicationDMPlayer.applicationContext, DMPlayerBaseActivity.class); intent.setAction("openplayer"); intent.setFlags(32768); PendingIntent contentIntent = PendingIntent.getActivity(ApplicationDMPlayer.applicationContext, 0, intent, 0); Notification notification = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.drawable.player).setContentIntent(contentIntent).setContentTitle(songName) .build(); notification.contentView = simpleContentView; if (supportBigNotifications) { notification.bigContentView = expandedView; } setListeners(simpleContentView); if (supportBigNotifications) { setListeners(expandedView); } Bitmap albumArt = audioInfo != null ? audioInfo.getSmallCover(ApplicationDMPlayer.applicationContext) : null; if (albumArt != null) { notification.contentView.setImageViewBitmap(R.id.player_album_art, albumArt); if (supportBigNotifications) { notification.bigContentView.setImageViewBitmap(R.id.player_album_art, albumArt); } } else { notification.contentView.setImageViewResource(R.id.player_album_art, R.drawable.bg_default_album_art); if (supportBigNotifications) { notification.bigContentView.setImageViewResource(R.id.player_album_art, R.drawable.bg_default_album_art); } } notification.contentView.setViewVisibility(R.id.player_progress_bar, View.GONE); notification.contentView.setViewVisibility(R.id.player_next, View.VISIBLE); notification.contentView.setViewVisibility(R.id.player_previous, View.VISIBLE); if (supportBigNotifications) { notification.bigContentView.setViewVisibility(R.id.player_next, View.VISIBLE); notification.bigContentView.setViewVisibility(R.id.player_previous, View.VISIBLE); notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.GONE); } if (MediaController.getInstance().isAudioPaused()) { notification.contentView.setViewVisibility(R.id.player_pause, View.GONE); notification.contentView.setViewVisibility(R.id.player_play, View.VISIBLE); if (supportBigNotifications) { notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE); notification.bigContentView.setViewVisibility(R.id.player_play, View.VISIBLE); } } else { notification.contentView.setViewVisibility(R.id.player_pause, View.VISIBLE); notification.contentView.setViewVisibility(R.id.player_play, View.GONE); if (supportBigNotifications) { notification.bigContentView.setViewVisibility(R.id.player_pause, View.VISIBLE); notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE); } } notification.contentView.setTextViewText(R.id.player_song_name, songName); notification.contentView.setTextViewText(R.id.player_author_name, authorName); if (supportBigNotifications) { notification.bigContentView.setTextViewText(R.id.player_song_name, songName); notification.bigContentView.setTextViewText(R.id.player_author_name, authorName); // notification.bigContentView.setTextViewText(R.id.player_albumname, albumName); } notification.flags |= Notification.FLAG_ONGOING_EVENT; startForeground(5, notification); if (remoteControlClient != null) { RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, authorName); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, songName); if (audioInfo != null && audioInfo.getCover(ApplicationDMPlayer.applicationContext) != null) { metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, audioInfo.getCover(ApplicationDMPlayer.applicationContext)); } metadataEditor.apply(); audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); } } catch (Exception e) { e.printStackTrace(); } }