public abstract class

PlaybackGlueHost

extends java.lang.Object

 java.lang.Object

↳androidx.leanback.media.PlaybackGlueHost

Subclasses:

PlaybackSupportFragmentGlueHost, VideoFragmentGlueHost, PlaybackFragmentGlueHost, VideoSupportFragmentGlueHost

Gradle dependencies

compile group: 'androidx.leanback', name: 'leanback', version: '1.2.0-alpha02'

  • groupId: androidx.leanback
  • artifactId: leanback
  • version: 1.2.0-alpha02

Artifact androidx.leanback:leanback:1.2.0-alpha02 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.leanback:leanback com.android.support:leanback-v17

Androidx class mapping:

androidx.leanback.media.PlaybackGlueHost android.support.v17.leanback.media.PlaybackGlueHost

Overview

This class represents the UI (e.g. Fragment/Activity) hosting playback controls and defines the interaction between PlaybackGlue and the host. PlaybackGlueHost provides the following functions:

Subclass of PlaybackGlueHost may implement optional interfaces: These optional interfaces should be accessed by glue in PlaybackGlue.onAttachedToHost(PlaybackGlueHost).

Summary

Constructors
publicPlaybackGlueHost()

Methods
public voidfadeOut()

Fades out the playback overlay immediately.

public PlaybackGlueHost.PlayerCallbackgetPlayerCallback()

Implemented by PlaybackGlueHost for responding to player events.

public voidhideControlsOverlay(boolean runAnimation)

Hide controls overlay.

public booleanisControlsOverlayAutoHideEnabled()

Returns true if auto hides controls overlay.

public booleanisControlsOverlayVisible()

Returns true if controls overlay is visible, false otherwise.

public voidnotifyPlaybackRowChanged()

Notifies host about a change so it can update the view.

public voidsetControlsOverlayAutoHideEnabled(boolean enabled)

Enables or disables controls overlay auto hidden.

public voidsetFadingEnabled(boolean enable)

Enables or disables view fading.

public voidsetHostCallback(PlaybackGlueHost.HostCallback callback)

Sets the host PlaybackGlueHost.HostCallback callback on the host.

public voidsetOnActionClickedListener(OnActionClickedListener listener)

Sets the on this fragment.

public voidsetOnKeyInterceptListener(View.OnKeyListener onKeyListener)

Sets the on the host.

public voidsetPlaybackRow(Row row)

Sets the Row that represents the information on control items that needs to be rendered.

public voidsetPlaybackRowPresenter(PlaybackRowPresenter presenter)

Sets PlaybackRowPresenter for rendering the playback controls.

public voidshowControlsOverlay(boolean runAnimation)

Show controls overlay.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public PlaybackGlueHost()

Methods

public void setFadingEnabled(boolean enable)

Deprecated: Use PlaybackGlueHost.setControlsOverlayAutoHideEnabled(boolean)

Enables or disables view fading. If enabled, the view will be faded in when the fragment starts and will fade out after a time period.

public void setControlsOverlayAutoHideEnabled(boolean enabled)

Enables or disables controls overlay auto hidden. If enabled, the view will be faded out after a time period.

Parameters:

enabled: True to enable auto hidden of controls overlay.

public boolean isControlsOverlayAutoHideEnabled()

Returns true if auto hides controls overlay.

Returns:

True if auto hiding controls overlay.

public void fadeOut()

Deprecated: Call PlaybackGlueHost.hideControlsOverlay(boolean)

Fades out the playback overlay immediately.

public boolean isControlsOverlayVisible()

Returns true if controls overlay is visible, false otherwise.

Returns:

True if controls overlay is visible, false otherwise.

See also: PlaybackGlueHost.showControlsOverlay(boolean), PlaybackGlueHost.hideControlsOverlay(boolean)

public void hideControlsOverlay(boolean runAnimation)

Hide controls overlay.

Parameters:

runAnimation: True to run animation, false otherwise.

public void showControlsOverlay(boolean runAnimation)

