use of android.support.v4.media.MediaMetadataCompat in project Shuttle by timusus.
the class VideoCastManager method updateMediaSessionMetadata.
/*
* On ICS and JB, lock screen metadata is one liner: Title - Album Artist - Album. On KitKat, it
* has two lines: Title , Album Artist - Album
*/
private void updateMediaSessionMetadata() {
if ((mMediaSessionCompat == null) || !isFeatureEnabled(CastConfiguration.FEATURE_LOCKSCREEN)) {
return;
}
try {
MediaInfo info = getRemoteMediaInformation();
if (info == null) {
return;
}
final MediaMetadata mm = info.getMetadata();
MediaMetadataCompat currentMetadata = mMediaSessionCompat.getController().getMetadata();
MediaMetadataCompat.Builder newBuilder = currentMetadata == null ? new MediaMetadataCompat.Builder() : new MediaMetadataCompat.Builder(currentMetadata);
MediaMetadataCompat metadata = newBuilder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, mm.getString(MediaMetadata.KEY_TITLE)).putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, mContext.getResources().getString(R.string.ccl_casting_to_device, getDeviceName())).putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, mm.getString(MediaMetadata.KEY_TITLE)).putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, mm.getString(MediaMetadata.KEY_SUBTITLE)).putLong(MediaMetadataCompat.METADATA_KEY_DURATION, info.getStreamDuration()).build();
mMediaSessionCompat.setMetadata(metadata);
Uri iconUri = mm.hasImages() ? mm.getImages().get(0).getUrl() : null;
if (iconUri == null) {
Bitmap bm = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.album_art_placeholder);
mMediaSessionCompat.setMetadata(newBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, bm).build());
} else {
if (mMediaSessionIconFetchTask != null) {
mMediaSessionIconFetchTask.cancel(true);
}
mMediaSessionIconFetchTask = new FetchBitmapTask() {
@Override
protected void onPostExecute(Bitmap bitmap) {
if (bitmap != null && mMediaSessionCompat != null) {
MediaMetadataCompat currentMetadata = mMediaSessionCompat.getController().getMetadata();
MediaMetadataCompat.Builder newBuilder = currentMetadata == null ? new MediaMetadataCompat.Builder() : new MediaMetadataCompat.Builder(currentMetadata);
mMediaSessionCompat.setMetadata(newBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, bitmap).build());
}
mMediaSessionIconFetchTask = null;
}
};
mMediaSessionIconFetchTask.execute(iconUri);
}
} catch (NotFoundException e) {
LOGE(TAG, "Failed to update Media Session due to resource not found", e);
} catch (TransientNetworkDisconnectionException | NoConnectionException e) {
LOGE(TAG, "Failed to update Media Session due to network issues", e);
}
}
use of android.support.v4.media.MediaMetadataCompat in project android-UniversalMusicPlayer by googlesamples.
the class PlaybackControlsFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_playback_controls, container, false);
mPlayPause = (ImageButton) rootView.findViewById(R.id.play_pause);
mPlayPause.setEnabled(true);
mPlayPause.setOnClickListener(mButtonListener);
mTitle = (TextView) rootView.findViewById(R.id.title);
mSubtitle = (TextView) rootView.findViewById(R.id.artist);
mExtraInfo = (TextView) rootView.findViewById(R.id.extra_info);
mAlbumArt = (ImageView) rootView.findViewById(R.id.album_art);
rootView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), FullScreenPlayerActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
MediaControllerCompat controller = ((FragmentActivity) getActivity()).getSupportMediaController();
MediaMetadataCompat metadata = controller.getMetadata();
if (metadata != null) {
intent.putExtra(MusicPlayerActivity.EXTRA_CURRENT_MEDIA_DESCRIPTION, metadata.getDescription());
}
startActivity(intent);
}
});
return rootView;
}
use of android.support.v4.media.MediaMetadataCompat in project android-UniversalMusicPlayer by googlesamples.
the class MusicProvider method updateMusicArt.
public synchronized void updateMusicArt(String musicId, Bitmap albumArt, Bitmap icon) {
MediaMetadataCompat metadata = getMusic(musicId);
metadata = new MediaMetadataCompat.Builder(metadata).putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, albumArt).putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, icon).build();
MutableMediaMetadata mutableMetadata = mMusicListById.get(musicId);
if (mutableMetadata == null) {
throw new IllegalStateException("Unexpected error: Inconsistent data structures in " + "MusicProvider");
}
mutableMetadata.metadata = metadata;
}
use of android.support.v4.media.MediaMetadataCompat in project android-UniversalMusicPlayer by googlesamples.
the class MusicProvider method retrieveMedia.
private synchronized void retrieveMedia() {
try {
if (mCurrentState == State.NON_INITIALIZED) {
mCurrentState = State.INITIALIZING;
Iterator<MediaMetadataCompat> tracks = mSource.iterator();
while (tracks.hasNext()) {
MediaMetadataCompat item = tracks.next();
String musicId = item.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID);
mMusicListById.put(musicId, new MutableMediaMetadata(musicId, item));
}
buildListsByGenre();
mCurrentState = State.INITIALIZED;
}
} finally {
if (mCurrentState != State.INITIALIZED) {
// Something bad happened, so we reset state to NON_INITIALIZED to allow
// retries (eg if the network connection is temporary unavailable)
mCurrentState = State.NON_INITIALIZED;
}
}
}
use of android.support.v4.media.MediaMetadataCompat in project android-UniversalMusicPlayer by googlesamples.
the class MusicProvider method createMediaItem.
private MediaBrowserCompat.MediaItem createMediaItem(MediaMetadataCompat metadata) {
// Since mediaMetadata fields are immutable, we need to create a copy, so we
// can set a hierarchy-aware mediaID. We will need to know the media hierarchy
// when we get a onPlayFromMusicID call, so we can create the proper queue based
// on where the music was selected from (by artist, by genre, random, etc)
String genre = metadata.getString(MediaMetadataCompat.METADATA_KEY_GENRE);
String hierarchyAwareMediaID = MediaIDHelper.createMediaID(metadata.getDescription().getMediaId(), MEDIA_ID_MUSICS_BY_GENRE, genre);
MediaMetadataCompat copy = new MediaMetadataCompat.Builder(metadata).putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, hierarchyAwareMediaID).build();
return new MediaBrowserCompat.MediaItem(copy.getDescription(), MediaBrowserCompat.MediaItem.FLAG_PLAYABLE);
}
Aggregations