jhomlala / betterplayer

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

Audio stopping after a few minutes (5-10) on lock screen [BUG] #1035

Open rafaelqcosta opened 2 years ago

rafaelqcosta commented 2 years ago

History check ok.

Describe the bug After a few minutes of listening to the audio with the screen locked, the audio suddenly stops. When unlocking the screen and returning to the app the process is still running. Then it is necessary to pause the video and play again.

To Reproduce

  1. play video
  2. lock sreen
  3. await some minutes (5-10)
  4. See error

*Example code BetterPlayerConfiguration( aspectRatio: 16 / 9, autoPlay: false, startAt: Duration(seconds: widget.lesson?.currentTime?.toInt() ?? 0), deviceOrientationsAfterFullScreen: [ DeviceOrientation.portraitUp, ], handleLifecycle: false, autoDetectFullscreenDeviceOrientation: true, ), betterPlayerDataSource: BetterPlayerDataSource( BetterPlayerDataSourceType.network, widget.lesson?.videoInformation?.files?.last.link ?? '', notificationConfiguration: BetterPlayerNotificationConfiguration( showNotification: true, title: widget.lesson?.title, author: widget.lesson?.courseTrail?.title, imageUrl: IFileStorageRepository.imagePath(widget.lesson?.thumbnailFileUUID ?? ''), ), bufferingConfiguration: BetterPlayerConfig.buffer, cacheConfiguration: BetterPlayerConfig.cache, ), );

and

` class BetterPlayerConfig { static const buffer = BetterPlayerBufferingConfiguration( minBufferMs: 50000, maxBufferMs: 13107200, bufferForPlaybackMs: 2500, bufferForPlaybackAfterRebufferMs: 5000, );

static const cache = BetterPlayerCacheConfiguration( useCache: true, preCacheSize: 10 1024 1024, maxCacheSize: 10 1024 1024, maxCacheFileSize: 10 1024 1024,

///Android only option to use cached video between app sessions
key: "testCacheKey",

); } `

Expected behavior adjust the error

Screenshots it's not necessary

Flutter doctor it's all ok

Better Player version

Smartphone (please complete the following information):

renatolealdev commented 2 years ago

Hello. I'm experiencing the same problem! On Android only.

tuvia commented 2 years ago

Same problem here...

Roee-Tsur commented 1 week ago

Any updates?

tuvia commented 1 week ago

Hi! I didn't get any answer. I ended up changing the plugin. Depending on what you need, there are different options. Best regards!

Roee-Tsur commented 1 week ago

@tuvia Thanks for replying so fast! I want the simplest solution to keep the media playing in the background, how did you solve this issue?

tuvia commented 1 week ago

Check just_audio_background plugin. If you need video, you'll have to work a little bit more. I used fijkplayer with audio_service .I can share my code if you want.

Roee-Tsur commented 1 week ago

Solved by requesting ignore battery optimization permission: Permission.ignoreBatteryOptimizations.request();

And added to the manifest the permissions: android.permission.FOREGROUND_SERVICE, android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS