use of android.support.v4.media.MediaBrowserCompat in project android-UniversalMusicPlayer by googlesamples.
the class MediaBrowserFragment method updateTitle.
private void updateTitle() {
if (MediaIDHelper.MEDIA_ID_ROOT.equals(mMediaId)) {
mMediaFragmentListener.setToolbarTitle(null);
return;
}
MediaBrowserCompat mediaBrowser = mMediaFragmentListener.getMediaBrowser();
mediaBrowser.getItem(mMediaId, new MediaBrowserCompat.ItemCallback() {
@Override
public void onItemLoaded(MediaBrowserCompat.MediaItem item) {
mMediaFragmentListener.setToolbarTitle(item.getDescription().getTitle());
}
});
}
use of android.support.v4.media.MediaBrowserCompat in project android-UniversalMusicPlayer by googlesamples.
the class TvPlaybackActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LogHelper.d(TAG, "Activity onCreate");
mMediaBrowser = new MediaBrowserCompat(this, new ComponentName(this, MusicService.class), mConnectionCallback, null);
setContentView(R.layout.tv_playback_controls);
mPlaybackFragment = (TvPlaybackFragment) getSupportFragmentManager().findFragmentById(R.id.playback_controls_fragment);
}
use of android.support.v4.media.MediaBrowserCompat in project android-UniversalMusicPlayer by googlesamples.
the class FullScreenPlayerActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_full_player);
initializeToolbar();
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("");
}
mBackgroundImage = (ImageView) findViewById(R.id.background_image);
mPauseDrawable = ContextCompat.getDrawable(this, R.drawable.uamp_ic_pause_white_48dp);
mPlayDrawable = ContextCompat.getDrawable(this, R.drawable.uamp_ic_play_arrow_white_48dp);
mPlayPause = (ImageView) findViewById(R.id.play_pause);
mSkipNext = (ImageView) findViewById(R.id.next);
mSkipPrev = (ImageView) findViewById(R.id.prev);
mStart = (TextView) findViewById(R.id.startText);
mEnd = (TextView) findViewById(R.id.endText);
mSeekbar = (SeekBar) findViewById(R.id.seekBar1);
mLine1 = (TextView) findViewById(R.id.line1);
mLine2 = (TextView) findViewById(R.id.line2);
mLine3 = (TextView) findViewById(R.id.line3);
mLoading = (ProgressBar) findViewById(R.id.progressBar1);
mControllers = findViewById(R.id.controllers);
mSkipNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MediaControllerCompat.TransportControls controls = MediaControllerCompat.getMediaController(FullScreenPlayerActivity.this).getTransportControls();
controls.skipToNext();
}
});
mSkipPrev.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MediaControllerCompat.TransportControls controls = MediaControllerCompat.getMediaController(FullScreenPlayerActivity.this).getTransportControls();
controls.skipToPrevious();
}
});
mPlayPause.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PlaybackStateCompat state = MediaControllerCompat.getMediaController(FullScreenPlayerActivity.this).getPlaybackState();
if (state != null) {
MediaControllerCompat.TransportControls controls = MediaControllerCompat.getMediaController(FullScreenPlayerActivity.this).getTransportControls();
switch(state.getState()) {
// fall through
case PlaybackStateCompat.STATE_PLAYING:
case PlaybackStateCompat.STATE_BUFFERING:
controls.pause();
stopSeekbarUpdate();
break;
case PlaybackStateCompat.STATE_PAUSED:
case PlaybackStateCompat.STATE_STOPPED:
controls.play();
scheduleSeekbarUpdate();
break;
default:
LogHelper.d(TAG, "onClick with state ", state.getState());
}
}
}
});
mSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
mStart.setText(DateUtils.formatElapsedTime(progress / 1000));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
stopSeekbarUpdate();
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
MediaControllerCompat.getMediaController(FullScreenPlayerActivity.this).getTransportControls().seekTo(seekBar.getProgress());
scheduleSeekbarUpdate();
}
});
// Only update from the intent if we are not recreating from a config change:
if (savedInstanceState == null) {
updateFromParams(getIntent());
}
mMediaBrowser = new MediaBrowserCompat(this, new ComponentName(this, MusicService.class), mConnectionCallback, null);
}
use of android.support.v4.media.MediaBrowserCompat in project android-UniversalMusicPlayer by googlesamples.
the class MediaBrowserFragment method onStop.
@Override
public void onStop() {
super.onStop();
MediaBrowserCompat mediaBrowser = mMediaFragmentListener.getMediaBrowser();
if (mediaBrowser != null && mediaBrowser.isConnected() && mMediaId != null) {
mediaBrowser.unsubscribe(mMediaId);
}
MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());
if (controller != null) {
controller.unregisterCallback(mMediaControllerCallback);
}
this.getActivity().unregisterReceiver(mConnectivityChangeReceiver);
}
use of android.support.v4.media.MediaBrowserCompat in project android-UniversalMusicPlayer by googlesamples.
the class BaseActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LogHelper.d(TAG, "Activity onCreate");
if (Build.VERSION.SDK_INT >= 21) {
// Since our app icon has the same color as colorPrimary, our entry in the Recent Apps
// list gets weird. We need to change either the icon or the color
// of the TaskDescription.
ActivityManager.TaskDescription taskDesc = new ActivityManager.TaskDescription(getTitle().toString(), BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_white), ResourceHelper.getThemeColor(this, R.attr.colorPrimary, android.R.color.darker_gray));
setTaskDescription(taskDesc);
}
// Connect a media browser just to get the media session token. There are other ways
// this can be done, for example by sharing the session token directly.
mMediaBrowser = new MediaBrowserCompat(this, new ComponentName(this, MusicService.class), mConnectionCallback, null);
}
Aggregations