5

我将颤振更新到 1.22.0,现在我的 video_player 给了我异常错误。在我将颤振更新到 1.22.0 之前它工作正常。

这是我的错误:

E/flutter(8545):[错误:flutter/lib/ui/ui_dart_state.cc(177)]未处理的异常:'package:flutter/src/services/message_codec.dart':断言失败:第111行pos 15:'code != null': 不正确。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 (包:flutter/src/widgets/framework.dart:3569:14)E/flutter(8545):#27 Element.updateChild(包: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 (包:flutter/src/widgets/framework.dart:4652:16)E/flutter(8545):#35 Element.rebuild(包: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 (包:flutter/src/widgets/framework.dart:3327:18)E/flutter(8545):#43 ComponentElement.performRebuild(包:颤振/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(),
    );
  }
}

需要帮助来解决这个问题。

4

3 回答 3

3

我不得不将我的颤振版本降级到 1.20.2 才能让我的 video_player 工作。

如果有其他解决方案,请告诉我。

于 2020-10-06T06:45:33.663 回答
1

或者,如果您没有使用视频播放器插件中的任何新功能,您可以将视频播放器降级到0.10.11+2而不是降级颤振。

您可以在此处找到更多详细信息:https ://github.com/flutter/flutter/issues/66627

于 2020-10-06T11:28:38.727 回答
1

同样的问题我刚刚升级了颤振版本 1.22.5 并且它有效

于 2020-12-23T07:23:32.250 回答