首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >颤振video_player不能在一个页面中加载多个视频

颤振video_player不能在一个页面中加载多个视频
EN

Stack Overflow用户
提问于 2020-11-28 16:19:46
回答 2查看 2.3K关注 0票数 3

我想创建一个页面在颤振与多个循环视频。在我的手机(三星Galaxy 10 Plus)上,所有的视频都加载得很完美,但当我在其他手机上运行相同的应用程序(我尝试了三星Galaxy S6和Galaxy A71)时,两个视频正在加载,其他视频被黑方格替换。

这是我的flutter doctor -v运行:

代码语言:javascript
复制
[√] Flutter (Channel stable, 1.22.4, on Microsoft Windows [Version 10.0.19042.630], locale en-US)
    • Flutter version 1.22.4 at C:\src\flutter
    • Framework revision 1aafb3a8b9 (2 weeks ago), 2020-11-13 09:59:28 -0800
    • Engine revision 2c956a31c0
    • Dart version 2.10.4

 
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2) 
    • Android SDK at C:\Users\myName\AppData\Local\Android\sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java       
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[!] Android Studio (version 4.1.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] VS Code (version 1.51.1)
    • VS Code at C:\Users\myName\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.16.0

[√] Connected device (1 available)
    • SM A715F (mobile) • R58N70XS23W • android-arm64 • Android 10 (API 29)

(我用代码编写代码)

在应用程序的调试版本中,我没有发现任何错误,但是视频仍然没有加载。

这是video_player控制器的配置:

代码语言:javascript
复制
class clipVideo extends StatefulWidget {
  final String path;
  clipVideo(this.path);
  @override
  _clipVideo createState() => _clipVideo();
}

class _clipVideo extends State<clipVideo> {
  String _path;
  VideoPlayerController _controller;
  Future<void> _initializeVideoPlayerFuture;
  @override
  void initState() {
    _path = widget.path;
    _controller = VideoPlayerController.asset(_path);
    //_controller = VideoPlayerController.network(
    //   'https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4');
    _initializeVideoPlayerFuture = _controller.initialize();
    _controller.play();
    _controller.setVolume(0.0);
    _controller.setLooping(true);
    super.initState();
  }

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

  @override
  Widget build(BuildContext context) {
    return Container(
      child: FutureBuilder(
        future: _initializeVideoPlayerFuture,
        builder: (context, snapshot) {
          if (snapshot.connectionState == ConnectionState.done) {
            return Center(
              child: AspectRatio(
                aspectRatio: _controller.value.aspectRatio,
                child: VideoPlayer(_controller),
              ),
            );
          } else {
            return Center(
              child: CircularProgressIndicator(),
            );
          }
        },
      ),
    );
  }
}

这是我要呈现多个循环视频的页面Scaffold的内容:

