当前位置: 首页>>代码示例>>Java>>正文


Java MediaControllerCompat.Callback方法代码示例

本文整理汇总了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);
}
 
开发者ID:StraaS,项目名称:StraaS-android-sdk-sample,代码行数:18,代码来源:PlayerControl.java

示例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);
    }
}
 
开发者ID:lifechurch,项目名称:nuclei-android,代码行数:71,代码来源:MediaInterface.java


注:本文中的android.support.v4.media.session.MediaControllerCompat.Callback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。