Show toast if media contains only unplayable audio/video.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=123885817
This commit is contained in:
parent
00aef6ddb7
commit
5cde3aa314
@ -235,8 +235,7 @@ public class PlayerActivity extends Activity implements SurfaceHolder.Callback,
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
initializePlayer();
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), R.string.storage_permission_denied,
|
||||
Toast.LENGTH_LONG).show();
|
||||
showToast(R.string.storage_permission_denied);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@ -330,10 +329,10 @@ public class PlayerActivity extends Activity implements SurfaceHolder.Callback,
|
||||
}
|
||||
|
||||
private void onUnsupportedDrmError(UnsupportedDrmException e) {
|
||||
String errorString = getString(Util.SDK_INT < 18 ? R.string.error_drm_not_supported
|
||||
int errorStringId = Util.SDK_INT < 18 ? R.string.error_drm_not_supported
|
||||
: e.reason == UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME
|
||||
? R.string.error_drm_unsupported_scheme : R.string.error_drm_unknown);
|
||||
Toast.makeText(getApplicationContext(), errorString, Toast.LENGTH_LONG).show();
|
||||
? R.string.error_drm_unsupported_scheme : R.string.error_drm_unknown;
|
||||
showToast(errorStringId);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -416,7 +415,7 @@ public class PlayerActivity extends Activity implements SurfaceHolder.Callback,
|
||||
}
|
||||
}
|
||||
if (errorString != null) {
|
||||
Toast.makeText(getApplicationContext(), errorString, Toast.LENGTH_LONG).show();
|
||||
showToast(errorString);
|
||||
}
|
||||
playerNeedsSource = true;
|
||||
updateButtonVisibilities();
|
||||
@ -440,8 +439,24 @@ public class PlayerActivity extends Activity implements SurfaceHolder.Callback,
|
||||
// DefaultTrackSelector.EventListener implementation
|
||||
|
||||
@Override
|
||||
public void onTracksChanged(TrackInfo trackSet) {
|
||||
public void onTracksChanged(TrackInfo trackInfo) {
|
||||
updateButtonVisibilities();
|
||||
// Print toasts if there exist only unplayable video or audio tracks.
|
||||
int videoRendererSupport = TrackInfo.RENDERER_SUPPORT_NO_TRACKS;
|
||||
int audioRendererSupport = TrackInfo.RENDERER_SUPPORT_NO_TRACKS;
|
||||
for (int i = 0; i < trackInfo.rendererCount; i++) {
|
||||
if (player.getRendererType(i) == C.TRACK_TYPE_VIDEO) {
|
||||
videoRendererSupport = Math.max(videoRendererSupport, trackInfo.getRendererSupport(i));
|
||||
} else if (player.getRendererType(i) == C.TRACK_TYPE_AUDIO) {
|
||||
audioRendererSupport = Math.max(audioRendererSupport, trackInfo.getRendererSupport(i));
|
||||
}
|
||||
}
|
||||
if (videoRendererSupport == TrackInfo.RENDERER_SUPPORT_UNPLAYABLE_TRACKS) {
|
||||
showToast(R.string.error_unsupported_video);
|
||||
}
|
||||
if (audioRendererSupport == TrackInfo.RENDERER_SUPPORT_UNPLAYABLE_TRACKS) {
|
||||
showToast(R.string.error_unsupported_audio);
|
||||
}
|
||||
}
|
||||
|
||||
// User controls
|
||||
@ -573,6 +588,14 @@ public class PlayerActivity extends Activity implements SurfaceHolder.Callback,
|
||||
return CaptionStyleCompat.createFromCaptionStyle(captioningManager.getUserStyle());
|
||||
}
|
||||
|
||||
private void showToast(int messageId) {
|
||||
showToast(getString(messageId));
|
||||
}
|
||||
|
||||
private void showToast(String message) {
|
||||
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
private static final class KeyCompatibleMediaController extends MediaController {
|
||||
|
||||
private MediaController.MediaPlayerControl playerControl;
|
||||
|
@ -47,6 +47,10 @@
|
||||
|
||||
<string name="error_instantiating_decoder">Unable to instantiate decoder <xliff:g id="decoder_name">%1$s</xliff:g></string>
|
||||
|
||||
<string name="error_unsupported_video">Media includes video tracks, but none are playable by this device</string>
|
||||
|
||||
<string name="error_unsupported_audio">Media includes audio tracks, but none are playable by this device</string>
|
||||
|
||||
<string name="storage_permission_denied">Permission to access storage was denied</string>
|
||||
|
||||
<string name="sample_list_load_error">One or more sample lists failed to load</string>
|
||||
|
@ -427,6 +427,19 @@ public final class DefaultTrackSelector extends TrackSelector implements
|
||||
*/
|
||||
public static final class TrackInfo {
|
||||
|
||||
/**
|
||||
* The renderer does not have any associated tracks.
|
||||
*/
|
||||
public static final int RENDERER_SUPPORT_NO_TRACKS = 0;
|
||||
/**
|
||||
* The renderer has associated tracks, but cannot play any of them.
|
||||
*/
|
||||
public static final int RENDERER_SUPPORT_UNPLAYABLE_TRACKS = 1;
|
||||
/**
|
||||
* The renderer has associated tracks, and can play at least one of them.
|
||||
*/
|
||||
public static final int RENDERER_SUPPORT_PLAYABLE_TRACKS = 2;
|
||||
|
||||
/**
|
||||
* The number of renderers.
|
||||
*/
|
||||
@ -459,7 +472,7 @@ public final class DefaultTrackSelector extends TrackSelector implements
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the array of {@link TrackGroup}s that belong to the renderer at a specified index.
|
||||
* Gets the array of {@link TrackGroup}s associated to the renderer at a specified index.
|
||||
*
|
||||
* @param rendererIndex The renderer index.
|
||||
* @return The corresponding {@link TrackGroup}s.
|
||||
@ -478,6 +491,28 @@ public final class DefaultTrackSelector extends TrackSelector implements
|
||||
return trackSelections[rendererIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the extent to which a renderer can support playback of the tracks associated to it.
|
||||
*
|
||||
* @param rendererIndex The renderer index.
|
||||
* @return One of {@link #RENDERER_SUPPORT_PLAYABLE_TRACKS},
|
||||
* {@link #RENDERER_SUPPORT_UNPLAYABLE_TRACKS} and {@link #RENDERER_SUPPORT_NO_TRACKS}.
|
||||
*/
|
||||
public int getRendererSupport(int rendererIndex) {
|
||||
boolean hasTracks = false;
|
||||
int[][] rendererFormatSupport = formatSupport[rendererIndex];
|
||||
for (int i = 0; i < rendererFormatSupport.length; i++) {
|
||||
for (int j = 0; j < rendererFormatSupport[i].length; j++) {
|
||||
hasTracks = true;
|
||||
if ((rendererFormatSupport[i][j] & TrackRenderer.FORMAT_SUPPORT_MASK)
|
||||
== TrackRenderer.FORMAT_HANDLED) {
|
||||
return RENDERER_SUPPORT_PLAYABLE_TRACKS;
|
||||
}
|
||||
}
|
||||
}
|
||||
return hasTracks ? RENDERER_SUPPORT_UNPLAYABLE_TRACKS : RENDERER_SUPPORT_NO_TRACKS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the extent to which the format of an individual track is supported by the renderer.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user