List of usage examples for android.media MediaMetadataRetriever METADATA_KEY_TITLE
int METADATA_KEY_TITLE
To view the source code for android.media MediaMetadataRetriever METADATA_KEY_TITLE.
Click Source Link
From source file:kz.qobyzbook.manager.MusicPlayerService.java
@SuppressLint("NewApi") private void createNotification(SongDetail mSongDetail) { try {/*from www .j a v a2 s. c o 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(); } }
From source file:co.codecrunch.musicplayerlite.manager.MusicPlayerService.java
@SuppressLint("NewApi") private void createNotification(SongDetail mSongDetail) { try {//w w w . j av a2 s . c o m String songName = mSongDetail.getTitle(); String authorName = mSongDetail.getArtist(); String albumName = mSongDetail.getDisplay_name(); 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(ApplicationMusicPlayer.applicationContext, MusicPlayerBaseActivity.class); intent.setAction("openplayer"); intent.setFlags(32768); PendingIntent contentIntent = PendingIntent.getActivity(ApplicationMusicPlayer.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(ApplicationMusicPlayer.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(ApplicationMusicPlayer.applicationContext) != null) { metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, audioInfo.getCover(ApplicationMusicPlayer.applicationContext)); } metadataEditor.apply(); audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); } } catch (Exception e) { e.printStackTrace(); } }
From source file:in.risysnetworks.shplayer.mediacontroller.MusicPlayerService.java
@SuppressLint("NewApi") private void createNotification(SongDetail mSongDetail) { try {/*ww w . j a v a2s . 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(ApplicationSHPlayer.applicationContext, SHPlayerMainActivity.class); intent.setAction("openplayer"); intent.setFlags(32768); PendingIntent contentIntent = PendingIntent.getActivity(ApplicationSHPlayer.applicationContext, 0, intent, 0); Notification notification = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.drawable.player).setContentIntent(contentIntent).setContentTitle(songName) .build(); if (supportBigNotifications) { notification.bigContentView = expandedView; } else { notification.contentView = simpleContentView; } if (supportBigNotifications) { setListeners(expandedView); } else { setListeners(simpleContentView); } Bitmap albumArt = audioInfo != null ? audioInfo.getSmallCover(ApplicationSHPlayer.applicationContext) : null; if (albumArt != null) { if (supportBigNotifications) { notification.bigContentView.setImageViewBitmap(R.id.player_album_art, albumArt); } else { notification.contentView.setImageViewBitmap(R.id.player_album_art, albumArt); } } else { if (supportBigNotifications) { notification.bigContentView.setImageViewResource(R.id.player_album_art, R.drawable.bg_default_album_art); } else { notification.contentView.setImageViewResource(R.id.player_album_art, R.drawable.bg_default_album_art); } } 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); } 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 (MediaController.getInstance().isAudioPaused()) { 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.GONE); notification.contentView.setViewVisibility(R.id.player_play, View.VISIBLE); } } else { if (supportBigNotifications) { notification.bigContentView.setViewVisibility(R.id.player_pause, View.VISIBLE); notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE); } else { notification.contentView.setViewVisibility(R.id.player_pause, View.VISIBLE); notification.contentView.setViewVisibility(R.id.player_play, View.GONE); } } if (supportBigNotifications) { notification.bigContentView.setTextViewText(R.id.player_song_name, songName); notification.bigContentView.setTextViewText(R.id.player_author_name, authorName); } else { 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(ApplicationSHPlayer.applicationContext) != null) { metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, audioInfo.getCover(ApplicationSHPlayer.applicationContext)); } metadataEditor.apply(); audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); } } catch (Exception e) { e.printStackTrace(); System.out.println(" error --> " + e.toString()); } }
From source file:com.goftagram.telegram.messenger.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 www . 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) { metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, audioInfo.getCover()); } metadataEditor.apply(); audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); } }
From source file:io.radio.streamer.MainActivity.java
@TargetApi(14) public void updateRemoteMetadata(String artist, String track) { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { MetadataEditor metaEditor = remoteControlClient.editMetadata(true); metaEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, track); metaEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, artist); metaEditor.apply();/* w ww . j ava 2 s.c o m*/ } Intent avrcp = new Intent("com.android.music.metachanged"); avrcp.putExtra("track", track); avrcp.putExtra("artist", artist); // avrcp.putExtra("album", "album name"); this.getApplicationContext().sendBroadcast(avrcp); }
From source file:be.ugent.zeus.hydra.util.audiostream.MusicService.java
/** * Starts playing the next song. If manualUrl is null, the next song will be randomly selected * from our Media Retriever (that is, it will be a random song in the user's device). If * manualUrl is non-null, then it specifies the URL or path to the song that will be played * next./*from w w w. ja v a2s.c o m*/ */ void playmp3(String mp3url) { mState = State.Stopped; relaxResources(false); // release everything except MediaPlayer try { // set the source of the media player to a manual URL or path createMediaPlayerIfNeeded(); mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mPlayer.setDataSource(mp3url); mIsStreaming = true; mSongTitle = "Urgent.fm"; mState = State.Preparing; setUpAsForeground(mSongTitle + " (loading)"); // Use the media button APIs (if available) to register ourselves for media button // events MediaButtonHelper.registerMediaButtonEventReceiverCompat(mAudioManager, mMediaButtonReceiverComponent); // Use the remote control APIs (if available) to set the playback state if (mRemoteControlClientCompat == null) { Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON); intent.setComponent(mMediaButtonReceiverComponent); mRemoteControlClientCompat = new RemoteControlClientCompat(PendingIntent.getBroadcast( this /*context*/, 0 /*requestCode, ignored*/, intent /*intent*/, 0 /*flags*/)); RemoteControlHelper.registerRemoteControlClient(mAudioManager, mRemoteControlClientCompat); } mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); mRemoteControlClientCompat.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_STOP); // Update the remote controls mRemoteControlClientCompat.editMetadata(true) .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, "Urgent.fm") .putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, mDummyAlbumArt) .apply(); // starts preparing the media player in the background. When it's done, it will call // our OnPreparedListener (that is, the onPrepared() method on this class, since we set // the listener to 'this'). // // Until the media player is prepared, we *cannot* call start() on it! mPlayer.prepareAsync(); // If we are streaming from the internet, we want to hold a Wifi lock, which prevents // the Wifi radio from going to sleep while the song is playing. If, on the other hand, // we are *not* streaming, we want to release the lock if we were holding it before. if (mIsStreaming) { mWifiLock.acquire(); } else if (mWifiLock.isHeld()) { mWifiLock.release(); } } catch (IOException ex) { Log.e("MusicService", "IOException playing next song: " + ex.getMessage()); ex.printStackTrace(); } }
From source file:de.qspool.clementineremote.backend.ClementinePlayerConnection.java
/** * Update the RemoteControlClient/*from w w w . ja va 2s . c om*/ */ private void updateRemoteControlClient() { // Update playstate if (App.mClementine.getState() == Clementine.State.PLAY) { mRcClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); } else { mRcClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED); } // Get the metadata editor if (mLastSong != null && mLastSong.getArt() != null) { RemoteControlClient.MetadataEditor editor = mRcClient.editMetadata(false); editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, mLastSong.getArt()); // The RemoteControlClients displays the following info: // METADATA_KEY_TITLE (white) - METADATA_KEY_ALBUMARTIST (grey) - METADATA_KEY_ALBUM (grey) // // So i put the metadata not in the "correct" fields to display artist, track and album // TODO: Fix it when changed in newer android versions editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, mLastSong.getAlbum()); editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, mLastSong.getArtist()); editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, mLastSong.getTitle()); editor.apply(); } }
From source file:com.andreadec.musicplayer.MusicService.java
private void updateNotificationMessage() { /* Update remote control client */ if (Build.VERSION.SDK_INT >= 14) { if (currentPlayingItem == null) { remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED); } else {/*from w w w .jav a 2 s.c o m*/ if (isPlaying()) { remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); } else { remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED); } RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, currentPlayingItem.getTitle()); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, currentPlayingItem.getArtist()); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, currentPlayingItem.getArtist()); metadataEditor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, getDuration()); if (currentPlayingItem.hasImage()) { metadataEditor.putBitmap(METADATA_KEY_ARTWORK, currentPlayingItem.getImage()); } else { metadataEditor.putBitmap(METADATA_KEY_ARTWORK, icon.copy(icon.getConfig(), false)); } metadataEditor.apply(); } } /* Update notification */ NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder.setSmallIcon(R.drawable.audio_white); //notificationBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)); notificationBuilder.setOngoing(true); int playPauseIcon = isPlaying() ? R.drawable.pause : R.drawable.play; //int playPauseString = isPlaying() ? R.string.pause : R.string.play; notificationBuilder.setContentIntent(pendingIntent); String notificationMessage = ""; if (currentPlayingItem == null) { notificationMessage = getResources().getString(R.string.noSong); } else { if (currentPlayingItem.getArtist() != null && !currentPlayingItem.getArtist().equals("")) notificationMessage = currentPlayingItem.getArtist() + " - "; notificationMessage += currentPlayingItem.getTitle(); } /*notificationBuilder.addAction(R.drawable.previous, getResources().getString(R.string.previous), previousPendingIntent); notificationBuilder.addAction(playPauseIcon, getResources().getString(playPauseString), playpausePendingIntent); notificationBuilder.addAction(R.drawable.next, getResources().getString(R.string.next), nextPendingIntent);*/ notificationBuilder.setContentTitle(getResources().getString(R.string.app_name)); notificationBuilder.setContentText(notificationMessage); notification = notificationBuilder.build(); RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.layout_notification); if (currentPlayingItem == null) { notificationLayout.setTextViewText(R.id.textViewArtist, getString(R.string.app_name)); notificationLayout.setTextViewText(R.id.textViewTitle, getString(R.string.noSong)); notificationLayout.setImageViewBitmap(R.id.imageViewNotification, BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)); } else { notificationLayout.setTextViewText(R.id.textViewArtist, currentPlayingItem.getArtist()); notificationLayout.setTextViewText(R.id.textViewTitle, currentPlayingItem.getTitle()); Bitmap image = currentPlayingItem.getImage(); if (image != null) { notificationLayout.setImageViewBitmap(R.id.imageViewNotification, image); } else { notificationLayout.setImageViewBitmap(R.id.imageViewNotification, BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)); } } notificationLayout.setOnClickPendingIntent(R.id.buttonNotificationQuit, quitPendingIntent); notificationLayout.setOnClickPendingIntent(R.id.buttonNotificationPrevious, previousPendingIntent); notificationLayout.setImageViewResource(R.id.buttonNotificationPlayPause, playPauseIcon); notificationLayout.setOnClickPendingIntent(R.id.buttonNotificationPlayPause, playpausePendingIntent); notificationLayout.setOnClickPendingIntent(R.id.buttonNotificationNext, nextPendingIntent); notification.bigContentView = notificationLayout; notificationManager.notify(Constants.NOTIFICATION_MAIN, notification); }
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:co.shunya.gita.player.MusicService.java
/** * Starts playing the next song. If manualUrl is null, the next song will be randomly selected * from our Media Retriever (that is, it will be a random song in the user's device). If * manualUrl is non-null, then it specifies the URL or path to the song that will be played * next.//from www . j a va 2s . c o m */ void playNextSong(Long id) { if (id == null || id < 0) { throw new IllegalArgumentException("id must be non nul +ve"); } setState(State.Stopped); relaxResources(false); // release everything except MediaPlayer try { // set the source of the media player to a manual URL or path Track playingItem = mRetriever.getItem(id); createMediaPlayerIfNeeded(); mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); if (playingItem == null) { Toast.makeText(this, "All Tracks of current category is been played", Toast.LENGTH_LONG).show(); processStopRequest(true); // stop everything! return; } // BusProvider.getInstance().post(playingItem); mCurrentID = id; mPlayer.setDataSource(playingItem.isDownloded() ? playingItem.getLocalUrl(this) : playingItem.getUrl()); mIsStreaming = playingItem.getUrl().startsWith("http:") || playingItem.getUrl().startsWith("https:"); mSongTitle = playingItem.getTitle(); setState(State.Preparing); updateUI(); setUpAsForeground(mSongTitle + " (loading)"); // Use the media button APIs (if available) to register ourselves for media button // events MediaButtonHelper.registerMediaButtonEventReceiverCompat(mAudioManager, mMediaButtonReceiverComponent); // Use the remote control APIs (if available) to set the playback state if (mRemoteControlClientCompat == null) { Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON); intent.setComponent(mMediaButtonReceiverComponent); mRemoteControlClientCompat = new RemoteControlClientCompat(PendingIntent.getBroadcast( this /*context*/, 0 /*requestCode, ignored*/, intent /*intent*/, 0 /*flags*/)); RemoteControlHelper.registerRemoteControlClient(mAudioManager, mRemoteControlClientCompat); } mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); mRemoteControlClientCompat.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_STOP); // Update the remote controls mRemoteControlClientCompat.editMetadata(true) .putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, "Gita") .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, playingItem.getTitle()) .putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, mDummyAlbumArt) .apply(); // starts preparing the media player in the background. When it's done, it will call // our OnPreparedListener (that is, the onPrepared() method on this class, since we set // the listener to 'this'). // // Until the media player is prepared, we *cannot* call start() on it! mPlayer.prepareAsync(); // If we are streaming from the internet, we want to hold a Wifi lock, which prevents // the Wifi radio from going to sleep while the song is playing. If, on the other hand, // we are *not* streaming, we want to release the lock if we were holding it before. if (mIsStreaming) mWifiLock.acquire(); else if (mWifiLock.isHeld()) mWifiLock.release(); } catch (IOException ex) { Log.e("MusicService", "IOException playing next song: " + ex.getMessage()); ex.printStackTrace(); } }