Comments (7)
Fixed in 0.0.9
from audio_session.
Oh, you're right!
Both addObserver
and removeObserver
are tied to the plugin instance. What should happen is that initWithRegistrar
and dealloc
should both look at sessions.count
and only call addObserver
if this is the first session being created, and only call removeObserver
if this is the last session being deallocated.
from audio_session.
Not to mention that dealloc
probably doesn't get called since each instance is retained in the sessions
array. Probably the array of sessions needs to be __weak
.
from audio_session.
Unfortunately my obj-c knowledge is very limited or almost non-existant so I have little there.... But I'm wondering what benefits there are of having multiple instances over one platform instance?
from audio_session.
Plugins that do it that way generally break when they are loaded into apps that use more than one FlutterEngine instance (like audio_service-based apps, or any apps that do background execution).
Basically what should happen in an app that uses multiple FlutterEngines is that each FlutterEngine will have its own plugin registrar, and the plugins will be instantiated anew in each registrar. So the plugin should have an instance of itself loaded in each FlutterEngine, but it is up to the plugin to manage any parts of its state that are to be shared globally between all instances. You'll notice that the only instance data in DarwinAudioSession
is the registrar and the channel, which need to be different per instance, while everything else was intended to be shared.
Technically DarwinAudioSession
isn't itself the plugin, AudioSessionPlugin
is, but the way I designed it is that DarwinAudioSession
is kind of like a sub-plugin that behaves in the same way as a plugin. If I ever end up exposing another iOS API aside from AVAudioSession
, the intention was that it would also be encapsulated in its own class, and itself behave in the same way as a plugin. That way, AudioSessionPlugin
doesn't need to concern itself with how each individual API works.
from audio_session.
Plugins that do it that way generally break when they are loaded into apps that use more than one FlutterEngine instance (like audio_service-based apps, or any apps that do background execution).
Basically what should happen in an app that uses multiple FlutterEngines is that each FlutterEngine will have its own plugin registrar, and the plugins will be instantiated anew in each registrar. So the plugin should have an instance of itself loaded in each FlutterEngine, but it is up to the plugin to manage any parts of its state that are to be shared globally between all instances. You'll notice that the only instance data in
DarwinAudioSession
is the registrar and the channel, which need to be different per instance, while everything else was intended to be shared.Technically
DarwinAudioSession
isn't itself the plugin,AudioSessionPlugin
is, but the way I designed it is thatDarwinAudioSession
is kind of like a sub-plugin that behaves in the same way as a plugin. If I ever end up exposing another iOS API aside fromAVAudioSession
, the intention was that it would also be encapsulated in its own class, and itself behave in the same way as a plugin. That way,AudioSessionPlugin
doesn't need to concern itself with how each individual API works.
Thank you for taking the time to write this. It all makes sense to me now.
from audio_session.
I have fixed the ARC management in the latest commit along with your issue, although fixing the ARC code has revealed a bug in just_audio and forced me to fix it's ARC code, too. I'll need to do some sort of coordinated release so that the new audio_session and just_audio are available at the same time.
I haven't pushed the just_audio fixes yet, so if you try the new audio_session with just_audio now, you'll experience a crash whenever a FlutterEngine is destroyed (when audio_service is stopped).
I might take a look at #7 before doing a release, and will let you know when it is available for testing.
from audio_session.
Related Issues (20)
- AVAudioSession.mm Failed to set category, error: -50 flutter HOT 2
- devicesChangedEventStream returns empty sets on first load HOT 2
- [iOS] Audio session activation failed when app is in background HOT 1
- Support rxdart 0.28
- Is it possible to set preferredIOBufferDuration for `AVAudioSession` HOT 3
- Stop audio when another app plays audio! HOT 1
- How to configure session to use Bluetooth headset mic on Android? HOT 6
- Can't build on android when targetting android 34 HOT 11
- Add privacy manifest for Apple HOT 6
- [iOS] Background audio not playing on iPhone 13+ HOT 3
- AVAudioSessionCategoryOptions.mixWithOthers stops background music the first time when audio is player, after continuing the music further sounds no longer stop the music HOT 1
- Call requires API level 23 (current min is 16) HOT 1
- Can not play by speaker on iOS HOT 3
- Is it possible to play audio when Do Not Disturb mode is on, but not in silent mode? HOT 1
- `AVAudioSessionCategoryOptions`'s `contains` method takes `AVAudioSessionInterruptionOptions`. Maybe it should be `AVAudioSessionCategoryOptions`? HOT 5
- Dependency causing an ANR in the Background HOT 3
- The music played by IOS17 is not output from Bluetooth earphones HOT 2
- Android detects the headset as if it is connected even if it is not HOT 1
- Trouble closing an audio session HOT 1
- Topics HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from audio_session.