Move DeviceComponent in ExoPlayer
PiperOrigin-RevId: 368437660
This commit is contained in:
parent
5ae84ab5f4
commit
54f3dfb453
@ -31,6 +31,7 @@ import com.google.android.exoplayer2.PlaybackParameters;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
import com.google.android.exoplayer2.Timeline;
|
||||
import com.google.android.exoplayer2.audio.AudioAttributes;
|
||||
import com.google.android.exoplayer2.device.DeviceInfo;
|
||||
import com.google.android.exoplayer2.metadata.Metadata;
|
||||
import com.google.android.exoplayer2.source.TrackGroup;
|
||||
import com.google.android.exoplayer2.source.TrackGroupArray;
|
||||
@ -281,13 +282,6 @@ public final class CastPlayer extends BasePlayer {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public DeviceComponent getDeviceComponent() {
|
||||
// TODO(b/151792305): Implement the component.
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Looper getApplicationLooper() {
|
||||
return Looper.getMainLooper();
|
||||
@ -665,6 +659,40 @@ public final class CastPlayer extends BasePlayer {
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
/** This method is not supported and always returns {@link DeviceInfo#UNKNOWN}. */
|
||||
@Override
|
||||
public DeviceInfo getDeviceInfo() {
|
||||
return DeviceInfo.UNKNOWN;
|
||||
}
|
||||
|
||||
/** This method is not supported and always returns {@code 0}. */
|
||||
@Override
|
||||
public int getDeviceVolume() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** This method is not supported and always returns {@code false}. */
|
||||
@Override
|
||||
public boolean isDeviceMuted() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** This method is not supported and does nothing. */
|
||||
@Override
|
||||
public void setDeviceVolume(int volume) {}
|
||||
|
||||
/** This method is not supported and does nothing. */
|
||||
@Override
|
||||
public void increaseDeviceVolume() {}
|
||||
|
||||
/** This method is not supported and does nothing. */
|
||||
@Override
|
||||
public void decreaseDeviceVolume() {}
|
||||
|
||||
/** This method is not supported and does nothing. */
|
||||
@Override
|
||||
public void setDeviceMuted(boolean muted) {}
|
||||
|
||||
// Internal methods.
|
||||
|
||||
// Call deprecated callbacks.
|
||||
|
@ -206,51 +206,6 @@ public interface Player {
|
||||
void clearVideoTextureView(@Nullable TextureView textureView);
|
||||
}
|
||||
|
||||
/** The device component of a {@link Player}. */
|
||||
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)}.
|
||||
*
|
||||
* <p>For devices with {@link DeviceInfo#PLAYBACK_TYPE_REMOTE remote playback}, the volume of
|
||||
* the remote device is returned.
|
||||
*/
|
||||
int getDeviceVolume();
|
||||
|
||||
/** Gets whether the device is muted or not. */
|
||||
boolean isDeviceMuted();
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
/** Sets the mute state of the device. */
|
||||
void setDeviceMuted(boolean muted);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener of changes in player state.
|
||||
*
|
||||
@ -1130,10 +1085,6 @@ public interface Player {
|
||||
@Nullable
|
||||
VideoComponent getVideoComponent();
|
||||
|
||||
/** 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
|
||||
* player and on which player events are received.
|
||||
@ -1810,4 +1761,39 @@ public interface Player {
|
||||
|
||||
/** Returns the current {@link Cue Cues}. This list may be empty. */
|
||||
List<Cue> getCurrentCues();
|
||||
|
||||
/** 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)}.
|
||||
*
|
||||
* <p>For devices with {@link DeviceInfo#PLAYBACK_TYPE_REMOTE remote playback}, the volume of the
|
||||
* remote device is returned.
|
||||
*/
|
||||
int getDeviceVolume();
|
||||
|
||||
/** Gets whether the device is muted or not. */
|
||||
boolean isDeviceMuted();
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
/** Sets the mute state of the device. */
|
||||
void setDeviceMuted(boolean muted);
|
||||
}
|
||||
|
@ -15,9 +15,7 @@
|
||||
*/
|
||||
package com.google.android.exoplayer2.device;
|
||||
|
||||
import com.google.android.exoplayer2.Player;
|
||||
|
||||
/** A listener for changes of {@link Player.DeviceComponent}. */
|
||||
/** A listener for changes of {@link DeviceInfo} or device volume. */
|
||||
public interface DeviceListener {
|
||||
|
||||
/** Called when the device information changes. */
|
||||
|
@ -28,6 +28,8 @@ import com.google.android.exoplayer2.audio.AudioSink;
|
||||
import com.google.android.exoplayer2.audio.AuxEffectInfo;
|
||||
import com.google.android.exoplayer2.audio.DefaultAudioSink;
|
||||
import com.google.android.exoplayer2.audio.MediaCodecAudioRenderer;
|
||||
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.MetadataRenderer;
|
||||
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory;
|
||||
@ -260,6 +262,51 @@ public interface ExoPlayer extends Player {
|
||||
void removeMetadataOutput(MetadataOutput output);
|
||||
}
|
||||
|
||||
/** The device component of an {@link ExoPlayer}. */
|
||||
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)}.
|
||||
*
|
||||
* <p>For devices with {@link DeviceInfo#PLAYBACK_TYPE_REMOTE remote playback}, the volume of
|
||||
* the remote device is returned.
|
||||
*/
|
||||
int getDeviceVolume();
|
||||
|
||||
/** Gets whether the device is muted or not. */
|
||||
boolean isDeviceMuted();
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
/** Sets the mute state of the device. */
|
||||
void setDeviceMuted(boolean muted);
|
||||
}
|
||||
|
||||
/**
|
||||
* The default timeout for calls to {@link #release} and {@link #setForegroundMode}, in
|
||||
* milliseconds.
|
||||
@ -613,6 +660,10 @@ public interface ExoPlayer extends Player {
|
||||
@Nullable
|
||||
MetadataComponent getMetadataComponent();
|
||||
|
||||
/** Returns the component of this player for playback device, or null if it's not supported. */
|
||||
@Nullable
|
||||
DeviceComponent getDeviceComponent();
|
||||
|
||||
/**
|
||||
* Adds a listener to receive audio offload events.
|
||||
*
|
||||
|
@ -29,6 +29,7 @@ import androidx.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.PlayerMessage.Target;
|
||||
import com.google.android.exoplayer2.analytics.AnalyticsCollector;
|
||||
import com.google.android.exoplayer2.audio.AudioAttributes;
|
||||
import com.google.android.exoplayer2.device.DeviceInfo;
|
||||
import com.google.android.exoplayer2.metadata.Metadata;
|
||||
import com.google.android.exoplayer2.source.MediaSource;
|
||||
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
|
||||
@ -1009,6 +1010,40 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
/** This method is not supported and always returns {@link DeviceInfo#UNKNOWN}. */
|
||||
@Override
|
||||
public DeviceInfo getDeviceInfo() {
|
||||
return DeviceInfo.UNKNOWN;
|
||||
}
|
||||
|
||||
/** This method is not supported and always returns {@code 0}. */
|
||||
@Override
|
||||
public int getDeviceVolume() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** This method is not supported and always returns {@link false}. */
|
||||
@Override
|
||||
public boolean isDeviceMuted() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** This method is not supported and does nothing. */
|
||||
@Override
|
||||
public void setDeviceVolume(int volume) {}
|
||||
|
||||
/** This method is not supported and does nothing. */
|
||||
@Override
|
||||
public void increaseDeviceVolume() {}
|
||||
|
||||
/** This method is not supported and does nothing. */
|
||||
@Override
|
||||
public void decreaseDeviceVolume() {}
|
||||
|
||||
/** This method is not supported and does nothing. */
|
||||
@Override
|
||||
public void setDeviceMuted(boolean muted) {}
|
||||
|
||||
private int getCurrentWindowIndexInternal() {
|
||||
if (playbackInfo.timeline.isEmpty()) {
|
||||
return maskingWindowIndex;
|
||||
|
@ -82,7 +82,7 @@ public class SimpleExoPlayer extends BasePlayer
|
||||
Player.VideoComponent,
|
||||
ExoPlayer.TextComponent,
|
||||
ExoPlayer.MetadataComponent,
|
||||
Player.DeviceComponent {
|
||||
ExoPlayer.DeviceComponent {
|
||||
|
||||
/** The default timeout for detaching a surface from the player, in milliseconds. */
|
||||
public static final long DEFAULT_DETACH_SURFACE_TIMEOUT_MS = 2_000;
|
||||
|
@ -28,6 +28,7 @@ import com.google.android.exoplayer2.PlayerMessage;
|
||||
import com.google.android.exoplayer2.SeekParameters;
|
||||
import com.google.android.exoplayer2.Timeline;
|
||||
import com.google.android.exoplayer2.audio.AudioAttributes;
|
||||
import com.google.android.exoplayer2.device.DeviceInfo;
|
||||
import com.google.android.exoplayer2.metadata.Metadata;
|
||||
import com.google.android.exoplayer2.source.MediaSource;
|
||||
import com.google.android.exoplayer2.source.ShuffleOrder;
|
||||
@ -444,6 +445,41 @@ public class StubExoPlayer extends BasePlayer implements ExoPlayer {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceInfo getDeviceInfo() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDeviceVolume() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDeviceMuted() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDeviceVolume(int volume) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void increaseDeviceVolume() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decreaseDeviceVolume() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDeviceMuted(boolean muted) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setForegroundMode(boolean foregroundMode) {
|
||||
throw new UnsupportedOperationException();
|
||||
|
Loading…
x
Reference in New Issue
Block a user