mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Make StyledPlayerView depend on PlaybackException
PiperOrigin-RevId: 377480089
This commit is contained in:
parent
cc3cd702ff
commit
536f7c8dbe
2 changed files with 24 additions and 26 deletions
|
|
@ -456,35 +456,33 @@ public class PlayerActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PlayerErrorMessageProvider implements ErrorMessageProvider<ExoPlaybackException> {
|
private class PlayerErrorMessageProvider implements ErrorMessageProvider<PlaybackException> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public Pair<Integer, String> getErrorMessage(@NonNull ExoPlaybackException e) {
|
public Pair<Integer, String> getErrorMessage(@NonNull PlaybackException e) {
|
||||||
String errorString = getString(R.string.error_generic);
|
String errorString = getString(R.string.error_generic);
|
||||||
if (e.type == ExoPlaybackException.TYPE_RENDERER) {
|
Throwable cause = e.getCause();
|
||||||
Exception cause = e.getRendererException();
|
if (cause instanceof DecoderInitializationException) {
|
||||||
if (cause instanceof DecoderInitializationException) {
|
// Special case for decoder initialization failures.
|
||||||
// Special case for decoder initialization failures.
|
DecoderInitializationException decoderInitializationException =
|
||||||
DecoderInitializationException decoderInitializationException =
|
(DecoderInitializationException) cause;
|
||||||
(DecoderInitializationException) cause;
|
if (decoderInitializationException.codecInfo == null) {
|
||||||
if (decoderInitializationException.codecInfo == null) {
|
if (decoderInitializationException.getCause() instanceof DecoderQueryException) {
|
||||||
if (decoderInitializationException.getCause() instanceof DecoderQueryException) {
|
errorString = getString(R.string.error_querying_decoders);
|
||||||
errorString = getString(R.string.error_querying_decoders);
|
} else if (decoderInitializationException.secureDecoderRequired) {
|
||||||
} else if (decoderInitializationException.secureDecoderRequired) {
|
|
||||||
errorString =
|
|
||||||
getString(
|
|
||||||
R.string.error_no_secure_decoder, decoderInitializationException.mimeType);
|
|
||||||
} else {
|
|
||||||
errorString =
|
|
||||||
getString(R.string.error_no_decoder, decoderInitializationException.mimeType);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
errorString =
|
errorString =
|
||||||
getString(
|
getString(
|
||||||
R.string.error_instantiating_decoder,
|
R.string.error_no_secure_decoder, decoderInitializationException.mimeType);
|
||||||
decoderInitializationException.codecInfo.name);
|
} else {
|
||||||
|
errorString =
|
||||||
|
getString(R.string.error_no_decoder, decoderInitializationException.mimeType);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
errorString =
|
||||||
|
getString(
|
||||||
|
R.string.error_instantiating_decoder,
|
||||||
|
decoderInitializationException.codecInfo.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Pair.create(0, errorString);
|
return Pair.create(0, errorString);
|
||||||
|
|
|
||||||
|
|
@ -48,8 +48,8 @@ import androidx.annotation.RequiresApi;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.ControlDispatcher;
|
import com.google.android.exoplayer2.ControlDispatcher;
|
||||||
import com.google.android.exoplayer2.ExoPlaybackException;
|
|
||||||
import com.google.android.exoplayer2.Format;
|
import com.google.android.exoplayer2.Format;
|
||||||
|
import com.google.android.exoplayer2.PlaybackException;
|
||||||
import com.google.android.exoplayer2.Player;
|
import com.google.android.exoplayer2.Player;
|
||||||
import com.google.android.exoplayer2.Player.DiscontinuityReason;
|
import com.google.android.exoplayer2.Player.DiscontinuityReason;
|
||||||
import com.google.android.exoplayer2.Timeline;
|
import com.google.android.exoplayer2.Timeline;
|
||||||
|
|
@ -306,7 +306,7 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
|
||||||
@Nullable private Drawable defaultArtwork;
|
@Nullable private Drawable defaultArtwork;
|
||||||
private @ShowBuffering int showBuffering;
|
private @ShowBuffering int showBuffering;
|
||||||
private boolean keepContentOnPlayerReset;
|
private boolean keepContentOnPlayerReset;
|
||||||
@Nullable private ErrorMessageProvider<? super ExoPlaybackException> errorMessageProvider;
|
@Nullable private ErrorMessageProvider<? super PlaybackException> errorMessageProvider;
|
||||||
@Nullable private CharSequence customErrorMessage;
|
@Nullable private CharSequence customErrorMessage;
|
||||||
private int controllerShowTimeoutMs;
|
private int controllerShowTimeoutMs;
|
||||||
private boolean controllerAutoShow;
|
private boolean controllerAutoShow;
|
||||||
|
|
@ -760,7 +760,7 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
|
||||||
* @param errorMessageProvider The error message provider.
|
* @param errorMessageProvider The error message provider.
|
||||||
*/
|
*/
|
||||||
public void setErrorMessageProvider(
|
public void setErrorMessageProvider(
|
||||||
@Nullable ErrorMessageProvider<? super ExoPlaybackException> errorMessageProvider) {
|
@Nullable ErrorMessageProvider<? super PlaybackException> errorMessageProvider) {
|
||||||
if (this.errorMessageProvider != errorMessageProvider) {
|
if (this.errorMessageProvider != errorMessageProvider) {
|
||||||
this.errorMessageProvider = errorMessageProvider;
|
this.errorMessageProvider = errorMessageProvider;
|
||||||
updateErrorMessage();
|
updateErrorMessage();
|
||||||
|
|
@ -1414,7 +1414,7 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
|
||||||
errorMessageView.setVisibility(View.VISIBLE);
|
errorMessageView.setVisibility(View.VISIBLE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@Nullable ExoPlaybackException error = player != null ? player.getPlayerError() : null;
|
@Nullable PlaybackException error = player != null ? player.getPlayerError() : null;
|
||||||
if (error != null && errorMessageProvider != null) {
|
if (error != null && errorMessageProvider != null) {
|
||||||
CharSequence errorMessage = errorMessageProvider.getErrorMessage(error).second;
|
CharSequence errorMessage = errorMessageProvider.getErrorMessage(error).second;
|
||||||
errorMessageView.setText(errorMessage);
|
errorMessageView.setText(errorMessage);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue