jhomlala / betterplayer

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

[BUG] OutofMemoryError on latest version #1211

Closed gOzaru closed 1 year ago

gOzaru commented 1 year ago

History check I have check and done all the solution on same bug, but it still didn't work.

Describe the bug My video is 75MB, this is my whole settings on Example code. It always gives error: W/om.sim.optik99(16701): Throwing OutOfMemoryError "Failed to allocate a 65552 byte allocation with 17616 free bytes and 17KB until OOM, target footprint 134217728, growth limit 134217728" (VmSize 1719588 kB)

This is the video url

To Reproduce Steps to reproduce the behavior:

  1. Enable multiDex
  2. Copy the code above
  3. Run it on Android
  4. See error

*Example code

class VideoBetPlayer extends StatefulWidget {
  const VideoBetPlayer({super.key, required this.url, required this.name});
  final String url;
  final String name;
  @override
  State<VideoBetPlayer> createState() => _VideoBetPlayerState();
}

class _VideoBetPlayerState extends State<VideoBetPlayer> {
  late BetterPlayerController _controller;
  late BetterPlayerDataSource _dataSource;
  bool isDownloaded = false;

  @override
  void initState() {
    super.initState();
    BetterPlayerConfiguration betterPlayerConfiguration = const BetterPlayerConfiguration(
      aspectRatio: 16 / 9,
      fit: BoxFit.fitHeight,
      looping: true,
      allowedScreenSleep: false,
      fullScreenByDefault: true,
      autoPlay: true,
    );
    _dataSource = BetterPlayerDataSource.network(
      widget.url,
      liveStream: false,
      cacheConfiguration: const BetterPlayerCacheConfiguration(
        useCache: true,
        preCacheSize: 10 * 1024 * 1024,
        maxCacheSize: 75 * 1024 * 1024,
        maxCacheFileSize: 128 * 1024 * 1024,
        key: "testCacheKey",
      ),
    );
    _controller = BetterPlayerController(betterPlayerConfiguration);
    _controller.setControlsEnabled(false);
    _controller.setControlsAlwaysVisible(false);
    precached();
  }

  Future<void> precached() async {
    await SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft]);
    await _controller.preCache(_dataSource);
    await setup();
  }

  Future<void> setup() async {
    await _controller.setupDataSource(_dataSource);
    setState(() {
      isDownloaded = true;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        color: Colors.black,
        child: Container(
          color: Colors.white,
          child: Stack(
            alignment: Alignment.topCenter,
            children: <Widget>[
              (isDownloaded == false) ? const Loading(128, 2) : BetterPlayer(controller: _controller),
              Close(
                callback: () => Get.off(() => const VideoList()),
                iconColor: Colors.white,
              ),
            ],
          ),
        ),
      ),
    );
  }

Expected behavior It should be running well and not crash.

Screenshots Sorry, just crash and exit the app.

Flutter doctor [√] Flutter (Channel stable, 3.10.0, on Microsoft Windows [Version 10.0.22621.1702], locale id-ID) [√] Windows Version (Installed version of Windows is version 10 or higher) [√] Android toolchain - develop for Android devices (Android SDK version 33.0.2) [√] Chrome - develop for the web [X] Visual Studio - develop for Windows X Visual Studio not installed; this is necessary for Windows development. Download at https://visualstudio.microsoft.com/downloads/. Please install the "Desktop development with C++" workload, including all of its default components [√] Android Studio (version 2021.2) [√] VS Code, 64-bit edition (version 1.78.2) [√] Connected device (4 available) [√] Network resources

Better Player version

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

gOzaru commented 1 year ago

Case closed. The cause is that I forgot to set the targetSdkVersion to 33. Sorry.

gOzaru commented 1 year ago

Hello, the crash still happens. I don't know what the cause. Please help me

gOzaru commented 1 year ago

I changed the precached() to setup() and now, it's okay

    _controller = BetterPlayerController(betterPlayerConfiguration);
    _controller.setControlsEnabled(false);
    _controller.setControlsAlwaysVisible(false);
    setup(); //precached();

We no need to run precached and setup at the same time. Just run setup() is enough.