fix: exoplayer fallback on bad container

This commit is contained in:
edde746
2026-01-27 09:39:40 +01:00
parent 394e877b9e
commit 5785df6fc6
3 changed files with 15 additions and 21 deletions
@@ -448,34 +448,20 @@ class ExoPlayerCore(private val activity: Activity) : Player.Listener {
}
override fun onPlayerError(error: PlaybackException) {
Log.e(TAG, "Player error: ${error.message}", error)
Log.e(TAG, "Player error: ${error.message} (code: ${error.errorCode})", error)
// Detect format/codec unsupported errors
val isFormatUnsupported = when {
error.errorCode == PlaybackException.ERROR_CODE_DECODING_FAILED -> true
error.errorCode == PlaybackException.ERROR_CODE_DECODER_INIT_FAILED -> true
error.errorCode == PlaybackException.ERROR_CODE_DECODER_QUERY_FAILED -> true
error.cause?.message?.contains("EXCEEDS_CAPABILITIES") == true -> true
error.cause?.message?.contains("MediaCodec") == true -> true
else -> false
}
if (isFormatUnsupported && currentMediaUri != null) {
Log.w(TAG, "Format unsupported - attempting fallback to MPV")
if (currentMediaUri != null) {
Log.w(TAG, "ExoPlayer error (code ${error.errorCode}) - attempting fallback to MPV")
val handled = delegate?.onFormatUnsupported(
uri = currentMediaUri!!,
headers = currentHeaders,
positionMs = lastPosition,
errorMessage = error.message ?: "Unknown format error"
errorMessage = error.message ?: "Unknown error"
) ?: false
if (handled) {
// Fallback was handled by the plugin, don't emit error
return
}
if (handled) return
}
// Fallback not handled or not a format error - emit error event
delegate?.onEvent("end-file", mapOf(
"reason" to "error",
"message" to (error.message ?: "Unknown error")
@@ -510,7 +510,7 @@ class ExoPlayerPlugin : FlutterPlugin, MethodChannel.MethodCallHandler,
): Boolean {
val currentActivity = activity ?: return false
Log.i(TAG, "Format unsupported, switching to MPV fallback at ${positionMs}ms")
Log.i(TAG, "ExoPlayer error, switching to MPV fallback at ${positionMs}ms: $errorMessage")
currentActivity.runOnUiThread {
try {
+9 -1
View File
@@ -1240,7 +1240,15 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen> with WidgetsBindin
}
void _onPlayerError(String error) {
appLogger.e('[MPV ERROR] $error');
appLogger.e('[Player ERROR] $error');
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(t.messages.failedPlayback(action: 'play', error: error)),
duration: const Duration(seconds: 4),
),
);
}
/// Handle notification when native player switched from ExoPlayer to MPV