fix: exoplayer fallback on bad container
This commit is contained in:
@@ -448,34 +448,20 @@ class ExoPlayerCore(private val activity: Activity) : Player.Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onPlayerError(error: PlaybackException) {
|
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
|
if (currentMediaUri != null) {
|
||||||
val isFormatUnsupported = when {
|
Log.w(TAG, "ExoPlayer error (code ${error.errorCode}) - attempting fallback to MPV")
|
||||||
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")
|
|
||||||
val handled = delegate?.onFormatUnsupported(
|
val handled = delegate?.onFormatUnsupported(
|
||||||
uri = currentMediaUri!!,
|
uri = currentMediaUri!!,
|
||||||
headers = currentHeaders,
|
headers = currentHeaders,
|
||||||
positionMs = lastPosition,
|
positionMs = lastPosition,
|
||||||
errorMessage = error.message ?: "Unknown format error"
|
errorMessage = error.message ?: "Unknown error"
|
||||||
) ?: false
|
) ?: false
|
||||||
|
|
||||||
if (handled) {
|
if (handled) return
|
||||||
// Fallback was handled by the plugin, don't emit error
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback not handled or not a format error - emit error event
|
|
||||||
delegate?.onEvent("end-file", mapOf(
|
delegate?.onEvent("end-file", mapOf(
|
||||||
"reason" to "error",
|
"reason" to "error",
|
||||||
"message" to (error.message ?: "Unknown error")
|
"message" to (error.message ?: "Unknown error")
|
||||||
|
|||||||
@@ -510,7 +510,7 @@ class ExoPlayerPlugin : FlutterPlugin, MethodChannel.MethodCallHandler,
|
|||||||
): Boolean {
|
): Boolean {
|
||||||
val currentActivity = activity ?: return false
|
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 {
|
currentActivity.runOnUiThread {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1240,7 +1240,15 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen> with WidgetsBindin
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _onPlayerError(String error) {
|
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
|
/// Handle notification when native player switched from ExoPlayer to MPV
|
||||||
|
|||||||
Reference in New Issue
Block a user