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] AVPlayer internal request error with custom url #1375

Open
gileadeteixeira opened this issue Dec 9, 2024 · 0 comments
Open

[iOS] AVPlayer internal request error with custom url #1375

gileadeteixeira opened this issue Dec 9, 2024 · 0 comments
Assignees
Labels
1 backlog bug Something isn't working

Comments

@gileadeteixeira
Copy link

Which API doesn't behave as documented, and how does it misbehave?
I'm working on a project that uses the just_audio package, but with the following requirements:

  • The audio file is encrypted;

  • The audio needs to be played as a stream of bytes.

I tried to manually implement a StreamAudioSource, but it didn't work out very well, so I decided to adapt the LockCachingAudioSource class (I renamed it CustomAudioSource), with an additional parameter to inform the decryptor to be used when downloading bytes. My idea is to use it as follows: setAudioSource(CustomAudioSource(url: "https://encrypted.mp3.aes", decrypter: ...)). Doing it this way works perfectly on Android, but on iOS the player "doesn't play". I spent a lot of time trying to understand the behavior, and I noticed the following:

  • The download and decryption work perfectly. I can even play the generated file on other audio players on my computer, for example;

  • If I use AudioSource.file, passing the path of the generated file, the iOS player works perfectly;

  • The player only gives an error with my url "https://encrypted.mp3.aes". Any other "normal" audio url (a free sample from a test site, for example) works perfectly;

In the end, I ended up stuck with AVPlayer (which is used under the hood in just_audio). From what I understand, it requests some initial bytes of my encrypted url to decide if it can play the entire file, but this ends up breaking the entire execution of setAudioSource.
I would like to solve this problem inside my CustomAudioSource class (to avoid a fork of just_audio), but I've run out of ideas. Do you have any suggestions?

(sorry for any English mistakes, I'm using Translator)

Minimal reproduction project
https://github.com/gileadeteixeira/encrypted_audio_source
(ignore README. it was created while I was testing the first version with my own version of StreamAudioSource.)

To Reproduce (i.e. user steps, not code)
run example
see errors

Error messages

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: (-11828) Cannot Open
#0      AudioPlayer._load (package:just_audio/just_audio.dart:874:9)
<asynchronous suspension>
#1      AudioPlayer._setPlatformActive.setPlatform (package:just_audio/just_audio.dart:1498:28)
<asynchronous suspension>

Expected behavior
The player is expected to... play.
I imagined that, since it is a StreamAudioSource, just the decrypted bytes stream would be enough to use in the player's playback. However, the source URL is passed internally to AVPlayer, and, consequently, breaks the entire playback.

Screenshots
All from example/lib/main:
image

Switch between sources. Encrypted fails, "normal" works fine (without decrypter generator, obviously).
image

Desktop (please complete the following information):

  • OS: MacOS Sonoma 14.5

Smartphone (please complete the following information):
Android [Success]

  • Device: (Simulator) Pixel 3a
  • OS: Android 14

iOS [Error]

  • Device: (Simulator) iPhone 15 Pro Max
  • OS: iOS 17.5

Flutter SDK version

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.22.3, on macOS 14.5 23F79 darwin-arm64, locale pt-BR)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.1)
[✓] VS Code (version 1.95.3)
[✓] Network resources

• No issues found!

Additional context
Not found any.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 backlog bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants