Search code examples
fluttervideo-player

Flutter video player 0.10.9+2 cannot be initialized in real Android project


Following the latest instruction of video_player V0.10.9, I got very strange situation, for the same video url, it works on a brand new flutter project just for demo, but doesn't work in my real project, I mean I got initialization issue in my real Android project. And I've already double checked configurations of the both projects, all are the same.

Both projects works on iPhone, and demo project works on Android phone, but real project doesn't work on the same Android phone.

I put following reference to both pubspec.yaml file:

video_player: ">=0.10.9+2 <2.0.0"

In my demo project, it works correctly:

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(),
      ),
    );
  }
}

But in my real project, initialize() will always make MissingPluginException twice, one for method name init on channel flutter.io/videoPlayer and one for method name create on channel flutter.io/videoPlayer. This exception is thrown at line 319 in file platform_channel.dart.

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(() {});
      }
    });
}

Screenshot

I double checked, configurations of both projects are all the same including iOS and Android settings, absolutely follow every steps in official instruction.

I even thought if multidex makes this difference, but the demo project still works correctly after I set it to support multidex.

Any help would be very appreciated!

BTW, my flutter environment is on stable channel and healthy.

[✓] 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!

Solution

  • Solved by removing flutter_facebook_login: ^3.0.0 from pubspec.yaml.