Show controls overlay.

Parameters:

runAnimation: True to run animation, false otherwise.

public void setOnKeyInterceptListener(View.OnKeyListener onKeyListener)

Sets the on the host. This would trigger the listener when a is unhandled by the host.

public void setOnActionClickedListener(OnActionClickedListener listener)

Sets the on this fragment.

public void setHostCallback(PlaybackGlueHost.HostCallback callback)

Sets the host PlaybackGlueHost.HostCallback callback on the host. This method should only be called by PlaybackGlue. App should not directly call this method, app should override PlaybackGlue.onHostStart() etc.

public void notifyPlaybackRowChanged()

Notifies host about a change so it can update the view.

public void setPlaybackRowPresenter(PlaybackRowPresenter presenter)

Sets PlaybackRowPresenter for rendering the playback controls.

public void setPlaybackRow(Row row)

Sets the Row that represents the information on control items that needs to be rendered.

public PlaybackGlueHost.PlayerCallback getPlayerCallback()

Implemented by PlaybackGlueHost for responding to player events. Such as showing a spinning wheel progress bar when PlaybackGlueHost.PlayerCallback.onBufferingStateChanged(boolean).

Returns:

PlayerEventCallback that Host supports, null if not supported.

Source

/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.leanback.media;

import android.view.View;

import androidx.leanback.widget.OnActionClickedListener;
import androidx.leanback.widget.PlaybackRowPresenter;
import androidx.leanback.widget.PlaybackSeekUi;
import androidx.leanback.widget.Row;

/**
 * This class represents the UI (e.g. Fragment/Activity) hosting playback controls and
 * defines the interaction between {@link PlaybackGlue} and the host.
 * PlaybackGlueHost provides the following functions:
 * <ul>
 * <li>Render UI of PlaybackGlue: {@link #setPlaybackRow(Row)},
 * {@link #setPlaybackRowPresenter(PlaybackRowPresenter)}.
 * </li>
 * <li>Client for fragment/activity onStart/onStop: {@link #setHostCallback(HostCallback)}.
 * </li>
 * <li>Auto fade out controls after a short period: {@link #setFadingEnabled(boolean)}.
 * </li>
 * <li>Key listener and ActionListener. {@link #setOnKeyInterceptListener(View.OnKeyListener)},
 * {@link #setOnActionClickedListener(OnActionClickedListener)}.
 * </li>
 * </ul>
 *
 * Subclass of PlaybackGlueHost may implement optional interfaces:
 * <ul>
 * <li>{@link SurfaceHolderGlueHost} to provide SurfaceView for video playback.</li>
 * <li>{@link PlaybackSeekUi} to provide seek UI to glue</li>
 * </ul>
 * These optional interfaces should be accessed by glue in
 * {@link PlaybackGlue#onAttachedToHost(PlaybackGlueHost)}.
 */
public abstract class PlaybackGlueHost {
    PlaybackGlue mGlue;

    /**
     * Callbacks triggered by the host(e.g. fragment) hosting the video controls/surface.
     *
     * @see #setHostCallback(HostCallback)
     */
    public abstract static class HostCallback {
        /**
         * Client triggered once the host(fragment) has started.
         */
        public void onHostStart() {
        }

        /**
         * Client triggered once the host(fragment) has stopped.
         */
        public void onHostStop() {
        }

        /**
         * Client triggered once the host(fragment) has paused.
         */
        public void onHostPause() {
        }

        /**
         * Client triggered once the host(fragment) has resumed.
         */
        public void onHostResume() {
        }

        /**
         * Client triggered once the host(fragment) has been destroyed.
         */
        public void onHostDestroy() {
        }
    }

    /**
     * Optional Client that implemented by PlaybackGlueHost to respond to player event.
     */
    public static class PlayerCallback {
        /**
         * Size of the video changes, the Host should adjust SurfaceView's layout width and height.
         * @param videoWidth
         * @param videoHeight
         */
        public void onVideoSizeChanged(int videoWidth, int videoHeight) {
        }

