【问题标题】:Video widget doesn't play "Unable to establish connection on channel"视频小部件不播放“无法在频道上建立连接”
【发布时间】:2021-03-20 16:20:10
【问题描述】:

您好,我一直在尝试在我的颤振应用程序的背景中播放视频 所以我关注了this issuethis tutorial

我想出了以下代码:

import 'package:flutter/material.dart';

void main() => runApp(VideoWidget());

class VideoWidget extends StatefulWidget {
  @override
  _VideoWidgetState createState() => _VideoWidgetState();
}

class _VideoWidgetState extends State<VideoWidget> {
  VideoPlayerController _controller;

  @override
  void initState() {
    super.initState();
    _controller = VideoPlayerController.asset("images/background.mov")
      ..initialize().then((_) {
        _controller.setLooping(true);
        _controller.play();
        // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
        setState(() {});
      });
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: _controller.value.initialized
          ? AspectRatio(
              aspectRatio: _controller.value.aspectRatio,
              child: VideoPlayer(_controller),
            )
          : Container(),
    );
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }
}

我确保视频在 images folderpubspec.yaml 上可用:


environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  hovering: ^1.0.2
  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.1
  video_player: ^0.10.5+2

dev_dependencies:
  flutter_test:
    sdk: flutter

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  assets:
    - images/2x/IconWithText.png
    - images/IconWithText.png
    - images/background.mov

但在构建应用程序后,我最终遇到以下错误:

[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)
#0      VideoPlayerApi.create (package:video_player_platform_interface/messages.dart:199:7)
<asynchronous suspension>
#1      MethodChannelVideoPlayer.create (package:video_player_platform_interface/method_channel_video_player.dart:46:31)
<asynchronous suspension>
#2      VideoPlayerController.initialize (package:video_player/video_player.dart:275:18)
<asynchronous suspension>
#3      _VideoWidgetState.initState.<anonymous closure> (package:myapp/video_widget.dart)
<asynchronous suspension>

我这样称呼 VideoWidget:

@override
  Widget build(BuildContext context) {
    var isLogged = false;
    var column = Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        VideoWidget(),
        Table(

我是 dart 和 flutter 的初学者,因此请务必询问我是否需要更多信息来帮助解决此问题,并感谢您的帮助!

【问题讨论】:

    标签: flutter


    【解决方案1】:

    从您的依赖项来看,您的版本太旧了,请先尝试将其升级到 1.0.1,因为您的错误似乎来自您的依赖项

    【讨论】:

    • video_player: ^1.0.1 ?
    • 我尝试做 video_player: ^1.0.1 然后重新启动应用程序,我最终遇到了同样的问题。
    • 您使用的video_player依赖已支持格式视频,请在此链接exoplayer.dev/supported-formats.html查看,因为video_player使用exoplayer作为播放器
    • @iqbalrahardian 谢谢...原来刚从 iOS 相机录制的 .MOV 文件不受支持。
    【解决方案2】:

    再次运行应用程序。有时,如果不关闭应用程序并再次运行,插件将无法工作。

    【讨论】:

      猜你喜欢
      • 2013-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多