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


Java MediaControllerCompat.setMediaController方法代码示例

本文整理汇总了Java中android.support.v4.media.session.MediaControllerCompat.setMediaController方法的典型用法代码示例。如果您正苦于以下问题:Java MediaControllerCompat.setMediaController方法的具体用法?Java MediaControllerCompat.setMediaController怎么用?Java MediaControllerCompat.setMediaController使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v4.media.session.MediaControllerCompat的用法示例。


在下文中一共展示了MediaControllerCompat.setMediaController方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initializeMediaSession

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
private void initializeMediaSession() {
    mSession = new MediaSessionCompat(this, TAG);
    mSession.setFlags(
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
                    | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mSession.setActive(true);
    MediaControllerCompat.setMediaController(this, mSession.getController());

    MediaMetadataCompat metadata = new MediaMetadataCompat.Builder()
            .putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, mMovieView.getTitle())
            .build();
    mSession.setMetadata(metadata);

    MediaSessionCallback mMediaSessionCallback = new MediaSessionCallback(mMovieView);
    mSession.setCallback(mMediaSessionCallback);

    int state =
            mMovieView.isPlaying()
                    ? PlaybackStateCompat.STATE_PLAYING
                    : PlaybackStateCompat.STATE_PAUSED;
    updatePlaybackState(
            state,
            MEDIA_ACTIONS_ALL,
            mMovieView.getCurrentPosition(),
            mMovieView.getVideoResourceId());
}
 
开发者ID:googlesamples,项目名称:android-PictureInPicture,代码行数:27,代码来源:MediaSessionPlaybackActivity.java

