flutter开发实战-video_player播放多个视频MediaCodecVideoRenderer error问题

flutter开发实战-video_player播放多个视频MediaCodecVideoRenderer error问题

在开发过程中,我这里使用video_player播放多个视频的时候,出现了MediaCodecVideoRenderer error

一、使用video_player播放视频

使用video_player播放单个视频请查看
https://blog.csdn.net/gloryFlow/article/details/132124837

这里记录一下解决多个视频MediaCodecVideoRenderer error问题。

二、在app/build.gradle下添加依赖

在app/build.gradle下添加依赖

dependencies{implementation 'com.google.android.exoplayer:exoplayer:2.17.1'
}

实现播放视频的Widget,在播放测试过程中,出现只能播放一个视频,可以设置VideoPlayerOptions,将VideoPlayerOptions的mixWithOthers设置为true。

Future<void> waitVideoPlay() async {_controller?.dispose();_controller = VideoPlayerController.networkUrl(Uri.parse(widget.videoUrl),videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true,allowBackgroundPlayback: false,),);await _controller?.initialize().then((_) {// Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.setState(() {});});await _controller!.setLooping(true);if (widget.autoPlay) {await _controller?.play();} else {await _controller?.pause();}}

完整VideoPlayerWidget代码如下

import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';//  视频播放测试
class VideoPlayerWidget extends StatefulWidget {const VideoPlayerWidget({Key? key,required this.videoUrl,required this.isLooping,this.autoPlay = true,required this.width,required this.height,}) : super(key: key);final String videoUrl;final bool isLooping;final bool autoPlay;final double width;final double height;@overrideState<VideoPlayerWidget> createState() => _VideoPlayerWidgetState();
}class _VideoPlayerWidgetState extends State<VideoPlayerWidget> {VideoPlayerController? _controller;@overridevoid initState() {super.initState();waitVideoPlay();}Future<void> waitVideoPlay() async {_controller?.dispose();_controller = VideoPlayerController.networkUrl(Uri.parse(widget.videoUrl),videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true,allowBackgroundPlayback: false,),);await _controller?.initialize().then((_) {// Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.setState(() {});});await _controller!.setLooping(true);if (widget.autoPlay) {await _controller?.play();} else {await _controller?.pause();}}@overrideWidget build(BuildContext context) {if (_controller != null && _controller!.value.isInitialized) {return Container(width: widget.width,height: widget.height,child: AspectRatio(aspectRatio: _controller!.value.aspectRatio,child: VideoPlayer(_controller!),),);}return Container(width: widget.width,height: widget.height,color: Colors.orange,);}@overridevoid dispose() {// TODO: implement dispose_controller?.dispose();super.dispose();}
}

三、video_player播放界面播放多个视频

在使用VideoPlayerWidget播放多个视频,

Widget buildVideoContainer(BuildContext context) {Size screenSize = MediaQuery.of(context).size;return Container(width: screenSize.width,height: screenSize.height,color: Colors.white,child: Wrap(spacing: 24.0.r, // 主轴(水平)方向间距runSpacing: 12.0.r, // 纵轴(垂直)方向间距alignment: WrapAlignment.center, //沿主轴方向居中children: buildVideoListWidget(context),),);}List<Widget> buildVideoListWidget(BuildContext context) {List<Widget> list = [];for (int i = 0; i < 4; i++) {String videoUrl = videoList[i];VideoPlayerWidget widget = VideoPlayerWidget(key: GlobalKey(),videoUrl: videoUrl,isLooping: true,width: 320.r,height: 480.r,delayDuration: Duration(seconds: i),);list.add(widget);}return list;}

完整video_page代码如下

class VideoPage extends StatefulWidget {const VideoPage({super.key});@overrideState<VideoPage> createState() => _VideoPageState();
}class _VideoPageState extends State<VideoPage>with AutomaticKeepAliveClientMixin {List<String> videoList = [];@overridevoid initState() {// TODO: implement initStateinitVideoList();super.initState();}void initVideoList() {videoList.add("https://v-qiniu.laikeshuo.com/1648693943358lkGhcDwFQzw3Ix266OsW7WWkzhY0.mp4");videoList.add("https://v-qiniu.laikeshuo.com/833134651693235939767");videoList.add("https://v-qiniu.laikeshuo.com/fb52e680058440a8b220ff7d2d555632");videoList.add("https://v-qiniu.laikeshuo.com/f6967489119040319a5fdda8be3e5662");videoList.add("https://v-qiniu.laikeshuo.com/7364b2eb14d54234b205d77147106b7f");videoList.add("https://v-qiniu.laikeshuo.com/ceee6bedf4814fbcaf4178ea5fb84fc0");videoList.add("https://v-qiniu.laikeshuo.com/3f7a60531042461eb10bf29f0c31ec6b");videoList.add("https://v-qiniu.laikeshuo.com/515211835007418da0e6b26425de907c");videoList.add("https://v-qiniu.laikeshuo.com/0bd0eaf2d30e4a66a4d7a5eb9970ed2a");videoList.add("https://v-qiniu.laikeshuo.com/35b2548bcf5140bc93425dcd69054294");videoList.add("https://v-qiniu.laikeshuo.com/3f7a60531042461eb10bf29f0c31ec6b");// videoList//     .add("https://dphoto.qiniu.laikeshuo.com/bc7a2df5143a4d3a84c8a8407b22e933.mp4");// videoList//     .add("https://dalat-qiniu.laikeshuo.com/31c5040167ec43168d7ec80c9bf33104.mp4");}@overridevoid dispose() {// TODO: implement disposesuper.dispose();}@overrideWidget build(BuildContext context) {return Scaffold(body: ProviderWidget<VideoModel>(model: VideoModel(),onModelReady: (model) => model.initData(),builder: (context, model, child) {if (model.isBusy) {return Container();} else if (model.isError) {return Container();} else if (model.isEmpty) {return Container();}return buildVideoContainer(context);},),);}Widget buildVideoContainer(BuildContext context) {Size screenSize = MediaQuery.of(context).size;return Container(width: screenSize.width,height: screenSize.height,color: Colors.white,child: Wrap(spacing: 24.0.r, // 主轴(水平)方向间距runSpacing: 12.0.r, // 纵轴(垂直)方向间距alignment: WrapAlignment.center, //沿主轴方向居中children: buildVideoListWidget(context),),);}List<Widget> buildVideoListWidget(BuildContext context) {List<Widget> list = [];for (int i = 0; i < 4; i++) {String videoUrl = videoList[i];VideoPlayerWidget widget = VideoPlayerWidget(key: GlobalKey(),videoUrl: videoUrl,isLooping: true,width: 320.r,height: 480.r,delayDuration: Duration(seconds: i),);list.add(widget);}return list;}@override// TODO: implement wantKeepAlivebool get wantKeepAlive => true;
}

经过测试,发现播放多个视频,播放三个正常,多于三个时候,会报告如下错误。(我使用的是低配置的Android主板,设备性能差)

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(VideoError, Video player had error x0.q: MediaCodecVideoRenderer error, index=0, format=Format(1, null, null, video/avc, avc1.64001E, -1, null, [1080, 1920, 30.0], [-1, -1]), format_supported=YES, null, null)

三、小结

flutter开发实战-video_player播放多个视频MediaCodecVideoRenderer error问题。

https://blog.csdn.net/gloryFlow/article/details/132676760

学习记录,每天不停进步。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/75591.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python基础语法(二)

目录 注释注释的语法注释行文档字符串 注释的规范 输入输出和用户的交互通过控制台输出通过控制台的输入 注释 注释的语法 注释行 python的注释:使用#开通的行都是注释 # 这是一行注释C语言的注释:使用//的都是注释 // 这是一行注释文档字符串 使用三引号引起来的称为文档…

人工智能安全-4-小样本问题

0 提纲 小样本学习问题数据增强基于模型的小样本学习基于算法的小样本学习相关资源1 小样本学习问题 在小样本监督分类中,通常将问题表述为 N-way-K-shot分类, 当K = 1,称为one-shot learning;当K = 0时,成为zero-shot learning(ZSL)。ZSL就要求学习的问题具备充足的先…

Mybatis-plus 抽象-接口方法类

Model pojo 类继承 Model 抽象类&#xff0c;即可获得 CRUD&#xff08;增删改查&#xff09;功能。Model 使用映射类 pojo 继承 Model 抽象类&#xff0c;直接使用该类可以进行 CRUD&#xff0c;但是必须存在对应的 xxMapper 继承 BaseMapper。 Mapper Mapper 用于 service…

算法AB实验平台进化历程和挑战

1 AB 平台简介 AB 实验平台这几年在互联网公司得到了越来越广泛的应用&#xff0c;采用 AB 实验来评估产品和技术迭代效果也成为主流的业务新功能效果评估方式&#xff0c;数据驱动的文化在这几年得到了不少公司的广泛的认同&#xff0c;通过数据和指标来说明产品效果也得到了…

ROM是什么? 刷ROM是什么意思?

文章目录 ROM是什么&#xff1f;刷ROM是什么意思 ROM是什么&#xff1f; ROM是只读内存&#xff08;Read-Only Memory&#xff09;的简称&#xff0c;是一种只能读出事先所存数据的固态半导体存储器。其特性是一旦储存资料就无法再将之改变或删除。通常用在不需经常变更资料的…

大数据组件-Flink环境搭建

&#x1f947;&#x1f947;【大数据学习记录篇】-持续更新中~&#x1f947;&#x1f947; 个人主页&#xff1a;beixi 本文章收录于专栏&#xff08;点击传送&#xff09;&#xff1a;【大数据学习】 &#x1f493;&#x1f493;持续更新中&#xff0c;感谢各位前辈朋友们支持…

Nacos使用和注册部分源码介绍

Nacos简单介绍 Nacos致力于帮助您发现、配置和管理微服务。Nacos提供了一组简单易用的特性集&#xff0c;帮助您快速实现动态服务发现、服务配置、服务元数据及流量管理。Nacos帮助您更敏捷和容易地构建、交付和管理微服务平台。Nacos是构建以“服务”为中心的现代应用架构 (例…

汇编:lea 需要注意的一点

lea和mov的效用上不一样&#xff0c;如果当前%rsi的值是0&#xff0c; lea 0x28(%rsi),%rax &#xff0c;这个只是计算一个地址&#xff0c;而不是去做地址访问。 mov 0x8(%rsi),%rsi&#xff0c;而这个mov&#xff0c;在计算完地址&#xff0c;还要访问内存地址。如果rsi是0&a…

NLP信息抽取全解析:从命名实体到事件的PyTorch实战指南

目录 引言背景和信息抽取的重要性文章的目标和结构 信息抽取概述什么是信息抽取信息抽取的应用场景信息抽取的主要挑战 实体识别什么是实体识别实体识别的应用场景PyTorch实现代码输入、输出与处理过程 关系抽取什么是关系抽取关系抽取的应用场景PyTorch实现代码输入、输出与处…

超高真空度精密控制解决方案设计中百度“文心一言”的具体应用

摘要&#xff1a;本文采用国产版本ChatGPT百度“文心一言”作为一种辅助工具&#xff0c;针对超高真空度精密控制装置的开发进行了初期的技术路线设计&#xff0c;对话调研的重点是了解可调节式微流量进气阀门和可用于连接非线性输出信号型真空计的PID控制器。总体而言&#xf…

Google Hacking搜索

Google Hacking概述 GoogleHacking基本用法逻辑或OR逻辑与And逻辑非NOT完整匹配 GoogleHacking高级用法sitefiletypeinurlintitleintext Google Hacking DataBaseGoogle Hacking概述 GoogleHacking&#xff1a;利用搜索引擎有争对性的搜索信息来对网络入侵的技术和行为。搜索引…

异步请求库的实际应用案例:爬取豆瓣经典电影

在日常爬虫过程中&#xff0c;你有没有遇到过需要爬取大量数据的情况&#xff0c;但是传统的同步请求方式让您等得焦头烂额&#xff1f; 这个问题的根源在于传统的同步请求方式。当我们使用同步请求时&#xff0c;程序会一直等待服务器的响应&#xff0c;直到数据返回后才能继续…

【juc】ReentrantReadWriteLock之缓存(仅当学习)

目录 一、说明二、代码示例2.1 pom依赖2.2 示例代码2.3 实体类 三、示例截图 一、说明 1.针对于读多写少的情况 2.先查缓存&#xff0c;没有再去查库 二、代码示例 2.1 pom依赖 <?xml version"1.0" encoding"UTF-8"?> <project xmlns"h…

期权权利金计算方法大揭秘!详解期权权利金的计算公式

期权的权利金就是指期权合约市场当时的价格&#xff0c;权利金是会浮动的&#xff0c;跟股票的价格一样&#xff0c;随着市场的波动而波动。权利金是期权费&#xff0c;不是保证金。那么期权权利金计算方法大揭秘&#xff01;详解期权权利金的计算公式。 一、什么是期权的权利金…

031:vue子组件向父组件传递多个参数,父组件2种解析方法

第031个 查看专栏目录: VUE ------ element UI 专栏目标 在vue和element UI联合技术栈的操控下&#xff0c;本专栏提供行之有效的源代码示例和信息点介绍&#xff0c;做到灵活运用。 &#xff08;1&#xff09;提供vue2的一些基本操作&#xff1a;安装、引用&#xff0c;模板使…

C++初阶--类和对象(中)

目录 类的6个默认成员函数构造函数使用方法 析构函数使用方法 拷贝构造函数使用方法 赋值运算符重载赋值运算符重载 const成员 上篇末尾我们讲到了关于c实现栈相较于c语言在传递参数时的一些优化&#xff0c;但实际上&#xff0c;c在 初始化 清理 赋值 拷贝等方面也做了很大程…

Java虚拟机(JVM)夺命20连问

博主介绍&#xff1a;✌全网粉丝3W&#xff0c;全栈开发工程师&#xff0c;从事多年软件开发&#xff0c;在大厂呆过。持有软件中级、六级等证书。可提供微服务项目搭建与毕业项目实战&#xff0c;博主也曾写过优秀论文&#xff0c;查重率极低&#xff0c;在这方面有丰富的经验…

Java voliate关键字常见面试题

1. 什么是 volatile 关键字&#xff1f;它的作用是什么&#xff1f; volatile 是 Java 中的关键字&#xff0c;用于声明一个变量是“易变”的&#xff0c;即可能被多个线程同时修改。它的主要作用是保证对该变量的读写操作具有可见性&#xff0c;即一个线程对该变量的修改对其…

Edit文本框支持回车Tab字符输入的方法C++源码

本篇文章属于《518抽奖软件开发日志》系列文章的一部分。 我在开发《518抽奖软件》&#xff08;www.518cj.net&#xff09;的时候&#xff0c;要在文本框里输入一行行的名单&#xff0c;要支持回车换行、Tab字符的输入。但是默认对话框上的文本框&#xff0c;是没法输入回车和T…

1.创建项目(wpf视觉项目)

目录 前言本章环境创建项目启动项目可执行文件 前言 本项目主要开发为视觉应用&#xff0c;项目包含&#xff08;视觉编程halcon的应用&#xff0c;会引入handycontrol组件库&#xff0c;工具库Masuit.Tools.Net&#xff0c;数据库工具sqlSugar等应用&#xff09; 后续如果还有…