Closed alnitak closed 1 week ago
can you check if it grabs the state changes on iOS? For example when you put the app in the background or when the app is back in the foreground or maybe when a call is incoming while flutter_soloud is playing something, you should see a Log.fine() message (Audio engine state changed: [event]). This is out of scope of the PR, but I have added it while adding the others for simplicity. Thank you!
I don't get any message when putting the app into background or foreground on iOS. I do get other logs, for example:
flutter: flutter_soloud.FlutterSoLoudFfi: VOICE ENDED EVENT handle: 1
flutter: flutter_soloud.SoLoud: Voice ended event received. Removing handle 1
flutter: flutter_soloud.SoLoud: Voice ended event received. Removing handle 1
flutter: flutter_soloud.SoLoud: Voice ended event received. Removing handle 1
flutter: _PlaySoundWidgetState: Received StreamSoundEvent SoundEventType.handleIsNoMoreValid
flutter: flutter_soloud.FlutterSoLoudFfi: VOICE ENDED EVENT handle: 4098
flutter: flutter_soloud.SoLoud: Voice ended event received. Removing handle 4098
flutter: flutter_soloud.SoLoud: Voice ended event received. Removing handle 4098
flutter: _PlaySoundWidgetState: Received StreamSoundEvent SoundEventType.handleIsNoMoreValid
flutter: flutter_soloud.FlutterSoLoudFfi: VOICE ENDED EVENT handle: 8195
flutter: flutter_soloud.SoLoud: Voice ended event received. Removing handle 8195
flutter: _PlaySoundWidgetState: Received StreamSoundEvent SoundEventType.handleIsNoMoreValid
flutter: _PlaySoundWidgetState: Received StreamSoundEvent SoundEventType.soundDisposed
FWIW, audio works.
I haven't dug into the code at all yet (let me know when you want me to), but a few points:
initialized
. It's useful to be able to await
this in places where you're not initializing._loader
, I think it's worth it. Most devs will want to play assets, and without the loader, that functionality is impossible. As a developer, you want to make sure that the audio can actually play (i.e. it throws if there's no place for the loader to clone the asset files to). There are also no reasons I can think of to peruse the audio engine after init() but before loader is ready.FutureOr<...>
? I don't know. If we do make async-to-sync changes, we have to go to 3.0.0 according to semver. Which is fine, I guess, but might remove some of the goodwill of developers. (Most prefer their engines stable.)Just to be clear: I'm really glad for all this work. Having the engine work as synchronously as possible, and possibly getting web support as a bonus, sounds fantastic. Just trying to be cognizant of our users' time and focus.
Should I be test-driving this version of flutter_soloud
now? Or should I still wait?
Should I be test-driving this version of flutter_soloud now? Or should I still wait?
Yes please, whenever you have the time. No hurry. I still continue to do some testing and research. Seems to do its job for now.
FWIW, audio works.
🥳
I don't think it's a good idea to make changes such as deprecating initialized. It's useful to be able to await this in places where you're not initializing.
initialized
getter was using the _initializeCompleter
which is no longer used. The latter was used to wait for the audio Isolate and the looping to be started and now they do not exist anymore.
Now it just checks natively if the engine is initialized. The await needed for the initialization is now delegated only to the init()
method. I wouldn't know how to do it otherwise with initialized
getter.
I will see if it is feasible to use FutureOr
, but I agree on not making API changes!
Ok, here's the output of running integration tests on iOS:
I do see some errors, namely:
flutter: [FINE] flutter_soloud.FlutterSoLoudFfi: FILE LOADED EVENT error: 0 hash:
flutter: 3105549061 file:
flutter: /var/mobile/Containers/Data/Application/D5A59E21-87EC-4ECC-9DD2-7517D235D2B5/Library/Caches/SoLoudLoader-Temp-Files/temp-sound-asset-0x96337e3
Also, the test app does NOT quit after it's done with the tests. I can't remember if this was the case in general or if it's something new. The last few messages before hanging are listed in the full log above, but I'm copying them here for convenience:
flutter: ===== TESTS PASSED! =====
===== TESTS PASSED! =====
flutter: [FINE] flutter_soloud.FlutterSoLoudFfi: STATE CHANGED EVENT state:
flutter: PlayerStateNotification.stopped
flutter: [FINE] flutter_soloud.SoLoud: Audio engine state changed:
flutter: PlayerStateNotification.stopped
I also do see STATE CHANGED EVENTs from flutter_soloud.FlutterSoLoudFfi
. When I "backgrounded" the app (went to "desktop" on the device) while the tests were running, I got the following:
flutter: [FINE] flutter_soloud.FlutterSoLoudFfi: STATE CHANGED EVENT state:
flutter: PlayerStateNotification.stopped
flutter: [FINE] flutter_soloud.SoLoud: Audio engine state changed:
flutter: PlayerStateNotification.stopped
flutter: [FINE] flutter_soloud.FlutterSoLoudFfi: STATE CHANGED EVENT state:
flutter: PlayerStateNotification.started
flutter: [FINE] flutter_soloud.SoLoud: Audio engine state changed:
flutter: PlayerStateNotification.started
flutter: [FINE] flutter_soloud.FlutterSoLoudFfi: STATE CHANGED EVENT state:
flutter: PlayerStateNotification.stopped
flutter: [FINE] flutter_soloud.SoLoud: Audio engine state changed:
flutter: PlayerStateNotification.stopped
flutter: [FINE] flutter_soloud.FlutterSoLoudFfi: STATE CHANGED EVENT state:
flutter: PlayerStateNotification.started
flutter: [FINE] flutter_soloud.SoLoud: Audio engine state changed:
flutter: PlayerStateNotification.started
flutter: [FINE] flutter_soloud.FlutterSoLoudFfi: FILE LOADED EVENT error: 0 hash:
flutter: 600584349 file:
flutter: /var/mobile/Containers/Data/Application/5956B8D1-56AF-45F2-B8ED-1684071D8EF9/Library/Caches/SoLoudLoader-Temp-Files/temp-sound-asset-0x96337e3
flutter: [FINEST] flutter_soloud.SoLoudLoader: Asset assets/audio/8_bit_mentality.mp3
flutter: already exists as a temporary file.
flutter: [FINE] flutter_soloud.FlutterSoLoudFfi: FILE LOADED EVENT error: 0 hash:
flutter: 1837005267 file:
flutter: /var/mobile/Containers/Data/Application/5956B8D1-56AF-45F2-B8ED-1684071D8EF9/Library/Caches/SoLoudLoader-Temp-Files/temp-sound-asset-0x14e85640
flutter: [SEVERE] flutter_soloud.SoLoud: stop() takes too much time for handle 4098. This
flutter: is not expected but not blocking. Worth to file a bug with a simple reproducible
flutter: code.
TEST error (SEVERE log): [SEVERE] flutter_soloud.SoLoud: stop() takes too much time for handle 4098. This is not expected but not blocking. Worth to file a bug with a simple reproducible code.
flutter: [FINE] flutter_soloud.FlutterSoLoudFfi: VOICE ENDED EVENT handle: 1
flutter: [FINEST] flutter_soloud.SoLoud: Voice ended event received. Removing handle 1
flutter: [FINEST] flutter_soloud.SoLoud: Voice ended event received. Removing handle 1
flutter: [FINE] flutter_soloud.FlutterSoLoudFfi: VOICE ENDED EVENT handle: 8195
flutter: [FINEST] flutter_soloud.SoLoud: Voice ended event received. Removing handle 8195
flutter: [INFO] testAllInstancesFinished: All instances of explosion finished.
Note that I only put the app into background once, but I get severeal state changes (start-stop-start-stop-...) in quick succession. Also, there's an error (stop() takes too much time to handle 4098
) which I'm not sure is expected when the app is backgrounded.
Thank you very much for the details!
I do see some errors, namely:
error: 0
in this case is not an error, but it's just the index of PlayerError.noError
. I fixed this output for an incoming chore commit.
Also, the test app does NOT quit after it's done with the tests. I can't remember if this was the case in general or if it's something new.
I remember seeing this behavior before, but I'm not 100% sure if it was the fault of
await SystemChannels.platform.invokeMethod('SystemNavigator.pop');
Also, there's an error (stop() takes too much time to handle 4098) which I'm not sure is expected when the app is backgrounded.
I need to test this.
About the STATE CHANGED EVENT logs is correct to see them after the ===== TESTS PASSED! =====
becasue they are async. The events I was happy to see on iOS were PlayerStateNotification.[interruptionBegan|interruptionEnded]
but are not related to this PR and need further investigation. I'd leave them here for convenience.
Aside from some minor work, we might think that this approach, without AudioIsolate, would work.
I've pushed the changes we discussed here. Hope I didn't forget something, if I didn't feel free to merge.
Ok, I added two more comments. Whether or not you address them, feel free to merge.
Description
By removing
AudioIsolate
all its logic is now handled on the cpp side, along with some other considerations described in #87.loadMem()
which accepts a Uint8list as a buffer, useful for the web where audio files cannot be directly opened¹ by adding these events we will be able to add feature #86.
start
andstop
events are triggered on all backends, but the Android audio backends seem not to fire the other events These might need to be captured using a Method Channel. The other events are:rerouted
,interruptionBegan
,interruptionEnded
,unlocked
.API changes
FutureOr<bool> get initialized
becomes deprecated. Usebool get isInitialized
instead.Duration timeout
param ofinit()
becomes deprecated.Some considerations
loadWaveform()
,speechText()
, 'play()',play3d()
can now be synchronous.init()
method is async because of_loader.initialize()
. Would it be worth considering making it sync?@filip, it might be beneficial for us to conduct some road testing for a period of time. I would appreciate your thoughts on this.
Type of Change