public abstract class

RemoteSessionPlayer

extends SessionPlayer

 java.lang.Object

androidx.media2.SessionPlayer

↳androidx.media2.RemoteSessionPlayer

Subclasses:

RoutePlayer

Gradle dependencies

compile group: 'androidx.media2', name: 'media2', version: '1.0.0-alpha04'

  • groupId: androidx.media2
  • artifactId: media2
  • version: 1.0.0-alpha04

Artifact androidx.media2:media2:1.0.0-alpha04 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.media2:media2 com.android.support:media2

Overview

Base interface for all remote media players that want media session and playback happens on the remote device through MediaRouter.

If you use this to the MediaSession, session would dispatch incoming volume change event to the player instead of changing device stream volume.

Summary

Fields
public static final intVOLUME_CONTROL_ABSOLUTE

The volume control uses an absolute value.

public static final intVOLUME_CONTROL_FIXED

The volume is fixed and can not be modified.

public static final intVOLUME_CONTROL_RELATIVE

The volume control uses relative adjustment via RemoteSessionPlayer.adjustVolume(int).

from SessionPlayerBUFFERING_STATE_BUFFERING_AND_PLAYABLE, BUFFERING_STATE_BUFFERING_AND_STARVED, BUFFERING_STATE_COMPLETE, BUFFERING_STATE_UNKNOWN, PLAYER_STATE_ERROR, PLAYER_STATE_IDLE, PLAYER_STATE_PAUSED, PLAYER_STATE_PLAYING, REPEAT_MODE_ALL, REPEAT_MODE_GROUP, REPEAT_MODE_NONE, REPEAT_MODE_ONE, SHUFFLE_MODE_ALL, SHUFFLE_MODE_GROUP, SHUFFLE_MODE_NONE, UNKNOWN_TIME
Constructors
publicRemoteSessionPlayer()

Methods
public abstract java.util.concurrent.Future<SessionPlayer.PlayerResult>adjustVolume(int direction)

Adjust player volume with the direction.

public abstract intgetMaxVolume()

Gets the maximum volume that can be used in RemoteSessionPlayer.setVolume(int).

public abstract intgetVolume()

Gets the current volume of this player to this player.

public abstract intgetVolumeControlType()

Gets the volume type.

public abstract java.util.concurrent.Future<SessionPlayer.PlayerResult>setVolume(int volume)

Sets the volume of the audio of the media to play, expressed as a linear multiplier on the audio samples.

from SessionPlayeraddPlaylistItem, getAudioAttributes, getBufferedPosition, getBufferingState, getCallbacks, getCurrentMediaItem, getCurrentMediaItemIndex, getCurrentPosition, getDuration, getNextMediaItemIndex, getPlaybackSpeed, getPlayerState, getPlaylist, getPlaylistMetadata, getPreviousMediaItemIndex, getRepeatMode, getShuffleMode, pause, play, prepare, registerPlayerCallback, removePlaylistItem, replacePlaylistItem, seekTo, setAudioAttributes, setMediaItem, setPlaybackSpeed, setPlaylist, setRepeatMode, setShuffleMode, skipToNextPlaylistItem, skipToPlaylistItem, skipToPreviousPlaylistItem, unregisterPlayerCallback, updatePlaylistMetadata
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Fields

public static final int VOLUME_CONTROL_FIXED

The volume is fixed and can not be modified. Requests to change volume should be ignored.

public static final int VOLUME_CONTROL_RELATIVE

The volume control uses relative adjustment via RemoteSessionPlayer.adjustVolume(int). Attempts to set the volume to a specific value should be ignored.

public static final int VOLUME_CONTROL_ABSOLUTE

The volume control uses an absolute value. It may be adjusted using RemoteSessionPlayer.adjustVolume(int) or set directly using RemoteSessionPlayer.setVolume(int).

Constructors

public RemoteSessionPlayer()

Methods

public abstract java.util.concurrent.Future<SessionPlayer.PlayerResult> adjustVolume(int direction)

Adjust player volume with the direction. Override this API to customize volume change in remote device

Default implement adjust volume by 1

This would be ignored when volume control type is RemoteSessionPlayer.VOLUME_CONTROL_FIXED.

Parameters:

direction: direction of the volume changes. Positive value for volume up, negative for volume down.

public abstract java.util.concurrent.Future<SessionPlayer.PlayerResult> setVolume(int volume)

Sets the volume of the audio of the media to play, expressed as a linear multiplier on the audio samples.

Note that this volume is specific to the player, and is separate from stream volume used across the platform.

