视频播放器在 flutter 2.0 中崩溃(空安全)

Video player breaks down in flutter 2.0 (null safety)

我想在我的 flutter 应用程序中显示一个视频,并且像往常一样,我正在使用 video_player 插件。但出于某种原因,现在我已经迁移到空安全,视频播放器给我这个错误

Error: PlatformException(MEDIA_ERR_SRC_NOT_SUPPORTED, MEDIA_ELEMENT_ERROR: Format error, The video has been found to be unsuitable (missing or in a format not supported by your browser)., null)


    at Object.createErrorWithStack (http://localhost:59815/dart_sdk.js:5050:12)
    at Object._rethrow (http://localhost:59815/dart_sdk.js:37641:16)
    at async._AsyncCallbackEntry.new.callback (http://localhost:59815/dart_sdk.js:37637:13)
    at Object._microtaskLoop (http://localhost:59815/dart_sdk.js:37497:13)
    at _startMicrotaskLoop (http://localhost:59815/dart_sdk.js:37503:13)
    at http://localhost:59815/dart_sdk.js:33274:9

我是 运行 我在 flutter web 上的代码,并且正在使用示例代码的精确复制粘贴,只是迁移到空安全。这是我的代码

import 'package:video_player/video_player.dart';
import 'package:flutter/material.dart';

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

class ChapterVideoPlayer extends StatefulWidget {
  @override
  _ChapterVideoPlayerState createState() => _ChapterVideoPlayerState();
}

class _ChapterVideoPlayerState extends State<ChapterVideoPlayer> {
  VideoPlayerController? _controller;

  @override
  void initState() {
    super.initState();
    _controller = VideoPlayerController.network(
        'https://www.sample-videos.com/video123/mp4/720/big_buck_bunny_720p_20mb.mp4')
      ..initialize().then((_) {
        // 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 MaterialApp(
      title: 'Video Demo',
      home: Scaffold(
        body: Center(
          child: _controller!.value.isInitialized
              ? AspectRatio(
            aspectRatio: _controller!.value.aspectRatio,
            child: VideoPlayer(_controller!),
          )
              : Container(),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            setState(() {
              _controller!.value.isPlaying
                  ? _controller!.pause()
                  : _controller!.play();
            });
          },
          child: Icon(
            _controller!.value.isPlaying ? Icons.pause : Icons.play_arrow,
          ),
        ),
      ),
    );
  }

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

我做错了吗?或者是插件有问题。我可以同时使用任何替代品吗?任何帮助将不胜感激。我正在使用版本 ^2.1.1

MEDIA_ERR_SRC_NOT_SUPPORTED 只是另一个错误 net::ERR_CERT_COMMON_NAME_INVALID 的结果(您可以在浏览器控制台中看到它)。因为默认情况下并非所有 SSL 证书都涵盖网站的 WWW 和非 WWW 版本(例如 sample-videos.com),您必须从 url 中删除 www

    _controller = VideoPlayerController.network(
        'https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_20mb.mp4')
      ..initialize().then((_) {
        // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
        setState(() {});
      });