代码语言:javascript
复制
body: SafeArea(
            child: Container(
                child: ListView(
          children: [
            SizedBox(height: 30.0),
            Column(
              children: [
                Image(
                    image: AssetImage('assets/images/logoecomed.png'),
                    width: 200.0),
                SizedBox(
                  height: 50.0,
                ),
                Row(
                  children: <Widget>[
                    SizedBox(width: 20.0),
                    Flexible(
                        child: Text(
                      'Text',
                      textAlign: TextAlign.start,
                      style: TextStyle(
                          color: Color(0xff40514e),
                          fontSize: 25.0,
                          fontFamily: 'Nurom',
                          fontWeight: FontWeight.w800),
                    )),
                    SizedBox(width: 15.0)
                  ],
                ),
                SizedBox(
                  height: 15.0,
                ),
                Row(
                  children: <Widget>[
                    SizedBox(width: 20.0),
                    Flexible(
                        child: Text(
                      'Text',
                      textAlign: TextAlign.start,
                      style: TextStyle(
                        color: Color(0xff40514e),
                        fontSize: 18.0,
                        fontFamily: 'Helvetica',
                        fontWeight: FontWeight.w200,
                      ),
                    )),
                    SizedBox(width: 30.0)
                  ],
                ),
                SizedBox(
                  height: 20,
                ),
                Container(
                  height: 550,
                  child: clipVideo('assets/videos/record1.mp4'),
                ),
                SizedBox(
                  height: 60,
                ),
                Row(
                  children: <Widget>[
                    SizedBox(width: 20.0),
                    Flexible(
                        child: Text(
                      'Text',
                      textAlign: TextAlign.start,
                      style: TextStyle(
                          color: Color(0xff40514e),
                          fontSize: 25.0,
                          fontFamily: 'Nurom',
                          fontWeight: FontWeight.w800),
                    ))
                  ],
                ),
                SizedBox(
                  height: 20.0,
                ),
                Row(
                  children: <Widget>[
                    SizedBox(width: 20.0),
                    Flexible(
                        child: Text(
                      'Text',
                      textAlign: TextAlign.start,
                      style: TextStyle(
                        color: Color(0xff40514e),
                        fontSize: 18.0,
                        fontFamily: 'Helvetica',
                        fontWeight: FontWeight.w200,
                      ),
                    )),
                    SizedBox(width: 40.0)
                  ],
                ),
                SizedBox(
                  height: 20,
                ),
                Container(
                  height: 550,
                  child: clipVideo('assets/videos/record3.mp4'),
                ),
                SizedBox(
                  height: 20,
                ),
                Row(
                  children: <Widget>[
                    SizedBox(width: 20.0),
                    Flexible(
                        child: Text(
                      'Text',
                      textAlign: TextAlign.start,
                      style: TextStyle(
                        color: Color(0xff40514e),
                        fontSize: 18.0,
                        fontFamily: 'Helvetica',
                        fontWeight: FontWeight.w200,
                      ),
                    )),
                    SizedBox(width: 40.0)
                  ],
                ),
                SizedBox(
                  height: 20,
                ),
                Container(
                  height: 550,
                  child: clipVideo('assets/videos/record2.mp4'),
                ),
                SizedBox(
                  height: 20,
                ),
                Row(
                  children: <Widget>[
                    SizedBox(width: 20.0),
                    Flexible(
                        child: Text(
                      'Text',
                      textAlign: TextAlign.start,
                      style: TextStyle(
                        color: Color(0xff40514e),
                        fontSize: 18.0,
                        fontFamily: 'Helvetica',
                        fontWeight: FontWeight.w200,
                      ),
                    )),
                    SizedBox(width: 40.0)
                  ],
                ),
                SizedBox(
                  height: 20,
                ),
                Container(
                  height: 550,
                  child: clipVideo('assets/videos/record6.mp4'),
                ),
                SizedBox(
                  height: 30,
                ),
                Row(
                  children: <Widget>[
                    SizedBox(width: 20.0),
                    Flexible(
                        child: Text(
                      'Text',
                      textAlign: TextAlign.start,
                      style: TextStyle(
                        color: Color(0xff40514e),
                        fontSize: 18.0,
                        fontFamily: 'Helvetica',
                        fontWeight: FontWeight.w200,
                      ),
                    )),
                    SizedBox(width: 40.0)
                  ],
                ),
                SizedBox(
                  height: 30,
                ),
                Row(
                  children: <Widget>[
                    SizedBox(width: 20.0),
                    Flexible(
                        child: Text(
                      'Text',
                      textAlign: TextAlign.start,
                      style: TextStyle(
                        color: Color(0xff40514e),
                        fontSize: 18.0,
                        fontFamily: 'Helvetica',
                        fontWeight: FontWeight.w200,
                      ),
                    )),
                    SizedBox(width: 40.0)
                  ],
                ),
                SizedBox(
                  height: 20,
                ),
                Container(
                  height: 550,
                  child: clipVideo('assets/videos/record4.mp4'),
                ),
                SizedBox(
                  height: 20,
                ),
                Row(
                  children: <Widget>[
                    SizedBox(width: 20.0),
                    Flexible(
                        child: Text(
                      'Text',
                      textAlign: TextAlign.start,
                      style: TextStyle(
                        color: Colors.red,
                        fontSize: 18.0,
                        fontFamily: 'Helvetica',
                        fontWeight: FontWeight.w200,
                      ),
                    )),
                    SizedBox(width: 40.0)
                  ],
                ),
                SizedBox(
                  height: 60,
                ),
                Row(
                  children: <Widget>[
                    SizedBox(width: 20.0),
                    Flexible(
                        child: Text(
                      'Text?',
                      textAlign: TextAlign.start,
                      style: TextStyle(
                          color: Color(0xff40514e),
                          fontSize: 25.0,
                          fontFamily: 'Nurom',
                          fontWeight: FontWeight.w800),
                    ))
                  ],
                ),
                SizedBox(
                  height: 20,
                ),
                Row(
                  children: <Widget>[
                    SizedBox(width: 20.0),
                    Flexible(
                        child: Text(
                      'Text',
                      textAlign: TextAlign.start,
                      style: TextStyle(
                        color: Color(0xff40514e),
                        fontSize: 18.0,
                        fontFamily: 'Helvetica',
                        fontWeight: FontWeight.w200,
                      ),
                    )),
                    SizedBox(width: 40.0)
                  ],
                ),
                SizedBox(
                  height: 20,
                ),
                Container(
                  height: 550,
                  child: clipVideo('assets/videos/record5.mp4'),
                ),
                SizedBox(
                  height: 30,
                ),
                // Center(
                //     child: Flexible(
                //         child: Text(
                //   'Text',
                //   textAlign: TextAlign.start,
                //   style: TextStyle(
                //     color: Color(0xff40514e),
                //     fontSize: 18.0,
                //     fontFamily: 'Helvetica',
                //     fontWeight: FontWeight.w800,
                //   ),
                // ))),
                // SizedBox(
                //   height: 90,
                // )
              ],
            )
          ],
        )))

资产包括在我的pubspec.yaml

代码语言:javascript
复制
flutter:
  assets:
    - assets/
    - assets/images/logoecomed.png
    - assets/videos/record1.mp4
    - assets/videos/record2.mp4
    - assets/videos/record3.mp4
    - assets/videos/record4.mp4
    - assets/videos/record5.mp4
    - assets/videos/record6.mp4

我把video_player版本改成了新版本,但它没有解决anything.Is问题--也许是因为手机?录像是不是太大了?(每个record[number].mp4都有8-10 MB)。

编辑:我试图将视频的大小缩小到2-3 MB,但它仍然不起作用。但是我发现当我使用多个视频进入该页面时,video_player插件会冻结/崩溃(我在前一页上有另一段视频也被冻结了),所以插件在某个地方崩溃了。

第二版:经过更多的flutter run之后,我在这里发现了一些东西:

代码语言:javascript
复制
D/MediaCodecInfo(18771): AssumedSupport [sizeAndRate.rotated, 1080x2280x60.19792938232422] [OMX.Exynos.avc.dec, video/avc] [zeroflte, SM-G920F, samsung, 24]
D/MediaCodecInfo(18771): NoSupport [sizeAndRate.support, 1080x2280x60.19792938232422] [OMX.SEC.avc.sw.dec, video/avc] [zeroflte, SM-G920F, samsung, 24]
D/MediaCodecInfo(18771): NoSupport [sizeAndRate.support, 1080x2280x60.19792938232422] [OMX.SEC.avc.sw.dec, video/avc] [zeroflte, SM-G920F, samsung, 24]
D/MediaCodecInfo(18771): NoSupport [sizeAndRate.support, 1080x2280x60.19792938232422] [OMX.google.h264.decoder, video/avc] [zeroflte, SM-G920F, samsung, 24]
D/MediaCodecInfo(18771): AssumedSupport [sizeAndRate.rotated, 1080x2280x60.19792938232422] [OMX.Exynos.avc.dec, video/avc] [zeroflte, SM-G920F, samsung, 24]
D/MediaCodecInfo(18771): AssumedSupport [sizeAndRate.rotated, 1080x2280x60.19792938232422] [OMX.Exynos.avc.dec, video/avc] [zeroflte, SM-G920F, samsung, 24]
D/MediaCodecInfo(18771): NoSupport [sizeAndRate.support, 1080x2280x60.19792938232422] [OMX.SEC.avc.sw.dec, video/avc] [zeroflte, SM-G920F, samsung, 24]
D/MediaCodecInfo(18771): NoSupport [sizeAndRate.support, 1080x2280x60.19792938232422] [OMX.SEC.avc.sw.dec, video/avc] [zeroflte, SM-G920F, samsung, 24]
D/MediaCodecInfo(18771): NoSupport [sizeAndRate.support, 1080x2280x60.19792938232422] [OMX.google.h264.decoder, video/avc] [zeroflte, SM-G920F, samsung, 24]
D/MediaCodecInfo(18771): AssumedSupport [sizeAndRate.rotated, 1080x2280x60.19792938232422] [OMX.Exynos.avc.dec, video/avc] [zeroflte, SM-G920F, samsung, 24]

我认为这是视频的问题,而不是玩家的问题

第三编辑:裁剪和调整视频后,video_player只显示每一个视频的第一帧,除了最后一个。我不知道该怎么办。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-11-28 19:09:20

我还是解决了它..。降级的video_player插件和调整视频大小已经做到了这一点。

票数 0
EN

Stack Overflow用户

发布于 2020-11-28 17:10:51

首先要改变这一点:

代码语言:javascript
复制
flutter:
  assets:
    - assets/images/
    - assets/videos/

重新构建并运行该应用程序。如果它不能工作,那么在终端上运行下面的命令。

代码语言:javascript
复制
flutter upgrade

flutter config --android-studio-dir="C:\Program Files\Android\Android Studio"

flutter doctor -v

如果问题仍然存在,那么只需切换到beta通道,升级就会改变。

代码语言:javascript
复制
flutter channel stable

flutter upgrade

我要求您运行终端命令,因为我注意到了这个错误。

代码语言:javascript
复制
[!] Android Studio (version 4.1.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

如果有用的话告诉我..。

注释:运行终端命令后的,您需要重新构建应用程序并运行。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65051790

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档