ukasz123 / soundpool

Soundpool plugin for Flutter
87 stars 64 forks source link

App crashing in iOS device when playing audio #29

Open Ccastillo06 opened 4 years ago

Ccastillo06 commented 4 years ago

Hello,

I've been using the package in my Android app with no issues, but we are now developing the iOS version and adapting the Flutter code to work in both OS.

The issue I found is that the app literally crashes and just shows the next message whenever we play audio: Lost connection to device

I tried recreating the issue in a new Flutter project and it happens too whenever I play audio from an url using pool.loadAndPlayUri(uri); where uri is a valid string and plays properly in Android.

I opened the issue just to communicate the problem and ask if there is some special permission needed in iOS to play the audio from url using this package. We are using a physical iPhone 6 and the software version is 12.4.5. Happens also when running the iOS simulator with an iPhone 11.

Thanks in advance!

ukasz123 commented 4 years ago

Hi, @Ccastillo06

Can you check if you have similar issues when using example project from this repository? If yes, then check the Console output for iPhone device/simulator. That may help a lot. App crashing immediately disconnects from debugger - that is the reason for Lost connection to device message.

Ccastillo06 commented 4 years ago

I just tested the example contained in the repo and tried replicating in a new project again. It works for iPhone as far as the audio file is not in AWS.

In the example, the audio file is in Github and it loads nice, but the moment I load an AWS url using any .mp3 file, it keeps working fine for Android but no for iOS. I tried storing the audio file in a public AWS S3 Bucket and still have the problem.

I also tried using flutter run --verbose and these are the logs related to the error I had:

[+3177 ms] Service protocol connection closed.
[        ] Lost connection to device.

No more info related to the error. I'm sorry I can't provide more data than this, but flutter is not giving more information.

ukasz123 commented 4 years ago

You should try to open the iOS subproject in Xcode, run it and check what would be printed there. I hope you'd find something useful in the crashlog. Also I was told that since iOS 9 all the network connections have to be done over secure protocols like HTTPS. Please, check your url if it uses HTTPS and not HTTP.

nezoat commented 4 years ago

Hardware Model: iPhone10,4 Process: Runner [5005] AppVariant: 1:iPhone10,4:13 Code Type: ARM-64 (Native) Role: Foreground Parent Process: launchd [1] Date/Time: 2020-06-11 10:22:14.1048 -0500 Launch Time: 2020-06-11 10:21:17.6765 -0500 OS Version: iPhone OS 13.5.1 (17F80) Release Type: User Baseband Version: 3.05.00 Report Version: 104

Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Subtype: KERN_INVALID_ADDRESS at 0x000000002b8a9b40 VM Region Info: 0x2b8a9b40 is not in any region. Bytes before following region: 3608782016 REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL UNUSED SPACE AT START --->
__TEXT 0000000102a44000-0000000102a4c000 [ 32K] r-x/r-x SM=COW ...er.app/Runner

Termination Signal: Segmentation fault: 11 Termination Reason: Namespace SIGNAL, Code 0xb Terminating Process: exc handler [5005] Triggered by Thread: 0

Thread 0 name: Thread 0 Crashed: 0 libobjc.A.dylib 0x000000018cc0a980 objcretain + 16 (objc-object.h:459) 1 soundpool 0x0000000104565594 specialized SwiftSoundpoolPlugin.SoundpoolWrapper.handle(:result:) + 6924 (SwiftSoundpoolPlugin.swift:111) 2 soundpool 0x0000000104566efc specialized SwiftSoundpoolPlugin.handle(:result:) + 2420 (:0) 3 soundpool 0x000000010455e61c @objc SwiftSoundpoolPlugin.handle(:result:) + 76 (:0) 4 Flutter 0x0000000103936e18 0x1038a4000 + 601624 5 Flutter 0x00000001038d0c88 0x1038a4000 + 183432 6 Flutter 0x0000000103927398 0x1038a4000 + 537496 7 Flutter 0x00000001038e0b68 0x1038a4000 + 248680 8 Flutter 0x00000001038e27e0 0x1038a4000 + 255968 9 CoreFoundation 0x000000018ce4c274 CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION + 28 (CFRunLoop.c:1766) 10 CoreFoundation 0x000000018ce4bf90 CFRunLoopDoTimer + 880 (CFRunLoop.c:2357) 11 CoreFoundation 0x000000018ce4b66c CFRunLoopDoTimers + 276 (CFRunLoop.c:2512) 12 CoreFoundation 0x000000018ce4667c __CFRunLoopRun + 1640 (CFRunLoop.c:0) 13 CoreFoundation 0x000000018ce45ce8 CFRunLoopRunSpecific + 424 (CFRunLoop.c:3192) 14 GraphicsServices 0x0000000196f9038c GSEventRunModal + 160 (GSEvent.c:2246) 15 UIKitCore 0x0000000190f74444 UIApplicationMain + 1932 (UIApplication.m:4823) 16 Runner 0x0000000102a4c288 main + 64 (AppDelegate.swift:7) 17 libdyld.dylib 0x000000018cccd8f0 start + 4

ukasz123 commented 4 years ago

@nezoat Can you answer following questions?

nezoat commented 4 years ago

It doesn't happen every time it. It's crashed 7 times, affecting 3 out of about 20 test users so a fairly high crash rate.

Plugin version 1.1.1

I can't reproduce the crash, but this is the code that is used (unrelated things removed):

if (_audioPlayer == null) { _audioPlayer = Soundpool(streamType: StreamType.notification); } final data = await rootBundle.load("assets/sounds/$soundName.mp4"); if (preloadOnly) { soundId = await _audioPlayer.load(data); } else { soundId = await _audioPlayer.loadAndPlay(data); }

StephanieGitHub commented 4 years ago

I have same problem, no any error message, just crash。plugin version 1.1.1 the play code is:


        asset = await rootBundle.load("assets/audio/alarm1.mp3");

        _alarmSound = await _soundpool.load(asset);

        _alarmSoundStreamId = await _soundpool.play(_alarmSound);

the stop code is :

 if(_alarmSoundStreamId!=null){ 

          await _soundpool.stop(_alarmSoundStreamId);

          _alarmSoundStreamId = null;

 }
ukasz123 commented 3 years ago

@nezoat I think this may be caused because you are using wrong soundIds. It seems there was no audio registered with the soundId OR soundId returned from load() was an error value of -1. I see the documentation is not clear enough about that -1 from load indicates error.