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 #1374

Closed
gileadeteixeira opened this issue Dec 9, 2024 · 3 comments
Closed

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

gileadeteixeira opened this issue Dec 9, 2024 · 3 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.)

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!
Copy link

github-actions bot commented Dec 9, 2024

Oops, it appears that your issue did not follow the template and is missing one or more required sections. Please open a new issue, and provide all required sections and information.

FAQ:

  1. Do I really need to submit a minimal reproduction project for a bug? A: Yes. I prioritise bugs secondarily on how many people are affected, and primarily on whether the bug report is complete, in the sense that it enables me to immediately reproduce it and start working on a fix. If a bug is important to you, the best thing you can do is to provide all requested information ASAP so that I can start looking into it ASAP.

  2. I think I supplied all required information, so did the bot make a mistake? A: The bot only checks the section headings, so when you post a new issue, make sure you leave the section headings intact. (Note that because of this, it is even possible to trick the bot by including only the section headings, and then not providing the requested information under each heading. This is frowned upon, and the issue will be closed manually.)

@github-actions github-actions bot closed this as completed Dec 9, 2024
@gileadeteixeira
Copy link
Author

@ryanheise I have provided all the relevant information to be able to reproduce the problem, could you please check?

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs, or use StackOverflow if you need help with just_audio.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 backlog bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants