ryanheise / audio_service

Flutter plugin to play audio in the background while the screen is off.
806 stars 480 forks source link

Warning from iOS app: [NowPlaying] [MRNowPlaying] Ignoring setPlaybackState because application does not contain entitlement com.apple.mediaremote.set-playback-state for platform #915

Open thecodinglinguist opened 2 years ago

thecodinglinguist commented 2 years ago

Documented behavior

Not part of the documentation

Actual behavior

Warning logs when interacting with player pause/play.

Runtime error

[NowPlaying] [MRNowPlaying] Ignoring setPlaybackState because application does not contain entitlement com.apple.mediaremote.set-playback-state for platform

Minimal reproduction project

Official example: main.dart

Reproduction steps

  1. Click Play
  2. Click Pause

The entitlement warning will appear with each click.

Output of flutter doctor


[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] VS Code (version 1.64.2)
[✓] Connected device (3 available)```
### Devices exhibiting the bug
Device: iPad Pro (10.5-inch) OS: 15.3.1
Device: iPhone 6s OS: 15.2.1
Yousuf-M-Hammad commented 2 years ago

Anyone got anything on this issue by now ?

ryanheise commented 2 years ago

I think there is a pull request addressing this, I'll check when I'm back at my computer. But from memory the solution in that pull request didn't produce the desired behaviour even though it got rid of the warning.

Colton127 commented 2 years ago

I was getting this error, and the control center wasn't appearing on a real iOS device, only simulator. I thought the two were related. However, I simply had to use audio_session to configure the session for music

session.configure(AudioSessionConfiguration.music());

After doing this, the controls appeared within iOS media center and lock screen fine.

Given this, does anybody know what the implications of this error are?

ryanheise commented 2 years ago

Thanks @Colton127 for sharing that audio_session resolves the issue.

Regarding the error/warning, it has been discussed on the following pull request: #900 . Contributions welcome.

mem3Dealer commented 1 year ago

@Colton127's solution did not work for me. Facing same issue on iOS when seeking new position in track.

leonidlist commented 1 year ago

Having the same issue for play/pause and skipToNext/skipToPrevious

[NowPlaying] [MRNowPlaying] Ignoring setPlaybackState because application does not contain entitlement com.apple.mediaremote.set-playback-state for platform

mhassan772 commented 1 year ago

same here @leonidlist . Did you find a solution?

shahmirzali49 commented 1 year ago

@ryanheise any update? https://github.com/ryanheise/just_audio/issues/1001

zeddyyz commented 1 year ago

I'm also experiencing this warning message while using a physical iOS device plugged in to my Macbook

enedrio commented 1 year ago

Same here, how can we help?

EXEIdeas commented 1 year ago

Same Here. Any Solution So Far...??? I am using this: https://pub.dev/packages/just_audio_background

sudo-ulmas commented 1 year ago

Same here using audio_session combined with audioplayers

anatoliisudor commented 1 year ago

UPDATE: kinda false alarm here. Issue can be solved one time only, and for the second audio playback and sesion configuration it's still there. Any help appreciated. And even calling await session?.setActive(false); method before configuring audio session does not help.

I was facing the same issue and fixed it by leaving only ONE option to configure audio_session. Didn't figure it out to the end, but looks like it was some options that conflict as described here.

Full error log from Flutter was:

[as_client]     AVAudioSession_iOS.mm:2386  Failed to set category, error: -50
Error Domain=NSOSStatusErrorDomain Code=-50 "(null)"
[NowPlaying] [MRNowPlaying] Ignoring setPlaybackState because application does not contain entitlement com.apple.mediaremote.set-playback-state for platform

The final code that works was:

    try {
      await _session?.configure(
        AudioSessionConfiguration(
          avAudioSessionCategory: AVAudioSessionCategory.playback,
          // The following lines was commented as they produced an error
          // avAudioSessionRouteSharingPolicy:
          //     AVAudioSessionRouteSharingPolicy.defaultPolicy,
          // avAudioSessionCategoryOptions:
          //     AVAudioSessionCategoryOptions.duckOthers,
          // avAudioSessionMode: AVAudioSessionMode.defaultMode,
          // avAudioSessionSetActiveOptions: AVAudioSessionSetActiveOptions.none,
          androidAudioAttributes: const AndroidAudioAttributes(
            contentType: AndroidAudioContentType.movie,
            flags: AndroidAudioFlags.none,
            usage: AndroidAudioUsage.media,
          ),
          androidAudioFocusGainType:
              AndroidAudioFocusGainType.gainTransientMayDuck,
          androidWillPauseWhenDucked: isAndroidWillPauseWhenDucked,
        ),
      );

      session?.setActive(true);
    } on PlatformException catch (e) {
      debugPrint('AUDIO MANAGER AUDIOSESSION CONFIGURE ERROR: ${e.toString()}');
    }

It STILL generates an error in logs, but at least it works now in the real app and not only in the emulator.

I was using audio_service 0.18.12 and upgrading it to actual from 0.18.9 didn't solve the problem.

MaxenceChantome commented 1 year ago

I am facing the same issue, did someone find a workaround?

serhii-k commented 1 year ago

Hello @ryanheise Sorry, I don't have any understanding of the iOS implementation. But there seems to be a possible solution from JonMercer in this thread. He suggests not to assign the MPNowPlayingInfoCenter.default().playbackState on iOS because this property only applies to macOS. Here's the assignment in audio_service: https://github.com/ryanheise/audio_service/blob/544e2f8d2d28203a74d3cbda709889b3c9cce1a2/audio_service/darwin/Classes/AudioServicePlugin.m#L292C8-L292C8 Can you please consider if it's a viable solution for this issue? Thank you.

jhonatan-3a commented 1 year ago

@ryanheise hey bro, do you have any time to check this ? greatlu appreaciated

ryanheise commented 1 year ago

There's a pr in #900 but it needs some changes as described in the discussion on that page, if someone would like to help. It would make a good first issue for a new contributor.

As it is, the warning itself should not actually cause problems but it would be nice to clean it up.

jhonatan-3a commented 1 year ago

thanks for the response but actually my issue is this one MSVEntitlementUtilities - Process Harmonie PID[28383] - Group: (null) - Entitlement: com.apple.mediaremote.external-artwork-validation - Entitled: NO - Error: (null) i am also using just audio background and just audio, and this seems to be only happening on ipad, do you know anuything about this error ?

ryanheise commented 1 year ago

I'm sorry, I didn't realise you were posting an off topic comment. I will hide your comment and my comment as off topic. Please keep this in mind for future comments.