Flutter-видео не отображается на некоторых устройствах на AndroidAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Flutter-видео не отображается на некоторых устройствах на Android

Сообщение Anonymous »

Я использую видеоплеер в приложении Flutter, и он отлично работает на большинстве устройств, но на некоторых других мобильных телефонах он не загружается со следующей ошибкой:
PlatformExcepetion ( videoerror:video player had error v0.n: MediaCodecVideoRenderrer error , index=0 , format=Format(1,null,null,video/avs,avc1.64001E,-1,null[352,640,25.000673,Colorinfo(BT709,Limited range , SDR SMTPE 170M , false,8bit Luma , 8bit Chrome)],[-1,1]),format_supported=YES,null,null)

вот мой фрагмент кода:
// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/widgets/index.dart'; // Imports other custom widgets
import '/custom_code/actions/index.dart'; // Imports custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom widget code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import '/custom_code/widgets/index.dart';
import '/custom_code/actions/index.dart';
import '/flutter_flow/custom_functions.dart';

import 'package:chewie/chewie.dart';
import 'package:video_player/video_player.dart';
import 'package:wakelock_plus/wakelock_plus.dart';
import 'package:flutter/services.dart';

class CustomVideoPlayer extends StatefulWidget {
const CustomVideoPlayer({
super.key,
this.width,
this.height,
required this.videoURL,
});

final double? width;
final double? height;
final String videoURL;

@override
State createState() => _CustomVideoPlayerState();
}

class _CustomVideoPlayerState extends State {
late VideoPlayerController videoPlayerController;
ChewieController? chewieController;
bool isLoading = true;
String? errorMessage;

@override
void initState() {
super.initState();
_initializePlayer();
}

Future _checkVideoFormat() async {
// Check if the URL has a supported video format
final supportedFormats = ['.mp4', '.m3u8', '.webm'];
final lowercaseUrl = widget.videoURL.toLowerCase();
return supportedFormats.any((format) => lowercaseUrl.contains(format));
}

Future _initializePlayer() async {
setState(() {
isLoading = true;
errorMessage = null;
});

try {
if (!await _checkVideoFormat()) {
throw Exception(
'Unsupported video format. Please use MP4, HLS, or WebM.');
}

videoPlayerController = VideoPlayerController.networkUrl(
Uri.parse(widget.videoURL),
);

bool initialized = false;
await Future.wait([
videoPlayerController.initialize().then((_) => initialized = true),
Future.delayed(const Duration(seconds: 15)),
]).timeout(
const Duration(seconds: 15),
onTimeout: () {
if (!initialized) {
throw Exception(
'Video loading timed out. Please check your internet connection.');
}
return [];
},
);

chewieController = ChewieController(
videoPlayerController: videoPlayerController,
autoPlay: true,
looping: true,
aspectRatio: videoPlayerController.value.aspectRatio,
allowedScreenSleep: false,
allowFullScreen: true,
deviceOrientationsAfterFullScreen: [DeviceOrientation.portraitUp],
placeholder: Container(
color: Colors.black,
child: const Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(Colors.white),
),
),
),
errorBuilder: (context, errorMessage) {
return Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.error_outline, color: Colors.red, size: 32),
SizedBox(height: 8),
Text(
errorMessage,
style: TextStyle(color: Colors.white),
textAlign: TextAlign.center,
),
SizedBox(height: 16),
ElevatedButton(
onPressed: _retryInitialization,
child: Text('Retry'),
),
],
),
),
);
},
);

if (mounted) {
setState(() {
isLoading = false;
});
}
} catch (e) {
print('Error initializing video player: $e');
if (mounted) {
setState(() {
isLoading = false;
errorMessage = e.toString();
});
}
}
}

Future _retryInitialization() async {
// Cleanup existing controllers
videoPlayerController.dispose();
chewieController?.dispose();

// Reinitialize
await _initializePlayer();
}

@override
Widget build(BuildContext context) {
if (isLoading) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
CircularProgressIndicator(),
SizedBox(height: 16),
Text('Loading video...'),
],
),
);
}

if (errorMessage != null || chewieController == null) {
return Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.error_outline, color: Colors.red, size: 32),
SizedBox(height: 8),
Text(
errorMessage ?? 'Error loading video',
textAlign: TextAlign.center,
),
SizedBox(height: 16),
ElevatedButton(
onPressed: _retryInitialization,
child: Text('Retry'),
),
],
),
),
);
}

WakelockPlus.enable();
return Container(
width: widget.width,
height: widget.height,
child: Chewie(
controller: chewieController!,
),
);
}

@override
void dispose() {
videoPlayerController.dispose();
chewieController?.dispose();
WakelockPlus.disable();
super.dispose();
}
}



Подробнее здесь: https://stackoverflow.com/questions/791 ... on-android
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»