Author Topic: BASS for iOS (iPhone/iPad)  (Read 661140 times)

pgruebele

  • Posts: 62
Re: BASS for iOS (iPhone/iPad)
« Reply #1325 on: 24 Oct '19 - 16:18 »
When I check it here, Instruments shows the HALB_IOThread thread getting terminated when BASS_Pause or BASS_Stop is called (and a new one is created when BASS_Start is called). Is that definitely not happening there? If so, what does BASS_IsStarted return after calling BASS_Pause or BASS_Stop? Is that 4.5% battery drain with or without calling BASS_Pause or BASS_Stop? For comparison, what battery drain do you see when you do the opposite?

HALB_IOThread does indeed terminate when BASS_Pause is called.  I really don't understand why it was not being terminated in my previous tests.  I apologize for misreporting this.  VS 2019 + Xamarin.iOS builds and deploys are very buggy and my only explanation is that my app was not getting deployed properly during my tests...

elan

  • Posts: 33
Re: BASS for iOS (iPhone/iPad)
« Reply #1326 on: 28 Oct '19 - 16:35 »
I just wanted to resolve some confusion around audio session management (for a music playback app, which of course wants to use the Control Center):

- Is the application expected to call AVAudioSession setActive YES/NO?
- Is the application expected to call BASS_Pause/Start when music pauses or stops (and if so, in both cases)?

Both of these things appear to tie into when the app can be suspended; e.g. if AVAudioSession isn't deactivated, the app doesn't appear to be suspended by the OS. If BASS_Pause isn't called then setting the audio session as inactive appears to fail with AVAudioSessionErrorCodeIsBusy.

Last, but not least, you made a reference over here http://www.un4seen.com/forum/?topic=17967.msg126233#msg126233 about retrying the restart. If we're manually calling BASS_Start do we need to loop that too with a delay in case of failure?

Many thanks!

Ian @ un4seen

  • Administrator
  • Posts: 22253
Re: BASS for iOS (iPhone/iPad)
« Reply #1327 on: 28 Oct '19 - 17:59 »
BASS activates and deactivates the session for interruptions itself, even when BASS_CONFIG_IOS_NOCATEGORY is enabled, so it shouldn't be necessary for you to do that. You can still use BASS_Stop/Pause to stop the output when nothing is playing (and BASS_Start to resume it) to save some battery. If you don't stop the output when nothing is playing, BASS will tell iOS that the output contains silence so that it can bypass additional processing and save some battery, but perhaps not as much.

Ian @ un4seen

  • Administrator
  • Posts: 22253
Re: BASS for iOS (iPhone/iPad)
« Reply #1328 on: 17 Dec '19 - 17:10 »
The iOS version of the BASS 2.4.15 release is up now in the 1st post. Note support for the armv6 architecture has been removed (it was dropped by Apple a long time ago).

elan

  • Posts: 33
Re: BASS for iOS (iPhone/iPad)
« Reply #1329 on: 23 Dec '19 - 05:15 »
Ian, I have a quick question about BASS_CONFIG_IOS_NOTIFY for interrupt notifications. In recent iOS versions, they added a super confusing AVAudioSessionInterruptionWasSuspendedKey option, which essentially means they're telling you that you _WERE_ interrupted, not that you _ARE_ interrupted.

I think it's possible the BASS code isn't handling this, because I'm seeing the callback get called telling me things got interrupted (and treating them internally as though they were) in this case (I set a separate observer to compare).

This leads to incorrect behavior, as the app behaves as if things were interrupted when it's really not.

My code to deal with this looks something like this, but as we've discussed before, it's not a good idea to double up the handling of interrupts between BASS and user code (right?)

Code: [Select]
  BOOL wasSuspended = notification.userInfo[AVAudioSessionInterruptionWasSuspendedKey] ? [notification.userInfo[AVAudioSessionInterruptionWasSuspendedKey] boolValue] : false;

  if (interruptionType == AVAudioSessionInterruptionTypeBegan)
  {
    // Let the audio player know, but only if it wasn't a confusing "was suspended" variant,
    // c.f. https://developer.apple.com/documentation/avfoundation/avaudiosessioninterruptionnotification
    //
    if (!wasSuspended)
      ; // handle
  }


Ian @ un4seen

  • Administrator
  • Posts: 22253
Re: BASS for iOS (iPhone/iPad)
« Reply #1330 on: 23 Dec '19 - 16:21 »
I'll look into this. Is the issue that BASS is pausing its output when the interruption notification with AVAudioSessionInterruptionWasSuspendedKey is received, and it shouldn't be? If so, does calling BASS_Start in your own BASS_CONFIG_IOS_NOTIFY based interruption handler then fix the problem?

The BASS_CONFIG_IOS_NOTIFY option isn't really needed these days (since iOS 6), as apps are able to register for their own interruption notifications directly from iOS now, but you should use BASS_CONFIG_IOS_NOTIFY for the BASS_Start test above because it's guaranteed to be called after BASS has done its interruption handling.

elan

  • Posts: 33
Re: BASS for iOS (iPhone/iPad)
« Reply #1331 on: 23 Dec '19 - 21:44 »
Is the issue that BASS is pausing its output when the interruption notification with AVAudioSessionInterruptionWasSuspendedKey is received, and it shouldn't be?

Yes, that seems to be exactly the case.

If so, does calling BASS_Start in your own BASS_CONFIG_IOS_NOTIFY based interruption handler then fix the problem?

It doesn't seem to, no, and even if it did, we wouldn't be able to distinguish the "false" background interrupt from a real one, right? Because I think we'd only want to call BASS_Start during a fake one.

The timeline is:

1. Start app, init BASS, audio is paused, BASS is paused.
2. Put the app in the background
3. Try to resume playback from lock screen control center.
4. App starts up BASS and usually a fraction of a second of audio is heard, before...
5. BASS interrupt handler is called (falsely, because iOS is just like "hey, FYI i suspended you") and stops BASS. This is the main issue.
6. Even if I call BASS_Start here, it doesn't seem to make a difference (audio won't resume).

The BASS_CONFIG_IOS_NOTIFY option isn't really needed these days (since iOS 6), as apps are able to register for their own interruption notifications directly from iOS now, but you should use BASS_CONFIG_IOS_NOTIFY for the BASS_Start test above because it's guaranteed to be called after BASS has done its interruption handling.

I'm happy either way (BASS or our app handling it), but I think the issue is that with this bug, you can't disable BASS interrupt handling, right?

Let me know if you need more data or want me to try a build.

Ian @ un4seen

  • Administrator
  • Posts: 22253
Re: BASS for iOS (iPhone/iPad)
« Reply #1332 on: 3 Jan '20 - 12:54 »
A BASS update (2.4.15.1) is up in the 1st post to fix a bug that could result in the output being stopped and not resuming when BASS_CONFIG_DEV_NONSTOP is set to 0 on iOS (other platforms are unaffected).

Ashazy1234

  • Posts: 1
Re: BASS for iOS (iPhone/iPad)
« Reply #1333 on: 5 Jan '20 - 21:59 »
Thanks for posting this.Specifically the links.