bluefireteam / audioplayers

A Flutter package to play multiple audio files simultaneously (Android/iOS/web/Linux/Windows/macOS)
https://pub.dartlang.org/packages/audioplayers
MIT License
2.01k stars 845 forks source link

PlatformException(AndroidAudioError, Failed to set source) after upgrading to 6.0.0 #1786

Closed talent-apps closed 7 months ago

talent-apps commented 7 months ago

Checklist

Current bug behaviour

After upgrading to audioplayers: ^6.0.0 we see multiple crashes on the crashlytics dashboard:

Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: PlatformException(AndroidAudioError, Failed to set source. For troubleshooting, see: https://github.com/bluefireteam/audioplayers/blob/main/troubleshooting.md, java.io.FileNotFoundException: /data/user/0/il.talent.winner/cache/dba7d3aa-99e7-46e8-b999-a065848e9f93/sounds/example.mp3: open failed: ENOENT (No such file or directory)
    at libcore.io.IoBridge.open(IoBridge.java:574)
    at java.io.FileInputStream.<init>(FileInputStream.java:160)
    at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1209)
    at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1187)
    at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1152)
    at xyz.luan.audioplayers.source.UrlSource.setForMediaPlayer(Unknown Source:7)
    at xyz.luan.audioplayers.player.MediaPlayerPlayer.setSource(Unknown Source:10)
    at xyz.luan.audioplayers.player.WrappedPlayer.setSource(Unknown Source:15)
    at xyz.luan.audioplayers.AudioplayersPlugin.methodHandler(Unknown Source:550)
    at xyz.luan.audioplayers.AudioplayersPlugin.access$methodHandler(Unknown Source:0)
    at xyz.luan.audioplayers.AudioplayersPlugin$onAttachedToEngine$1$1.invoke(Unknown Source:14)
    at xyz.luan.audioplayers.AudioplayersPlugin$onAttachedToEngine$1$1.invoke(Unknown Source:4)
    at xyz.luan.audioplayers.AudioplayersPlugin.safeCall(Unknown Source:0)
    at xyz.luan.audioplayers.AudioplayersPlugin.onAttachedToEngine$lambda$0(Unknown Source:20)
    at xyz.luan.audioplayers.AudioplayersPlugin.a(Unknown Source:0)
    at xyz.luan.audioplayers.b.onMethodCall(Unknown Source:2)
    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(Unknown Source:17)
    at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(Unknown Source:18)
    at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0(Unknown Source:41)
    at io.flutter.embedding.engine.dart.DartMessenger.a(Unknown Source:0)
    at io.flutter.embedding.engine.dart.a.run(Unknown Source:12)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at<truncated: 792 chars>

The crashes occur on multiple devices, for example Galaxy A03 Core, Galaxy A13, Redmi 9A.

Expected behaviour

No crash

Code sample

Code sample ```dart static void playApplauseSound() { AudioPlayer() ..setAudioContext( AudioContext( android: const AudioContextAndroid(audioFocus: AndroidAudioFocus.gainTransientMayDuck), iOS: AudioContextIOS(options: const {AVAudioSessionOptions.duckOthers}), ), ) ..play(AssetSource('sounds/example.mp3')); } ```

Affected platforms

Android

Platform details

No response

AudioPlayers Version

6.0.0

sandeep-kadyangc1 commented 7 months ago

yes thats happening

Gustl22 commented 7 months ago

Does this also happen, if you await setAudioContext and then play?

talent-apps commented 7 months ago

@Gustl22 That seems to resolve the issue. Thanks.

sandeep-kadyangc1 commented 7 months ago

no still happening after setting setAudioContext PlatformException(DarwinAudioError, Failed to set source. For troubleshooting, see https://github.com/bluefireteam/audioplayers/blob/main/troubleshooting.md, AVPlayerItem.Status.failed on setSourceUrl: Unknown error, null)<…> [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(DarwinAudioError, Failed to set source. For troubleshooting, see https://github.com/bluefireteam/audioplayers/blob/main/troubleshooting.md, AVPlayerItem.Status.failed on setSourceUrl: Unknown error, null)

its working fine in android issue comes in iOS

Gustl22 commented 7 months ago

@sandeep-kadyangc1 then its probably another issue. Can you open a full bug report please?

sandeep-kadyangc1 commented 7 months ago

that solved.. it was problem with my simulator