just_audio icon indicating copy to clipboard operation
just_audio copied to clipboard

PlatformException(-1102, You do not have permission to access the requested resource., null, null)

Open anirudhrao-github opened this issue 1 year ago • 3 comments

Which API doesn't behave as documented, and how does it misbehave? _player.playbackEventStream.listen((event) {}, onError: (Object e, StackTrace stackTrace) { print('A stream error occurred: $e'); }); On android PlatformException is thrown when the player tries to play the invalid audio file. On iOS, a PlatformException is thrown in the beginning itself, with no clue regarding which url is invalid

Minimal reproduction project Provide a link here using one of two options: The example

To Reproduce (i.e. user steps, not code) Steps to reproduce the behavior:

  1. Make any of the Playlist URL invalid (add typo) on iOS
  2. Restart the app
  3. See error caught in playbackEventStream in the beginning itself even if the first audio is playable.

Error messages

A stream error occurred: PlatformException(-1102, You do not have permission to access the requested resource., null, null)

Expected behavior It should throw exception similar to android when there is an error, and it should only throw it when player tries to play that invalid audio.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: iOS, Android
  • Browser [e.g. chrome, safari + version]

Smartphone (please complete the following information):

  • Device: iPhone 11
  • OS: 15.6

Flutter SDK version

[✓] Flutter (Channel stable, 3.13.6, on macOS 12.5 21G72 darwin-arm64, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.83.1)
[✓] Connected device (4 available)
[✓] Network resources

Additional context The issue replicates in the example_playlist.dart.

anirudhrao-github avatar Oct 19 '23 09:10 anirudhrao-github

I'm seeing a similar issued logged in sentry for my app. These lines are coming up as breaking it.

PlayerException: (-1102) You do not have permission to access the requested resource. File "just_audio.dart", line 869, in AudioPlayer._load File "" File "just_audio.dart", line 1464, in AudioPlayer._setPlatformActive.setPlatform

This is only happening intermittently for me, if I find a pattern I'll post here.

davefaliskie avatar Jan 15 '24 15:01 davefaliskie

I think this would better be submitted as a feature request. What sort of API would you like to be able to find out which item in a playlist caused the error?

ryanheise avatar Feb 29 '24 14:02 ryanheise

I have added an API available on the feature/treadmill branch. As per the README, you can now do this:

player.playbackEventStream.listen((event) {}, onError: (Object e, StackTrace st) {
  if (e is PlatformException) {
    print('AudioSource index: ${e.details?["index"]}');
  } else {
    print('An error occurred: $e');
  }
});

This branch also recognises the useLazyPreparation option on iOS/macOS so that it doesn't attempt to preload all children in a ConcatenatingAudioSource by default. However, it will still preload the "next" child as soon as the current child starts playing which means the error will still be detected earlier than on Android where it waits until the current child's playback is near the end of its duration before preloading the next child. In any case, the exception now allows you to query the index of the audio source in the sequence that is associated with the error.

ryanheise avatar Mar 05 '24 11:03 ryanheise