【问题标题】:Flutter video player 0.10.9+2 cannot be initialized in real Android projectFlutter video player 0.10.9+2 无法在真实Android项目中初始化
【发布时间】:2020-08-22 04:05:16
【问题描述】:

按照video_player V0.10.9的最新指令,我遇到了非常奇怪的情况,对于same video url,它适用于一个全新的flutter项目,只是为了演示,但在我的实际项目中不起作用,我的意思是我得到了我真正的 Android 项目中的初始化问题。而且我已经仔细检查了这两个项目的配置,都是一样的。

两个项目都可以在 iPhone 上运行,演示项目可以在 Android 手机上运行,​​但实际项目不能在同一部 Android 手机上运行。

我对这两个 pubspec.yaml 文件进行了以下引用:

video_player: ">=0.10.9+2 <2.0.0"

在我的演示项目中,它可以正常工作:

class _MyHomePageState extends State<MyHomePage> {
  final videoUrl =
      'https://captnotes.com/wp-content/uploads/2020/02/demo_video_02.mp4';

  VideoPlayerController videoPlayerController;

  @override
  void initState() {
    super.initState();

    print('^_^initState()');

    videoPlayerController = VideoPlayerController.network(videoUrl)
      ..initialize().then((_) {
        setState(() {
          videoPlayerController.play();
          print('^_^play()');
        });
      })
      ..addListener(() {
        print('Is playing: ${videoPlayerController.value.isPlaying}');
      });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: videoPlayerController.value.initialized
            ? AspectRatio(
                aspectRatio: videoPlayerController.value.aspectRatio,
                child: VideoPlayer(videoPlayerController))
            : Container(),
      ),
    );
  }
}

但在我的实际项目中,initialize() 总是会产生 MissingPluginException 两次,一次用于通道 flutter.io/videoPlayer 上的方法名称 init,另一次用于通道 flutter.io/videoPlayer 上的方法名称 create .此异常在文件 platform_channel.dart 的第 319 行引发。

void initVideoPlayer() {
  if (TextUtil.isEmpty(videoUrl)) {
    logger.debug('videoUrl is EMPTY.');
    return;
  }

  logger.debug('videoUrl: $videoUrl');

  videoPlayerController?.dispose();
  videoPlayerController = VideoPlayerController.network(videoUrl)
    ..initialize()
    ..addListener(() {
      // logger.debug(
      //     'isVideoPlaying: $isVideoPlaying, videoPlayerController.value.isPlaying: ${videoPlayerController.value.isPlaying}');

      if (isVideoPreparing && videoPlayerController.value.isPlaying) {
        isVideoPreparing = false;
        isVideoPlaying = true;
      } else if (isVideoPlaying && !videoPlayerController.value.isPlaying) {
        videoPlayerController.seekTo(Duration(milliseconds: 0));
        isVideoPlaying = false;
        stopVideo();
        setState(() {});
      }
    });
}

我仔细检查了,两个项目的配置都是一样的,包括iOS和Android设置,绝对按照官方说明的每一步。

我什至认为如果 multidex 会产生这种影响,但是在我将演示项目设置为支持 multidex 后,它仍然可以正常工作。

任何帮助将不胜感激!

顺便说一句,我的 Flutter 环境处于稳定通道且健康。

[✓] Flutter (Channel stable, v1.12.13+hotfix.9, on Mac OS X 10.14.6 18G103, locale en-CN)
    • Flutter version 1.12.13+hotfix.9 at /Volumes/Transcend/Development/flutter
    • Framework revision f139b11009 (5 weeks ago), 2020-03-30 13:57:30 -0700
    • Engine revision af51afceb8
    • Dart version 2.7.2

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Volumes/Transcend/Development/AndroidSDK
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.3.1, Build version 11C504
    • CocoaPods version 1.9.0

[✓] Android Studio (version 3.6)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 45.1.1
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[✓] VS Code (version 1.44.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.10.1

[✓] Connected device (1 available)
    • SM G9500 • 988a1b474239545746 • android-arm64 • Android 9 (API 28)

• No issues found!

【问题讨论】:

  • 尝试强制重启应用。我猜它会起作用的。
  • @VinothVino,我试过了,我什至多次重启手机,但仍然很重要。

标签: flutter video-player


【解决方案1】:

通过从 pubspec.yaml 中删除 flutter_facebook_login: ^3.0.0 解决。

【讨论】:

    【解决方案2】:

    降级到颤振版本 1.20.4 并且 video_player 插件可以正常工作。它是与 video_player 插件产生问题的新颤振版本

    更新: 当前 Flutter sdk 稳定版和 video_player 插件最新版本运行良好

    【讨论】:

      猜你喜欢
      • 2020-12-22
      • 1970-01-01
      • 2020-08-29
      • 2019-06-19
      • 2022-08-04
      • 2020-12-21
      • 1970-01-01
      • 2021-12-30
      • 2018-11-19
      相关资源
      最近更新 更多