media-kit / media-kit

A cross-platform video player & audio player for Flutter & Dart.
https://github.com/media-kit/media-kit
MIT License
884 stars 119 forks source link

Black Screen on Android #787

Closed Orillio closed 5 days ago

Orillio commented 1 week ago

When i play media through this plugin on android emulator. Only black screen is shown, but the audio is still playing.

Dont know if its related, but i get this error on MediaKit.ensureInitialized();

image

Flutter doctor

[✓] Flutter (Channel stable, 3.19.0, on macOS 14.2.1 23C71 darwin-arm64, locale ru-RU)
    • Flutter version 3.19.0 on channel stable at /opt/homebrew/Caskroom/flutter/3.7.6/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision bae5e49bc2 (2 months ago), 2024-02-13 17:46:18 -0800
    • Engine revision 04817c99c9
    • Dart version 3.3.0
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/ykozyrenko/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C500b
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)

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

[✓] Connected device (3 available)
    • sdk gphone64 arm64 (mobile)  • emulator-5554             • android-arm64  • Android 14 (API 34) (emulator)
    • macOS (desktop)              • macos                     • darwin-arm64   • macOS 14.2.1 23C71 darwin-arm64
    • Chrome (web)                 • chrome                    • web-javascript • Google Chrome 111.0.5563.64

[✓] Network resources
    • All expected network resources are available.

• No issues found!
abdelaziz-mahdy commented 1 week ago

ensureInitialized failed i think it may be the reason of the black screen can you try the package from github?

dependency_overrides:
  media_kit: 
    git:
      url: https://github.com/media-kit/media-kit
      path: media_kit
  media_kit_video: 
    git:
      url: https://github.com/media-kit/media-kit
      path: media_kit_video
  media_kit_libs_video: 
    git:
      url: https://github.com/media-kit/media-kit
      path: libs/universal/media_kit_libs_video
Orillio commented 1 week ago

@abdelaziz-mahdy Nope, same thing happens

This is my pubspec.yaml file, if you need it

name: mirror
description: "A new Flutter project."
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
  sdk: '>=3.3.0 <4.0.0'

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.6
  bloc: ^8.1.3
  flutter_bloc: ^8.1.4
  injectable: ^2.3.5
  get_it: ^7.6.7
  auto_route: ^7.9.2
  hive: ^2.2.3
  freezed_annotation: ^2.4.1
  flutter_svg: ^2.0.10+1
  path_provider: ^2.1.2
  flutter_gen: ^5.4.0
  flutter_native_splash: ^2.4.0
  flutter_launcher_icons: ^0.13.1
  flutter_screenutil: ^5.9.0
  flutter_multi_formatter: ^2.12.4
  dio: ^5.4.3+1
  collection: ^1.18.0
  smooth_page_indicator: ^1.1.0
  intl: ^0.19.0
  json_annotation: ^4.8.1
  video_thumbnail: ^0.5.3
  faker: ^2.1.0
  file_picker: ^8.0.0+1
  dio_request_inspector: ^3.0.1
  image_picker: ^1.0.7
  transparent_pointer: ^1.0.0
  url_launcher: ^6.2.5
  http_parser: ^4.0.2
  dio_cookie_manager: ^3.1.1
  cookie_jar: ^4.0.8
  uuid: ^3.0.7

  media_kit: ^1.1.10
  media_kit_video: ^1.2.4
  media_kit_libs_video: ^1.0.4
  media_kit_libs_android_video: ^1.3.6
  media_kit_native_event_loop: ^1.0.8
  media_kit_libs_ios_video: ^1.1.4

dependency_overrides:
  media_kit: 
    git:
      url: https://github.com/media-kit/media-kit
      path: media_kit
  media_kit_video: 
    git:
      url: https://github.com/media-kit/media-kit
      path: media_kit_video
  media_kit_libs_video: 
    git:
      url: https://github.com/media-kit/media-kit
      path: libs/universal/media_kit_libs_video

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^3.0.0
  build_runner: ^2.4.8
  injectable_generator: ^2.5.1
  auto_route_generator: ^7.3.2
  freezed: ^2.4.7
  flutter_gen_runner: ^5.4.0
  hive_generator: ^2.0.1
  json_serializable: ^6.7.1

flutter_gen:
  output: lib/presentation/shared/assets/

  integrations:
    flutter_svg: true

flutter_launcher_icons:
  android: "launcher_icon"
  ios: true
  image_path: "assets/icons/logo/logo.png"
  min_sdk_android: 16

flutter:
  uses-material-design: true

  assets:
    - assets/icons/
    - assets/docs/

  fonts:
    - family: Geologica
      fonts:
        - asset: assets/fonts/Geologica-Black.ttf
        - asset: assets/fonts/Geologica-Bold.ttf
        - asset: assets/fonts/Geologica-ExtraBold.ttf
        - asset: assets/fonts/Geologica-ExtraLight.ttf
        - asset: assets/fonts/Geologica-Light.ttf
        - asset: assets/fonts/Geologica-Medium.ttf
        - asset: assets/fonts/Geologica-Regular.ttf
        - asset: assets/fonts/Geologica-SemiBold.ttf
        - asset: assets/fonts/Geologica-Thin.ttf
abdelaziz-mahdy commented 1 week ago

Weird, did you terminate the app and recompile?

Maybe a flutter clean to be sure all is good

abdelaziz-mahdy commented 1 week ago

Btw

Those are not needed since they are included in the libs before them

media_kit_libs_android_video: ^1.3.6
  media_kit_native_event_loop: ^1.0.8
  media_kit_libs_ios_video: ^1.1.4
Orillio commented 1 week ago

Yep, tried again with flutter clean. Removed unnecessary packages, recompiled. And still, unfortunately same error is thrown.

Orillio commented 1 week ago

@abdelaziz-mahdy Then, tried again with another emulator (Pixel 7 API 33). ensureInitialized still fails, but black screen is now gone. At this point, i dont know what mught be the issue exactly, but maybe your package somehow doesnt support API 34?

abdelaziz-mahdy commented 1 week ago

@abdelaziz-mahdy Then, tried again with another emulator (Pixel 7 API 33). ensureInitialized still fails, but black screen is now gone. At this point, i dont know what mught be the issue exactly, but maybe your package somehow doesnt support API 34?

Well I don't think there should be any problem with API number, but I am not sure

Also these tries with the dependency override? There was a fix I don't think it was released related to the error, this is why I suggested it

abdelaziz-mahdy commented 1 week ago

note please test on a physical device since simulators are not stable.

Orillio commented 1 week ago

Unfortunately, I don’t have physical device on android to test it. But since it worked on another simulator, I guess it should also work on real device. The overrides definitely didn’t help in my case.

Anyways, I appreciate your help

abdelaziz-mahdy commented 1 week ago

Just a question, do you have catch all the exceptions set to be on

In vscode? I think that's the reason for the ensure error

Orillio commented 1 week ago

Yes, they were on. I already figured out that the error is caught on your side. But I’m still frustrated about the reason

abdelaziz-mahdy commented 1 week ago

Yes, they were on. I already figured out that the error is caught on your side. But I’m still frustrated about the reason

The reason for the error? Is that lib are loaded and some are not based on your configuration and device, so we try to load each of them and if it failed it gets ignored

But if none worked it will throw an exception

wutea7 commented 5 days ago

I created an empty project to test this problem and it was still. The test image was Android 14.0 (API 34) arm64-v8a.

The problem seems to only occur on an emulator. It works on my physical device Galaxy S8+ (Android 9.0 API 28).

pubspec.yaml ```yaml name: media_kit_sample description: "A new Flutter project." publish_to: 'none' version: 0.1.0 environment: sdk: '>=3.3.3 <4.0.0' dependencies: flutter: sdk: flutter media_kit: ^1.1.10 media_kit_video: ^1.2.4 media_kit_libs_video: ^1.0.4 dev_dependencies: flutter_test: sdk: flutter flutter_lints: ^3.0.0 flutter: uses-material-design: true assets: - assets/videos/ ```
main.dart ```dart import 'package:flutter/material.dart'; import 'package:media_kit/media_kit.dart'; import 'package:media_kit_video/media_kit_video.dart'; void main() { MediaKit.ensureInitialized(); runApp(const MaterialApp(home: MainApp())); } class MainApp extends StatefulWidget { const MainApp({super.key}); @override State createState() => _MainAppState(); } class _MainAppState extends State { late final player = Player(); @override void initState() { super.initState(); player.open(Media('asset://assets/videos/1.mp4')); } @override void dispose() { player.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Center(child: Video(controller: VideoController(player))); } } ```
console ```bash Launching lib/main.dart on sdk gphone64 arm64 in debug mode... Running Gradle task 'assembleDebug'... ✓ Built build/app/outputs/flutter-apk/app-debug.apk. Installing build/app/outputs/flutter-apk/app-debug.apk... Debug service listening on ws://127.0.0.1:56253/KRX01ossHpc=/ws Syncing files to device sdk gphone64 arm64... D/media_kit(24427): Asset name: flutter_assets/assets/videos/1.mp4 D/media_kit(24427): Asset size: 1769817 D/media_kit(24427): Asset directory: /data/user/0/com.example.media_kit_sample/files/com.alexmercerind.media_kit/ D/media_kit(24427): Asset directory exists. D/media_kit(24427): Asset file: /data/user/0/com.example.media_kit_sample/files/com.alexmercerind.media_kit/flutter_assets_assets_videos_1.mp4 D/media_kit(24427): Asset file exists. I/media_kit(24427): com.alexmercerind.media_kit_video.VideoOutputManager.create: -5476376618711758032 I/media_kit(24427): flutterJNIAPIAvailable = true I/media_kit(24427): com.alexmercerind.media_kit_video.VideoOutput: id = 0 I/flutter (24427): {id: 0} I/flutter (24427): media_kit: AndroidVideoController: Emulator detected. I/flutter (24427): media_kit: AndroidVideoController: Enforcing S/W rendering. I/flutter (24427): media_kit: wakelock: _count = 1 I/media_kit(24427): com.alexmercerind.media_kit_video.VideoOutputManager.createSurface: -5476376618711758032 I/flutter (24427): {wid: 12402} D/edia_kit_sample(24427): PlayerBase::PlayerBase() D/edia_kit_sample(24427): TrackPlayerBase::TrackPlayerBase() I/libOpenSLES(24427): Emulating old channel mask behavior (ignoring positional mask 0x3, using default mask 0x3 based on channel count of 2) D/edia_kit_sample(24427): PlayerBase::stop() from IPlayer D/AudioTrack(24427): stop(72): called with 0 frames delivered E/libOpenSLES(24427): Configuration error: unknown key W/libOpenSLES(24427): Leaving AndroidConfiguration::GetConfiguration (SL_RESULT_PARAMETER_INVALID) I/media_kit(24427): com.alexmercerind.media_kit_video.VideoOutputManager.setSurfaceTextureSize: -5476376618711758032 1280 720 E/EGL_emulation(24427): tid 24522: eglCreateContext(1755): error 0x3004 (EGL_BAD_ATTRIBUTE) E/EGL_emulation(24427): tid 24523: eglCreateContext(1755): error 0x3004 (EGL_BAD_ATTRIBUTE) I/flutter (24427): media_kit: wakelock: _count = 0 D/EGL_emulation(24427): app_time_stats: avg=220.72ms min=2.11ms max=4406.42ms count=21 D/edia_kit_sample(24427): PlayerBase::stop() from IPlayer D/AudioTrack(24427): stop(72): called with 240456 frames delivered ```
abdelaziz-mahdy commented 5 days ago

Emulators are not stable, so as long as the physical device works it's all good

alexmercerind commented 5 days ago

Don't use emulator.

alexmercerind commented 5 days ago

Dont know if its related, but i get this error.

Fix your development environment, don't care about caught exceptions.