Add DeviceComponent to Player interface
PiperOrigin-RevId: 303655497
This commit is contained in:
parent
ca799716b8
commit
fd03949f85
@ -276,6 +276,13 @@ public final class CastPlayer extends BasePlayer {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public DeviceComponent getDeviceComponent() {
|
||||||
|
// TODO(b/151792305): Implement the component.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Looper getApplicationLooper() {
|
public Looper getApplicationLooper() {
|
||||||
return Looper.getMainLooper();
|
return Looper.getMainLooper();
|
||||||
|
@ -215,6 +215,12 @@ import java.util.concurrent.TimeoutException;
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public DeviceComponent getDeviceComponent() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Looper getPlaybackLooper() {
|
public Looper getPlaybackLooper() {
|
||||||
return internalPlayer.getPlaybackLooper();
|
return internalPlayer.getPlaybackLooper();
|
||||||
|
@ -27,6 +27,8 @@ import com.google.android.exoplayer2.C.VideoScalingMode;
|
|||||||
import com.google.android.exoplayer2.audio.AudioAttributes;
|
import com.google.android.exoplayer2.audio.AudioAttributes;
|
||||||
import com.google.android.exoplayer2.audio.AudioListener;
|
import com.google.android.exoplayer2.audio.AudioListener;
|
||||||
import com.google.android.exoplayer2.audio.AuxEffectInfo;
|
import com.google.android.exoplayer2.audio.AuxEffectInfo;
|
||||||
|
import com.google.android.exoplayer2.device.DeviceInfo;
|
||||||
|
import com.google.android.exoplayer2.device.DeviceListener;
|
||||||
import com.google.android.exoplayer2.metadata.MetadataOutput;
|
import com.google.android.exoplayer2.metadata.MetadataOutput;
|
||||||
import com.google.android.exoplayer2.source.TrackGroupArray;
|
import com.google.android.exoplayer2.source.TrackGroupArray;
|
||||||
import com.google.android.exoplayer2.text.TextOutput;
|
import com.google.android.exoplayer2.text.TextOutput;
|
||||||
@ -367,6 +369,48 @@ public interface Player {
|
|||||||
void removeMetadataOutput(MetadataOutput output);
|
void removeMetadataOutput(MetadataOutput output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The device component of a {@link Player}. */
|
||||||
|
// Note: It's mostly from the androidx.media.VolumeProviderCompat and
|
||||||
|
// androidx.media.MediaControllerCompat.PlaybackInfo.
|
||||||
|
interface DeviceComponent {
|
||||||
|
|
||||||
|
/** Adds a listener to receive device events. */
|
||||||
|
void addDeviceListener(DeviceListener listener);
|
||||||
|
|
||||||
|
/** Removes a listener of device events. */
|
||||||
|
void removeDeviceListener(DeviceListener listener);
|
||||||
|
|
||||||
|
/** Gets the device information. */
|
||||||
|
DeviceInfo getDeviceInfo();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current volume of the device.
|
||||||
|
*
|
||||||
|
* <p>For devices with {@link DeviceInfo#PLAYBACK_TYPE_LOCAL local playback}, the volume
|
||||||
|
* returned by this method varies according to the current {@link C.StreamType stream type}. The
|
||||||
|
* stream type is determined by {@link AudioAttributes#usage} which can be converted to stream
|
||||||
|
* type with {@link Util#getStreamTypeForAudioUsage(int)}. The audio attributes can be set to
|
||||||
|
* the player by calling {@link AudioComponent#setAudioAttributes}.
|
||||||
|
*
|
||||||
|
* <p>For devices with {@link DeviceInfo#PLAYBACK_TYPE_REMOTE remote playback}, the volume of
|
||||||
|
* the remote device is returned.
|
||||||
|
*/
|
||||||
|
int getDeviceVolume();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the volume of the device.
|
||||||
|
*
|
||||||
|
* @param volume The volume to set.
|
||||||
|
*/
|
||||||
|
void setDeviceVolume(int volume);
|
||||||
|
|
||||||
|
/** Increases the volume of the device. */
|
||||||
|
void increaseDeviceVolume();
|
||||||
|
|
||||||
|
/** Decreases the volume of the device. */
|
||||||
|
void decreaseDeviceVolume();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listener of changes in player state. All methods have no-op default implementations to allow
|
* Listener of changes in player state. All methods have no-op default implementations to allow
|
||||||
* selective overrides.
|
* selective overrides.
|
||||||
@ -733,6 +777,10 @@ public interface Player {
|
|||||||
@Nullable
|
@Nullable
|
||||||
MetadataComponent getMetadataComponent();
|
MetadataComponent getMetadataComponent();
|
||||||
|
|
||||||
|
/** Returns the component of this player for playback device, or null if it's not supported. */
|
||||||
|
@Nullable
|
||||||
|
DeviceComponent getDeviceComponent();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link Looper} associated with the application thread that's used to access the
|
* Returns the {@link Looper} associated with the application thread that's used to access the
|
||||||
* player and on which player events are received.
|
* player and on which player events are received.
|
||||||
|
@ -484,6 +484,13 @@ public class SimpleExoPlayer extends BasePlayer
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public DeviceComponent getDeviceComponent() {
|
||||||
|
// TODO(b/145595776): Return this after implementing DeviceComponent.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the video scaling mode.
|
* Sets the video scaling mode.
|
||||||
*
|
*
|
||||||
|
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2020 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 com.google.android.exoplayer2.device;
|
||||||
|
|
||||||
|
import androidx.annotation.IntDef;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import java.lang.annotation.Documented;
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/** Information about the playback device. */
|
||||||
|
public final class DeviceInfo {
|
||||||
|
|
||||||
|
/** Types of playback. One of {@link #PLAYBACK_TYPE_LOCAL} or {@link #PLAYBACK_TYPE_REMOTE}. */
|
||||||
|
@Documented
|
||||||
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
|
@Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE})
|
||||||
|
@IntDef({
|
||||||
|
PLAYBACK_TYPE_LOCAL,
|
||||||
|
PLAYBACK_TYPE_REMOTE,
|
||||||
|
})
|
||||||
|
public @interface PlaybackType {}
|
||||||
|
/** Playback happens on the local device (e.g. phone). */
|
||||||
|
public static final int PLAYBACK_TYPE_LOCAL = 0;
|
||||||
|
/** Playback happens outside of the device (e.g. a cast device). */
|
||||||
|
public static final int PLAYBACK_TYPE_REMOTE = 1;
|
||||||
|
|
||||||
|
/** The type of playback. */
|
||||||
|
public final @PlaybackType int playbackType;
|
||||||
|
/** The minimum volume that the device supports. */
|
||||||
|
public final int minVolume;
|
||||||
|
/** The maximum volume that the device supports. */
|
||||||
|
public final int maxVolume;
|
||||||
|
|
||||||
|
/** Creates device information. */
|
||||||
|
public DeviceInfo(@PlaybackType int playbackType, int minVolume, int maxVolume) {
|
||||||
|
this.playbackType = playbackType;
|
||||||
|
this.minVolume = minVolume;
|
||||||
|
this.maxVolume = maxVolume;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(@Nullable Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!(obj instanceof DeviceInfo)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
DeviceInfo other = (DeviceInfo) obj;
|
||||||
|
return playbackType == other.playbackType
|
||||||
|
&& minVolume == other.minVolume
|
||||||
|
&& maxVolume == other.maxVolume;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = 17;
|
||||||
|
result = 31 * result + playbackType;
|
||||||
|
result = 31 * result + minVolume;
|
||||||
|
result = 31 * result + maxVolume;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2020 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 com.google.android.exoplayer2.device;
|
||||||
|
|
||||||
|
import com.google.android.exoplayer2.Player;
|
||||||
|
|
||||||
|
/** A listener for changes of {@link Player.DeviceComponent}. */
|
||||||
|
public interface DeviceListener {
|
||||||
|
|
||||||
|
/** Called when the device information changes. */
|
||||||
|
default void onDeviceInfoChanged(DeviceInfo deviceInfo) {}
|
||||||
|
|
||||||
|
/** Called when the device volume changes. */
|
||||||
|
default void onDeviceVolumeChanged(int volume) {}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2020 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.
|
||||||
|
*/
|
||||||
|
@NonNullApi
|
||||||
|
package com.google.android.exoplayer2.device;
|
||||||
|
|
||||||
|
import com.google.android.exoplayer2.util.NonNullApi;
|
@ -58,6 +58,11 @@ public abstract class StubExoPlayer extends BasePlayer implements ExoPlayer {
|
|||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeviceComponent getDeviceComponent() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Looper getPlaybackLooper() {
|
public Looper getPlaybackLooper() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user