Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS 16: fix playback for podcasts with a single channel + Spatial Audio enabled #213

Conversation

leandroalonso
Copy link
Member

@leandroalonso leandroalonso commented Sep 6, 2022

Fixes #62

iOS 16 seems not to like the combination of mono audio (single channel) and Spatial Audio enabled. When those two conditions are met and EffectsPlayer is used the audio just doesn't work.

This seems to be an issue on Apple's side, but given they might not fix it by the time iOS 16 is released, it is good to handle it on our app.

The change works in this way: if the user is on iOS 16 and the user is playing a file with one single channel, we convert the buffer to 2 channels to avoid this issue.

To test

There are a few ways to test this PR, by manually adding your own files and by testing with podcasts. But before testing, make sure that:

  1. You're using a real device with iOS 16
  2. You're using an AirPods Pro/Max or any other device with Spatial Audio capabilities
  3. Enable Spatial Audio: when playing audio on Pocket Casts, swipe down to access the control center, tap the audio bar and hold, tap "Spatialize Stereo", choose "Fixed" or "Head Tracked"

All done? Let's go.

Testing with a podcast

  1. Search for the podcast "The Rizzuto Show"
  2. Download any episode
  3. Wait for the download to finish
  4. Play it
  5. ✅ Make sure the podcast play correctly

Testing with audio files

You can use your own audio files with one or two audio channels, or you can download some here: https://espressif-docs.readthedocs-hosted.com/projects/esp-adf/en/latest/design-guide/audio-samples.html

  1. Add a file that has two-channel audio
  2. Play it
  3. ✅ The audio file should play correctly
  4. Add a file with a single-channel audio
  5. Play it
  6. ✅ The audio file should play correctly

Checklist

  • I have considered if this change warrants user-facing release notes and have added them to CHANGELOG.md if necessary.
  • I have considered adding unit tests for my changes.
  • I have updated (or requested that someone edit) the spreadsheet to reflect any new or changed analytics.

@leandroalonso leandroalonso added [Type] Bug Used for issues where something is not functioning as intended. [Area] iOS 16 labels Sep 6, 2022
@leandroalonso leandroalonso added this to the 7.22 ❄️ milestone Sep 6, 2022
@leandroalonso leandroalonso requested a review from a team as a code owner September 6, 2022 20:38
Copy link
Contributor

@emilylaguna emilylaguna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, 👏 👏 bravo, very nice fix. I tested using my own mono audio files and the test podcast and reproduced the issue then switched to the branch and all is working now.

I left a comment about using some force unwrapping and whether we need to do it.

// In order to prevent this issue, we convert a mono buffer to stereo buffer
// For more info, see: https://github.com/Automattic/pocket-casts-ios/issues/62
var audioBuffer: BufferedAudio
if #available(iOS 16, *), audioPCMBuffer!.audioBufferList.pointee.mNumberBuffers == 1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

audioPCMBuffer!.audioBufferList.pointee.mNumberBuffers

Do we need to force unwrap here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ops, we don't. Removed in 1a5cb6b

Copy link
Contributor

@emilylaguna emilylaguna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! :shipit:

@leandroalonso leandroalonso merged commit fd8206a into release/7.22 Sep 7, 2022
@leandroalonso leandroalonso deleted the issue/62-fix-podcast-playback-when-spatial-audio-is-enabled branch September 7, 2022 16:20
leandroalonso added a commit that referenced this pull request Sep 19, 2022
…-when-spatial-audio-is-enabled

iOS 16: fix playback for podcasts with a single channel + Spatial Audio enabled
leandroalonso added a commit that referenced this pull request Sep 19, 2022
…-when-spatial-audio-is-enabled

iOS 16: fix playback for podcasts with a single channel + Spatial Audio enabled
@leandroalonso leandroalonso mentioned this pull request Jun 12, 2024
3 tasks
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Area] iOS 16 [Type] Bug Used for issues where something is not functioning as intended.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants