gpt4 book ai didi

flutter - video_player 插件无法播放视频 - Flutter

转载 作者:行者123 更新时间:2023-12-04 11:23:23 26 4
gpt4 key购买 nike

我将我的 flutter 更新到 1.22.0,现在我的 video_player 给了我异常错误。在我将 flutter 更新到 1.22.0 之前,它运行良好。
这是我的错误:

E/flutter ( 8545): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)]Unhandled Exception:'package:flutter/src/services/message_codec.dart': Failed assertion:line 111 pos 15: 'code != null': is not true. E/flutter ( 8545): #0
_AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:46:39) E/flutter ( 8545): #1 _AssertionError._throwNew(dart:core-patch/errors_patch.dart:36:5) E/flutter ( 8545): #2
new PlatformException(package:flutter/src/services/message_codec.dart:111:15) E/flutter (8545): #3 VideoPlayerApi.create(package:video_player_platform_interface/messages.dart:205:13)E/flutter ( 8545): E/flutter ( 8545): #4
MethodChannelVideoPlayer.create(package:video_player_platform_interface/method_channel_video_player.dart:46:42)E/flutter ( 8545): #5 VideoPlayerController.initialize(package:video_player/video_player.dart:275:45) E/flutter ( 8545): #6_ScreenBackgroundVideoState.initState (package:flow/widget/background/screen_background_video.dart:17:9)E/flutter ( 8545): #7 StatefulElement._firstBuild(package:flutter/src/widgets/framework.dart:4765:58) E/flutter (8545): #8 ComponentElement.mount(package:flutter/src/widgets/framework.dart:4601:5) E/flutter ( 8545):#9 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) E/flutter (8545): #10 MultiChildRenderObjectElement.mount(package:flutter/src/widgets/framework.dart:6236:32) E/flutter (8545): #11 Element.inflateWidget(package:flutter/src/widgets/framework.dart:3569:14) E/flutter (8545): #12 Element.updateChild(package:flutter/src/widgets/framework.dart:3327:18) E/flutter (8545): #13 SingleChildRenderObjectElement.mount(package:flutter/src/widgets/framework.dart:6118:14) E/flutter (8545): #14 Element.inflateWidget(package:flutter/src/widgets/framework.dart:3569:14) E/flutter (8545): #15 Element.updateChild(package:flutter/src/widgets/framework.dart:3327:18) E/flutter (8545): #16 ComponentElement.performRebuild(package:flutter/src/widgets/framework.dart:4652:16) E/flutter (8545): #17 Element.rebuild(package:flutter/src/widgets/framework.dart:4343:5) E/flutter ( 8545):#18 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4606:5) E/flutter ( 8545):#19 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5) E/flutter ( 8545):#20 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) E/flutter (8545): #21 Element.updateChild(package:flutter/src/widgets/framework.dart:3327:18) E/flutter (8545): #22 SingleChildRenderObjectElement.mount(package:flutter/src/widgets/framework.dart:6118:14) E/flutter (8545): #23 Element.inflateWidget(package:flutter/src/widgets/framework.dart:3569:14) E/flutter (8545): #24 Element.updateChild(package:flutter/src/widgets/framework.dart:3327:18) E/flutter (8545): #25 SingleChildRenderObjectElement.mount(package:flutter/src/widgets/framework.dart:6118:14) E/flutter (8545): #26 Element.inflateWidget(package:flutter/src/widgets/framework.dart:3569:14) E/flutter (8545): #27 Element.updateChild(package:flutter/src/widgets/framework.dart:3327:18) E/flutter (8545): #28 SingleChildRenderObjectElement.mount(package:flutter/src/widgets/framework.dart:6118:14) E/flutter (8545): #29 Element.inflateWidget(package:flutter/src/widgets/framework.dart:3569:14) E/flutter (8545): #30 Element.updateChild(package:flutter/src/widgets/framework.dart:3327:18) E/flutter (8545): #31 SingleChildRenderObjectElement.mount(package:flutter/src/widgets/framework.dart:6118:14) E/flutter (8545): #32 Element.inflateWidget(package:flutter/src/widgets/framework.dart:3569:14) E/flutter (8545): #33 Element.updateChild(package:flutter/src/widgets/framework.dart:3327:18) E/flutter (8545): #34 ComponentElement.performRebuild(package:flutter/src/widgets/framework.dart:4652:16) E/flutter (8545): #35 Element.rebuild(package:flutter/src/widgets/framework.dart:4343:5) E/flutter ( 8545):#36 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4606:5) E/flutter ( 8545):#37 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5) E/flutter ( 8545):#38 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) E/flutter (8545): #39 Element.updateChild(package:flutter/src/widgets/framework.dart:3327:18) E/flutter (8545): #40 SingleChildRenderObjectElement.mount(package:flutter/src/widgets/framework.dart:6118:14) E/flutter (8545): #41 Element.inflateWidget(package:flutter/src/widgets/framework.dart:3569:14) E/flutter (8545): #42 Element.updateChild(package:flutter/src/widgets/framework.dart:3327:18) E/flutter (8545): #43 ComponentElement.performRebuild(package:flutter/src/widgets/framework.dart:4652:16)


这是我的代码:
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';

class ScreenBackgroundVideo extends StatefulWidget {
@override
_ScreenBackgroundVideoState createState() => _ScreenBackgroundVideoState();
}

class _ScreenBackgroundVideoState extends State<ScreenBackgroundVideo> {
VideoPlayerController _controller;

@override
void initState() {
super.initState();
_controller = VideoPlayerController.asset('assets/vid/login.mp4')
// set background video using assets for login screen
..initialize().then((_) {
// Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
setState(() {});
}); // background video will play as soon as the splashscreen is closed
_controller.play();
_controller
.setLooping(true); // looping set to true for the background video
_controller.setVolume(0); // volume set to 0 for background video
}

@override
void dispose() {
super.dispose();
// TODO: implement dispose
_controller.dispose(); // Dispose the controller after play is done.
}

@override
Widget build(BuildContext context) {
return Container(
child: _controller.value.initialized
? AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: VideoPlayer(_controller),
)
: Container(),
);
}
}
需要帮助来解决这个问题。

最佳答案

我不得不将我的 flutter 版本降级到 1.20.2 才能让我的 video_player 工作。
如果有任何其他解决方案,请告诉我。

关于flutter - video_player 插件无法播放视频 - Flutter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64191623/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com