本文整理汇总了Java中android.support.v4.media.session.MediaControllerCompat.Callback方法的典型用法代码示例。如果您正苦于以下问题:Java MediaControllerCompat.Callback方法的具体用法?Java MediaControllerCompat.Callback怎么用?Java MediaControllerCompat.Callback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.media.session.MediaControllerCompat
的用法示例。
在下文中一共展示了MediaControllerCompat.Callback方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PlayerControl
import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
public PlayerControl(@NonNull MediaControllerCompat mediaControllerCompat, final MediaController mediaController) {
mMediaControllerCompat = mediaControllerCompat;
mCallback = new MediaControllerCompat.Callback() {
@Override
public void onPlaybackStateChanged(PlaybackStateCompat state) {
processPlaybackState(state, mediaController);
}
@Override
public void onMetadataChanged(MediaMetadataCompat metadata) {
mLastMediaMetadataCompat = metadata;
}
};
mMediaControllerCompat.registerCallback(mCallback);
mLastMediaMetadataCompat = mMediaControllerCompat.getMetadata();
processPlaybackState(mMediaControllerCompat.getPlaybackState(), mediaController);
}
示例2: onConnected
import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
void onConnected() {
try {
Context context = mFragmentActivity == null ? mLActivity : mFragmentActivity;
if (context == null)
return;
mMediaControls = new MediaControllerCompat(context, mMediaBrowser.getSessionToken());
mMediaCallback = new MediaControllerCompat.Callback() {
@Override
public void onPlaybackStateChanged(PlaybackStateCompat state) {
MediaInterface.this.onPlaybackStateChanged(state);
}
@Override
public void onSessionEvent(String event, Bundle extras) {
MediaInterface.this.onSessionEvent(event, extras);
}
@Override
public void onMetadataChanged(MediaMetadataCompat metadata) {
MediaInterface.this.onMetadataChanged(metadata);
}
};
mMediaControls.registerCallback(mMediaCallback);
if (mFragmentActivity != null) {
MediaControllerCompat.setMediaController(mFragmentActivity, mMediaControls);
//mFragmentActivity.setSupportMediaController(mMediaControls);
} else if (mLActivity != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
setMediaControllerL();
if (mPlayerControls != null)
mPlayerControls.setMediaControls(mCallbacks, mMediaControls);
if (mMediaControls.getPlaybackState() != null)
onPlaybackStateChanged(mMediaControls.getPlaybackState());
final Intent intent = mFragmentActivity == null ? mLActivity.getIntent() : mFragmentActivity.getIntent();
if (MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH.equals(intent.getAction())) {
final Bundle params = intent.getExtras();
final String query = params.getString(SearchManager.QUERY);
LOG.i("Starting from voice search query=" + query);
mMediaControls.getTransportControls()
.playFromSearch(query, params);
}
if (mCallbacks != null) {
mCallbacks.onConnected(this);
MediaMetadataCompat metadataCompat = mMediaControls.getMetadata();
if (metadataCompat != null) {
final long duration = metadataCompat.getLong(MediaMetadataCompat.METADATA_KEY_DURATION);
if (duration > 0)
mCallbacks.setTimeTotal(this, duration);
}
}
Bundle extras = mMediaControls.getExtras();
if (extras != null && extras.containsKey(MediaService.EXTRA_CONNECTED_CAST)) {
mCallbacks.onCasting(this, extras.getString(MediaService.EXTRA_CONNECTED_CAST));
}
if (mPlayerControls != null && mPlayerControls.isPlaying())
mHandler.start();
if (mSurface != null)
setSurface(mSurface);
LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent(ACTION_CONNECTED));
} catch (RemoteException err) {
LOG.e("Error in onConnected", err);
}
}