        /**
         * notify media starts/stops buffering/preparing. The Host could start or stop
         * progress bar.
         * @param start True for buffering start, false otherwise.
         */
        public void onBufferingStateChanged(boolean start) {
        }

        /**
         * notify media has error. The Host could show error dialog.
         * @param errorCode Optional error code for specific implementation.
         * @param errorMessage Optional error message for specific implementation.
         */
        public void onError(int errorCode, CharSequence errorMessage) {
        }
    }

    /**
     * Enables or disables view fading.  If enabled, the view will be faded in when the
     * fragment starts and will fade out after a time period.
     * @deprecated Use {@link #setControlsOverlayAutoHideEnabled(boolean)}
     */
    @Deprecated
    public void setFadingEnabled(boolean enable) {
    }

    /**
     * Enables or disables controls overlay auto hidden.  If enabled, the view will be faded out
     * after a time period.
     * @param enabled True to enable auto hidden of controls overlay.
     *
     */
    public void setControlsOverlayAutoHideEnabled(boolean enabled) {
        setFadingEnabled(enabled);
    }

    /**
     * Returns true if auto hides controls overlay.
     * @return True if auto hiding controls overlay.
     */
    public boolean isControlsOverlayAutoHideEnabled() {
        return false;
    }

    /**
     * Fades out the playback overlay immediately.
     * @deprecated Call {@link #hideControlsOverlay(boolean)}
     */
    @Deprecated
    public void fadeOut() {
    }

    /**
     * Returns true if controls overlay is visible, false otherwise.
     *
     * @return True if controls overlay is visible, false otherwise.
     * @see #showControlsOverlay(boolean)
     * @see #hideControlsOverlay(boolean)
     */
    public boolean isControlsOverlayVisible() {
        return true;
    }

    /**
     * Hide controls overlay.
     *
     * @param runAnimation True to run animation, false otherwise.
     */
    public void hideControlsOverlay(boolean runAnimation) {
    }

    /**
     * Show controls overlay.
     *
     * @param runAnimation True to run animation, false otherwise.
     */
    public void showControlsOverlay(boolean runAnimation) {
    }

    /**
     * Sets the {@link android.view.View.OnKeyListener} on the host. This would trigger
     * the listener when a {@link android.view.KeyEvent} is unhandled by the host.
     */
    public void setOnKeyInterceptListener(View.OnKeyListener onKeyListener) {
    }

    /**
     * Sets the {@link View.OnClickListener} on this fragment.
     */
    public void setOnActionClickedListener(OnActionClickedListener listener) {}

    /**
     * Sets the host {@link HostCallback} callback on the host. This method should only be called
     * by {@link PlaybackGlue}. App should not directly call this method, app should override
     * {@link PlaybackGlue#onHostStart()} etc.
     */
    public void setHostCallback(HostCallback callback) {
    }

    /**
     * Notifies host about a change so it can update the view.
     */
    public void notifyPlaybackRowChanged() {}

    /**
     * Sets {@link PlaybackRowPresenter} for rendering the playback controls.
     */
    public void setPlaybackRowPresenter(PlaybackRowPresenter presenter) {}

    /**
     * Sets the {@link Row} that represents the information on control items that needs
     * to be rendered.
     */
    public void setPlaybackRow(Row row) {}

    final void attachToGlue(PlaybackGlue glue) {
        if (mGlue != null) {
            mGlue.onDetachedFromHost();
        }
        mGlue = glue;
        if (mGlue != null) {
            mGlue.onAttachedToHost(this);
        }
    }

    /**
     * Implemented by PlaybackGlueHost for responding to player events. Such as showing a spinning
     * wheel progress bar when {@link PlayerCallback#onBufferingStateChanged(boolean)}.
     * @return PlayerEventCallback that Host supports, null if not supported.
     */
    public PlayerCallback getPlayerCallback() {
        return null;
    }

}