Я использую видеоплеер в приложении 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
Flutter-видео не отображается на некоторых устройствах на Android ⇐ Android
Форум для тех, кто программирует под Android
-
Anonymous
1730198407
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();
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79136820/flutter-video-fails-to-render-on-some-devices-on-android[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия