0.3 C
New York
Thursday, February 6, 2025

ios – AudioPlayer stops working after app in background for lengthy interval


Atmosphere

just_audio: ^0.9.42
riverpod: ^2.6.1
flutter_riverpod: ^2.4.10
riverpod_annotation: ^2.3.4

Dev:
riverpod_generator: ^2.3.11

Platform: iOS
Flutter model: 3.27.2
Gadget: iPhone 12 Professional Max - 18.1.1

Supplier Setup

@Riverpod(keepAlive: true)
AudioPlayer audioPlayer(AudioPlayerRef ref) {
  remaining audioPlayer = AudioPlayer(
    userAgent:
        'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0',
  );
  ref.onDispose(() async => await audioPlayer.dispose());
  return audioPlayer;
}

Steps to Reproduce

  1. Open app and play audio efficiently
  2. Press residence button to place app in background (not killing the app)
  3. Use different apps, lock display screen, depart machine idle
  4. After a number of hours (e.g. in a single day)
  5. Return to app from background
  6. Attempt to play audio

Present Habits

  • Audio will not play after returning to app
  • No error messages
  • Solely mounted by utterly killing and reopening the app

Anticipated Habits

  • Audio ought to proceed to work when returning to app from background
  • Since supplier is marked with keepAlive: true, the occasion ought to persist

Speculation

There are two potential eventualities:

  1. Riverpod Supplier Challenge:

    • Regardless of keepAlive: true, the supplier is likely to be disposing the occasion
    • Nonetheless, this appears unlikely as Riverpod documentation states keepAlive suppliers ought to solely dispose when app is killed
  2. just_audio Challenge:

    • The AudioPlayer occasion is likely to be self-disposing or releasing sources after lengthy intervals in background
    • The supplier stays alive however holds an invalid AudioPlayer occasion

Questions

  1. Is it potential for just_audio to launch sources routinely when app is in background for lengthy intervals?
  2. Are there any identified points with keepAlive suppliers in comparable eventualities?
  3. What can be the really useful strategy to deal with audio playback that should survive lengthy background intervals?

Extra Context

  • Challenge solely happens after prolonged background intervals (hours)
  • Quick background intervals (half-hour) work tremendous

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles