jhomlala / betterplayer

Better video player for Flutter, with multiple configuration options. Solving typical use cases!
Apache License 2.0
928 stars 1.02k forks source link

[BUG] Video player not working on android 12 #941

Open Silfalion opened 2 years ago

Silfalion commented 2 years ago

History check

Yes

Describe the bug When starting a youtube video on Android 12, a certificate error is returned. It's fixed through changing the the httpclient. That's just a side issue.

The main issue occured with Exoplayer returning this error message:

E/ExoPlayerImplInternal(15899):       at sun.security.provider.certpath.PKIXMasterCertPathValidator.validate(PKIXMasterCertPathValidator.java:125)
E/ExoPlayerImplInternal(15899):       ... 49 more
E/flutter (15899): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(VideoError, Video player had error com.google.android.exoplayer2.ExoPlaybackException: Source error, , null)

The error doesn't happen on Android 12 and prior and IOS.

I'm not sure it's the issue but could it be because betterPlayer still depends on exoplayer 2.15? The 2 last versions introduced fixes for android 12 compatibility.

I'm using youtube explode to extract the .googlevideo.com url. And this works fine on prior versions of android

To Reproduce Steps to reproduce the behavior:

  1. Generate youtube url with youtube explode
  2. assign url to Betterplayer data source
  3. setup controller
  4. assign controller to better player widget
  5. run the app
  6. the video doesnt load

*Example code Paste here your minimal reproducible code. This code should be ready to copy-paste-run.

Code used to fetch the URL:

  Future<String> videoURL(String url) async {
    var yt = YoutubeExplode();

    var streamInfo = await yt.videos.streamsClient.getManifest(url);
    var d = streamInfo.muxed.where((e) => e.container == StreamContainer.mp4);
    return d.first.url.toString();
  }

Code used to setup the controller:

setupController() async {
    BetterPlayerDataSource dataSource;
    String url = await videoURL(videoId);
    dataSource = BetterPlayerDataSource(
      BetterPlayerDataSourceType.network,
      url,
      bufferingConfiguration: const BetterPlayerBufferingConfiguration(
        minBufferMs: 2000,
        maxBufferMs: 10000,
        bufferForPlaybackMs: 1000,
        bufferForPlaybackAfterRebufferMs: 2000,
      ),
    );
    await betterPlayerController?.setupDataSource(dataSource);

    betterPlayerController?.setControlsEnabled(false);

    //createListeners();

    //betterPlayerController
    //  ?..addEventsListener(fullScreenListener!)
    //  ..addEventsListener(videoEndListener!);

    log.i("loading state ${state.loading}");

    // emit(state.copyWith(initialized: true));

    log.i("setup finished");
  }

Sorry, the code is tangled so I can't provide the whole code rightaway.

Expected behavior Video loading and starting to play.

Video loaded and playing Screenshots If applicable, add screenshots to help explain your problem.

Flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.10.3, on Linux Mint 20.2 5.4.0-100-generic,
    locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version
    32.1.0-rc1)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2021.1)
[✓] VS Code (version 1.64.2)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

• No issues found!

Better Player version

Smartphone (please complete the following information):

Additional context

rounce commented 2 years ago

The error appears to be a certificate issue. It is unlikely that a newer exo player will help. But you can try https://github.com/shiyiya/betterplayer

jhomlala commented 2 years ago

Can you provide sample url which causes this error? It's unlikely BetterPlayer issue, I think you're missing some configuration on your side.

Silfalion commented 2 years ago

Can you provide sample url which causes this error? It's unlikely BetterPlayer issue, I think you're missing some configuration on your side.

Hey, the issue got fixed on its own so maybe the YouTube certificate had issues. Everything's fine now. While still here wanted to thank you for this amazing package , your work and patience. You rock! Hope it will be less frustrating for you in the future and thank you again.

Silfalion commented 2 years ago

The error appears to be a certificate issue. It is unlikely that a newer exo player will help. But you can try https://github.com/shiyiya/betterplayer

Yes, it was likely that. It's working fine now and sorry for taking so much time to reply.

sanjidbillah commented 2 years ago

@jhomlala Check with this link