A value of 0 indicates muting. See RemoteSessionPlayer.getMaxVolume() for the volume range supported by this player.

Parameters:

volume: a value between 0.0f and RemoteSessionPlayer.getMaxVolume().

public abstract int getVolume()

Gets the current volume of this player to this player.

Note that it does not take into account the associated stream volume because the playback is happening outside of the phone device.

Returns:

the player volume.

public abstract int getMaxVolume()

Gets the maximum volume that can be used in RemoteSessionPlayer.setVolume(int).

Returns:

the maximum volume. Shouldn't be negative.

public abstract int getVolumeControlType()

Gets the volume type.

This shouldn't be changed after instantiation.

Returns:

one of the volume type

See also: RemoteSessionPlayer.VOLUME_CONTROL_FIXED, RemoteSessionPlayer.VOLUME_CONTROL_RELATIVE, RemoteSessionPlayer.VOLUME_CONTROL_ABSOLUTE

Source

/*
 * Copyright 2018 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.media2;

import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;

import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.concurrent.Future;

/**
 * Base interface for all remote media players that want media session and playback happens on the
 * remote device through MediaRouter.
 * <p>
 * If you use this to the {@link MediaSession}, session would dispatch incoming volume change event
 * to the player instead of changing device stream volume.
 *
 * @hide
 */
@RestrictTo(LIBRARY_GROUP)
public abstract class RemoteSessionPlayer extends SessionPlayer {
    /**
     * @hide
     */
    @RestrictTo(LIBRARY_GROUP)
    @IntDef({VOLUME_CONTROL_FIXED, VOLUME_CONTROL_RELATIVE, VOLUME_CONTROL_ABSOLUTE})
    @Retention(RetentionPolicy.SOURCE)
    public @interface VolumeControlType {}

    /**
     * The volume is fixed and can not be modified. Requests to change volume
     * should be ignored.
     */
    public static final int VOLUME_CONTROL_FIXED = 0;

    /**
     * The volume control uses relative adjustment via
     * {@link #adjustVolume(int)}. Attempts to set the volume to a specific
     * value should be ignored.
     */
    public static final int VOLUME_CONTROL_RELATIVE = 1;

    /**
     * The volume control uses an absolute value. It may be adjusted using
     * {@link #adjustVolume(int)} or set directly using
     * {@link #setVolume(int)}.
     */
    public static final int VOLUME_CONTROL_ABSOLUTE = 2;

    /**
     * Adjust player volume with the direction. Override this API to customize volume change in
     * remote device
     * <p>
     * Default implement adjust volume by 1
     * <p>
     * This would be ignored when volume control type is {@link #VOLUME_CONTROL_FIXED}.
     *
     * @param direction direction of the volume changes. Positive value for volume up, negative for
     *                  volume down.
     */
    public abstract Future<PlayerResult> adjustVolume(int direction);

    /**
     * Sets the volume of the audio of the media to play, expressed as a linear multiplier
     * on the audio samples.
     * <p>
     * Note that this volume is specific to the player, and is separate from stream volume
     * used across the platform.
     * <p>
     * A value of {@code 0} indicates muting. See {@link #getMaxVolume()} for the volume range
     * supported by this player.
     *
     * @param volume a value between 0.0f and {@link #getMaxVolume()}.
     */
    public abstract Future<PlayerResult> setVolume(int volume);

    /**
     * Gets the current volume of this player to this player.
     * <p>
     * Note that it does not take into account the associated stream volume because the playback is
     * happening outside of the phone device.
     *
     * @return the player volume.
     */
    public abstract int getVolume();

    /**
     * Gets the maximum volume that can be used in {@link #setVolume(int)}.
     *
     * @return the maximum volume. Shouldn't be negative.
     */
    public abstract int getMaxVolume();

    /**
     * Gets the volume type.
     * <p>
     * This shouldn't be changed after instantiation.
     *
     * @return one of the volume type
     * @see #VOLUME_CONTROL_FIXED
     * @see #VOLUME_CONTROL_RELATIVE
     * @see #VOLUME_CONTROL_ABSOLUTE
     */
    public abstract @VolumeControlType int getVolumeControlType();

    /**
     * @hide
     */
    @RestrictTo(LIBRARY_GROUP)
    public static class Callback extends SessionPlayer.PlayerCallback {
        /**
         * Called to indicate that the volume has changed.
         *
         * @param player2 the player that has completed volume changes.
         * @param volume the new volume
         * @see #setVolume(int)
         */
        public void onVolumeChanged(@NonNull RemoteSessionPlayer player2, int volume) {
        }
    }
}