示例2: onConnected

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
@Override
public void onConnected() {
    mMediaBrowser.subscribe(mMediaBrowser.getRoot(), mSubscriptionCallback);
    try {
        MediaControllerCompat mediaController =
                new MediaControllerCompat(
                        MusicPlayerActivity.this, mMediaBrowser.getSessionToken());
        updatePlaybackState(mediaController.getPlaybackState());
        updateMetadata(mediaController.getMetadata());
        mediaController.registerCallback(mMediaControllerCallback);
        MediaControllerCompat.setMediaController(
                MusicPlayerActivity.this, mediaController);
    } catch (RemoteException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:googlecodelabs,项目名称:musicplayer-devices,代码行数:17,代码来源:MusicPlayerActivity.java

示例3: connectToSession

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
private void connectToSession(MediaSessionCompat.Token token) throws RemoteException
{
    LogHelper.e(TAG, "connectToSession");
    MediaControllerCompat mediaController = new MediaControllerCompat(this, token);
    MediaControllerCompat.setMediaController(this, mediaController);

    mediaController.registerCallback(mMediaControllerCallback);

    if (shouldShowControls()) {
        showPlaybackControls();
    } else {
        LogHelper.e(TAG, "connectionCallback.onConnected: hiding controls because metadata is null");
        hidePlaybackControls();
    }

    if (mControlsFragment != null) {
        mControlsFragment.onConnected();
    }

    onMediaControllerConnected();
}
 
开发者ID:teocci,项目名称:YouTube-In-Background,代码行数:22,代码来源:MainActivity.java

示例4: onMediaBrowserConnected

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
@Override
public void onMediaBrowserConnected(StraasMediaCore client) {
    mIsBind = true;
    if (mFragmentActivity == null) {
        Log.e(TAG, "It's not FragmentActivity.");
        return;
    }
    MediaControllerCompat.setMediaController(mFragmentActivity, client.getMediaController());
    for (ConnectionCallback connectionCallback : mMediaConnectedListenerList) {
        connectionCallback.onConnected();
    }

    mMediaControllerCallback.onExtrasChanged(getMediaControllerCompat().getExtras());
    mMediaControllerCallback.onMetadataChanged(getMediaControllerCompat().getMetadata());
    mMediaControllerCallback.onPlaybackStateChanged(getMediaControllerCompat().getPlaybackState());
    mMediaControllerCallback.onQueueChanged(getMediaControllerCompat().getQueue());
    mMediaControllerCallback.onQueueTitleChanged(getMediaControllerCompat().getQueueTitle());

    getMediaControllerCompat().registerCallback(mMediaControllerCallback);

    if (mContentSeekBar != null) {
        mContentSeekBar.setMediaPlayer(new PlayerControl(mFragmentActivity, null));
    }
}
 
开发者ID:StraaS,项目名称:StraaS-android-sdk-sample,代码行数:25,代码来源:StraasPlayerView.java

示例5: onConnected

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
@Override
public void onConnected() {
    LogHelper.d(TAG, "onConnected");
    try {
        MediaControllerCompat mediaController = new MediaControllerCompat(
                TvPlaybackActivity.this, mMediaBrowser.getSessionToken());
        MediaControllerCompat.setMediaController(TvPlaybackActivity.this, mediaController);
        mediaController.registerCallback(mMediaControllerCallback);

        MediaMetadataCompat metadata = mediaController.getMetadata();
        if (metadata != null) {
            mPlaybackFragment.updateMetadata(metadata);
            mPlaybackFragment.updatePlaybackState(mediaController.getPlaybackState());
        }
    } catch (RemoteException e) {
        LogHelper.e(TAG, e, "could not connect media controller");
    }
}
 
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:19,代码来源:TvPlaybackActivity.java

示例6: connectToSession

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
private void connectToSession(MediaSessionCompat.Token token) throws RemoteException {
    MediaControllerCompat mediaController = new MediaControllerCompat(this, token);
    MediaControllerCompat.setMediaController(this, mediaController);
    mediaController.registerCallback(mMediaControllerCallback);

    if (shouldShowControls()) {
        showPlaybackControls();
    } else {
        LogHelper.d(TAG, "connectionCallback.onConnected: " +
            "hiding controls because metadata is null");
        hidePlaybackControls();
    }

    if (mControlsFragment != null) {
        mControlsFragment.onConnected();
    }

    onMediaControllerConnected();
}
 
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:20,代码来源:BaseActivity.java

示例7: connectToSession

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
private void connectToSession(MediaSessionCompat.Token token) throws RemoteException {
    MediaControllerCompat mediaController = new MediaControllerCompat(
            FullScreenPlayerActivity.this, token);
    if (mediaController.getMetadata() == null) {
        finish();
        return;
    }
    MediaControllerCompat.setMediaController(FullScreenPlayerActivity.this, mediaController);
    mediaController.registerCallback(mCallback);
    PlaybackStateCompat state = mediaController.getPlaybackState();
    updatePlaybackState(state);
    MediaMetadataCompat metadata = mediaController.getMetadata();
    if (metadata != null) {
        updateMediaDescription(metadata.getDescription());
        updateDuration(metadata);
    }
    updateProgress();
    if (state != null && (state.getState() == PlaybackStateCompat.STATE_PLAYING ||
            state.getState() == PlaybackStateCompat.STATE_BUFFERING)) {
        scheduleSeekbarUpdate();
    }
}
 
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:23,代码来源:FullScreenPlayerActivity.java

示例8: onConnected

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
@Override
public void onConnected() {
    Timber.d("Connected to media service");
    try {
        // Get the token for the MediaSession
        MediaSessionCompat.Token token = mediaBrowser.getSessionToken();

        // Create a MediaControllerCompat
        MediaControllerCompat mediaController =
                new MediaControllerCompat(
                        PlayaItemViewActivity.this,
                        token);

        // Save the controller
        MediaControllerCompat.setMediaController(PlayaItemViewActivity.this, mediaController);

        // Finish building the UI
        setupMediaTransportControls();

    } catch (RemoteException e) {
        e.printStackTrace();
    }
}
 
开发者ID:Burning-Man-Earth,项目名称:iBurn-Android,代码行数:24,代码来源:PlayaItemViewActivity.java

示例9: connectToSession

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
private void connectToSession(MediaSessionCompat.Token token) throws RemoteException {
    MediaControllerCompat controller = new MediaControllerCompat(this, token);
    MediaControllerCompat.setMediaController(this, controller);
    controller.registerCallback(mMediaControllerCallback);

    //// TODO: 2017/9/14 do this in sub class
    getFragment().onConnected();
}
 
开发者ID:Jaysaw,项目名称:NovaMusicPlayer,代码行数:9,代码来源:MainActivity.java

示例10: onConnected

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
@Override
public void onConnected()  {
    super.onConnected();
    MediaSessionCompat.Token token=browserCompat.getSessionToken();
    try {
        MediaControllerCompat mediaController =new MediaControllerCompat(getActivity(), token);
        // Save the controller
        mediaController.registerCallback(controllerCallback);
        MediaControllerCompat.setMediaController(getActivity(), mediaController);
        //inject the passed query
        inject();
    }catch (RemoteException ex){
        ex.printStackTrace();
    }
}
 
开发者ID:vpaliyX,项目名称:Melophile,代码行数:16,代码来源:TrackFragment.java

示例11: onCreate

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    int movieId = getActivity().getIntent().getIntExtra(EXTRA_MOVIE_ID, -1);
    if (movieId == -1) {
        Log.w(TAG, "Invalid movieId, cannot playback.");
        throw new IllegalArgumentException("Invalid movieId " + movieId);
    }

    mPlaylistAdapter =
            MockPlaylistAdapterFactory.createMoviePlaylistAdapterWithActiveMovieId(movieId);

    mSession = new MediaSessionCompat(getContext(), TAG);
    mSession.setFlags(
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
                    | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mSession.setActive(true);
    MediaControllerCompat.setMediaController((Activity) getContext(), mSession.getController());

    mPlayerGlue =
            new PrimaryPlaybackControlsGlue<>(
                    getContext(),
                    new MediaPlayerAdapter(getContext()),
                    mSession.getController());
    mPlayerGlue.setHost(new VideoFragmentGlueHost(this));
    mPlayerGlue.addPlayerCallback(playWhenReadyPlayerCallback);
    mPlayerGlue.addPlayerCallback(playPausePlayerCallback);

    mMediaSessionCallback = new MediaSessionCallback(mPlayerGlue);
    mSession.setCallback(mMediaSessionCallback);

    playMedia(mPlaylistAdapter.getCurrentItem());
}
 
开发者ID:googlesamples,项目名称:leanback-assistant,代码行数:35,代码来源:PlaybackFragment.java

示例12: unsetMediaController

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
private void unsetMediaController() {
    MediaControllerCompat mediaController = MediaControllerCompat.getMediaController(this);
    if (mediaController != null) {
        mediaController.unregisterCallback(controllerCallback);
        MediaControllerCompat.setMediaController(this, null);
    }
}
 
开发者ID:kalikov,项目名称:lighthouse,代码行数:8,代码来源:LighthouseActivity.java

示例13: onConnected

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
@Override
public void onConnected() {
    LogHelper.d(TAG, "onConnected: session token ",
            mMediaBrowser.getSessionToken());

    try {
        MediaControllerCompat mediaController = new MediaControllerCompat(
                TvVerticalGridActivity.this, mMediaBrowser.getSessionToken());
        MediaControllerCompat.setMediaController(TvVerticalGridActivity.this, mediaController);
        browse();
    } catch (RemoteException e) {
        LogHelper.e(TAG, e, "could not connect media controller");
    }
}
 
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:15,代码来源:TvVerticalGridActivity.java

示例14: onConnected

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
@Override
public void onConnected() {
    LogHelper.d(TAG, "onConnected: session token ",
            mMediaBrowser.getSessionToken());
    try {
        MediaControllerCompat mediaController = new MediaControllerCompat(
                TvBrowseActivity.this, mMediaBrowser.getSessionToken());
        MediaControllerCompat.setMediaController(TvBrowseActivity.this, mediaController);
        navigateToBrowser(mMediaId);
    } catch (RemoteException e) {
        LogHelper.e(TAG, e, "could not connect media controller");
    }
}
 
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:14,代码来源:TvBrowseActivity.java

示例15: onConnectionSuspended

import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
@Override
public void onConnectionSuspended() {
    LogHelper.d(TAG, "onConnectionSuspended");
    MediaControllerCompat controllerCompat = MediaControllerCompat.getMediaController(TvPlaybackActivity.this);
    controllerCompat.unregisterCallback(mMediaControllerCallback);
    MediaControllerCompat.setMediaController(TvPlaybackActivity.this, null);
}
 
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:8,代码来源:TvPlaybackActivity.java


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