Remove Player.Listener inheritance of AudioListener

PiperOrigin-RevId: 390332263
This commit is contained in:
olly 2021-08-12 11:25:28 +01:00 committed by Oliver Woodman
parent c5b01b2f7b
commit 2a6136f370
5 changed files with 34 additions and 107 deletions

View File

@ -26,6 +26,8 @@
* Remove `FileDataSourceFactory`. Use `FileDataSource.Factory` instead.
* Remove `SimpleExoPlayer.addMetadataOutput` and `removeMetadataOutput`.
Use `Player.addListener` and `Player.Listener` instead.
* Remove `SimpleExoPlayer.addAudioListener`, `removeAudioListener` and
`AudioListener`. Use `Player.addListener` and `Player.Listener` instead.
### 2.15.0 (2021-08-10)

View File

@ -24,7 +24,6 @@ import android.view.TextureView;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.audio.AudioAttributes;
import com.google.android.exoplayer2.audio.AudioListener;
import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.text.Cue;
@ -870,7 +869,7 @@ public interface Player {
*
* <p>All methods have no-op default implementations to allow selective overrides.
*/
interface Listener extends VideoListener, AudioListener, TextOutput, EventListener {
interface Listener extends VideoListener, TextOutput, EventListener {
@Override
default void onTimelineChanged(Timeline timeline, @TimelineChangeReason int reason) {}
@ -928,16 +927,32 @@ public interface Player {
@Override
default void onSeekBackIncrementChanged(long seekBackIncrementMs) {}
@Override
/**
* Called when the audio session ID changes.
*
* @param audioSessionId The audio session ID.
*/
default void onAudioSessionIdChanged(int audioSessionId) {}
@Override
/**
* Called when the audio attributes change.
*
* @param audioAttributes The audio attributes.
*/
default void onAudioAttributesChanged(AudioAttributes audioAttributes) {}
@Override
/**
* Called when the volume changes.
*
* @param volume The new volume, with 0 being silence and 1 being unity gain.
*/
default void onVolumeChanged(float volume) {}
@Override
/**
* Called when skipping silences is enabled or disabled in the audio stream.
*
* @param skipSilenceEnabled Whether skipping silences in the audio stream is enabled.
*/
default void onSkipSilenceEnabledChanged(boolean skipSilenceEnabled) {}
/** Called when the device information changes. */

View File

@ -1,55 +0,0 @@
/*
* Copyright (C) 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 com.google.android.exoplayer2.audio;
import com.google.android.exoplayer2.Player;
/**
* A listener for changes in audio configuration.
*
* @deprecated Use {@link Player.Listener}.
*/
@Deprecated
public interface AudioListener {
/**
* Called when the audio session ID changes.
*
* @param audioSessionId The audio session ID.
*/
default void onAudioSessionIdChanged(int audioSessionId) {}
/**
* Called when the audio attributes change.
*
* @param audioAttributes The audio attributes.
*/
default void onAudioAttributesChanged(AudioAttributes audioAttributes) {}
/**
* Called when the volume changes.
*
* @param volume The new volume, with 0 being silence and 1 being unity gain.
*/
default void onVolumeChanged(float volume) {}
/**
* Called when skipping silences is enabled or disabled in the audio stream.
*
* @param skipSilenceEnabled Whether skipping silences in the audio stream is enabled.
*/
default void onSkipSilenceEnabledChanged(boolean skipSilenceEnabled) {}
}

View File

@ -29,7 +29,6 @@ import androidx.annotation.VisibleForTesting;
import com.google.android.exoplayer2.analytics.AnalyticsCollector;
import com.google.android.exoplayer2.audio.AudioAttributes;
import com.google.android.exoplayer2.audio.AudioCapabilities;
import com.google.android.exoplayer2.audio.AudioListener;
import com.google.android.exoplayer2.audio.AudioSink;
import com.google.android.exoplayer2.audio.AuxEffectInfo;
import com.google.android.exoplayer2.audio.DefaultAudioSink;
@ -146,24 +145,6 @@ public interface ExoPlayer extends Player {
/** The audio component of an {@link ExoPlayer}. */
interface AudioComponent {
/**
* Adds a listener to receive audio events.
*
* @param listener The listener to register.
* @deprecated Use {@link #addListener(Listener)}.
*/
@Deprecated
void addAudioListener(AudioListener listener);
/**
* Removes a listener of audio events.
*
* @param listener The listener to unregister.
* @deprecated Use {@link #removeListener(Listener)}.
*/
@Deprecated
void removeAudioListener(AudioListener listener);
/**
* Sets the attributes for audio playback, used by the underlying audio track. If not set, the
* default audio attributes will be used. They are suitable for general media playback.

View File

@ -48,7 +48,6 @@ import androidx.annotation.VisibleForTesting;
import com.google.android.exoplayer2.analytics.AnalyticsCollector;
import com.google.android.exoplayer2.analytics.AnalyticsListener;
import com.google.android.exoplayer2.audio.AudioAttributes;
import com.google.android.exoplayer2.audio.AudioListener;
import com.google.android.exoplayer2.audio.AudioRendererEventListener;
import com.google.android.exoplayer2.audio.AuxEffectInfo;
import com.google.android.exoplayer2.decoder.DecoderCounters;
@ -427,7 +426,6 @@ public class SimpleExoPlayer extends BasePlayer
private final ComponentListener componentListener;
private final FrameMetadataListener frameMetadataListener;
private final CopyOnWriteArraySet<VideoListener> videoListeners;
private final CopyOnWriteArraySet<AudioListener> audioListeners;
private final CopyOnWriteArraySet<TextOutput> textOutputs;
private final CopyOnWriteArraySet<Listener> listeners;
private final AnalyticsCollector analyticsCollector;
@ -510,7 +508,6 @@ public class SimpleExoPlayer extends BasePlayer
componentListener = new ComponentListener();
frameMetadataListener = new FrameMetadataListener();
videoListeners = new CopyOnWriteArraySet<>();
audioListeners = new CopyOnWriteArraySet<>();
textOutputs = new CopyOnWriteArraySet<>();
listeners = new CopyOnWriteArraySet<>();
Handler eventHandler = new Handler(builder.looper);
@ -802,21 +799,6 @@ public class SimpleExoPlayer extends BasePlayer
player.removeAudioOffloadListener(listener);
}
@Deprecated
@Override
public void addAudioListener(AudioListener listener) {
// Don't verify application thread. We allow calls to this method from any thread.
Assertions.checkNotNull(listener);
audioListeners.add(listener);
}
@Deprecated
@Override
public void removeAudioListener(AudioListener listener) {
// Don't verify application thread. We allow calls to this method from any thread.
audioListeners.remove(listener);
}
@Override
public void setAudioAttributes(AudioAttributes audioAttributes, boolean handleAudioFocus) {
verifyApplicationThread();
@ -828,8 +810,9 @@ public class SimpleExoPlayer extends BasePlayer
sendRendererMessage(TRACK_TYPE_AUDIO, MSG_SET_AUDIO_ATTRIBUTES, audioAttributes);
streamVolumeManager.setStreamType(Util.getStreamTypeForAudioUsage(audioAttributes.usage));
analyticsCollector.onAudioAttributesChanged(audioAttributes);
for (AudioListener audioListener : audioListeners) {
audioListener.onAudioAttributesChanged(audioAttributes);
// TODO(internal b/187152483): Events should be dispatched via ListenerSet
for (Listener listener : listeners) {
listener.onAudioAttributesChanged(audioAttributes);
}
}
@ -867,8 +850,9 @@ public class SimpleExoPlayer extends BasePlayer
sendRendererMessage(TRACK_TYPE_AUDIO, MSG_SET_AUDIO_SESSION_ID, audioSessionId);
sendRendererMessage(TRACK_TYPE_VIDEO, MSG_SET_AUDIO_SESSION_ID, audioSessionId);
analyticsCollector.onAudioSessionIdChanged(audioSessionId);
for (AudioListener audioListener : audioListeners) {
audioListener.onAudioSessionIdChanged(audioSessionId);
// TODO(internal b/187152483): Events should be dispatched via ListenerSet
for (Listener listener : listeners) {
listener.onAudioSessionIdChanged(audioSessionId);
}
}
@ -898,8 +882,9 @@ public class SimpleExoPlayer extends BasePlayer
this.audioVolume = audioVolume;
sendVolumeToRenderers();
analyticsCollector.onVolumeChanged(audioVolume);
for (AudioListener audioListener : audioListeners) {
audioListener.onVolumeChanged(audioVolume);
// TODO(internal b/187152483): Events should be dispatched via ListenerSet
for (Listener listener : listeners) {
listener.onVolumeChanged(audioVolume);
}
}
@ -1120,7 +1105,6 @@ public class SimpleExoPlayer extends BasePlayer
@Override
public void addListener(Listener listener) {
Assertions.checkNotNull(listener);
addAudioListener(listener);
addVideoListener(listener);
addTextOutput(listener);
listeners.add(listener);
@ -1139,7 +1123,6 @@ public class SimpleExoPlayer extends BasePlayer
@Override
public void removeListener(Listener listener) {
Assertions.checkNotNull(listener);
removeAudioListener(listener);
removeVideoListener(listener);
removeTextOutput(listener);
listeners.remove(listener);
@ -1827,7 +1810,8 @@ public class SimpleExoPlayer extends BasePlayer
@SuppressWarnings("SuspiciousMethodCalls")
private void notifySkipSilenceEnabledChanged() {
analyticsCollector.onSkipSilenceEnabledChanged(skipSilenceEnabled);
for (AudioListener listener : audioListeners) {
// TODO(internal b/187152483): Events should be dispatched via ListenerSet
for (Listener listener : listeners) {
listener.onSkipSilenceEnabledChanged(skipSilenceEnabled);
}
}