Canardoux / flutter_sound

Flutter plugin for sound. Audio recorder and player.
Mozilla Public License 2.0
878 stars 574 forks source link

WASM support #1094

Open putnokiabel opened 2 months ago

putnokiabel commented 2 months ago

Is your feature request related to a problem? Please describe. Projects using flutter_sound cannot compile to WASM right now, since flutter_sound_web uses the deprecated package:js and dart:html.

Describe the solution you'd like Replace usages of the deprecated package:js with the newer package:js_interop (or dart:js_interop_unsafe), and the usages of the deprecated dart:html with the new package:web.

Describe alternatives you've considered I don't see an alternative to be able to use flutter_sound on WASM, since it does not compile due to usage of incompatible packages.

Larpoux commented 2 months ago

@putnokiabel : I think that you are perfectly right. Flutter Sound should depends on package:web. This is a very important requirement. FlutterSound should not depends on deprecated libraries. I don't remember why there is this dependency in Flutter Sound ... I think that there is no fundamental reason and someone should fix that, more or less easily.

More important : I am currently busy working on a Flutter Sound v 10.0. And this new version will be also dependent on dart_html, in its first release. This is bad. But in v 10.0, I need to use Flutter WebAudio.dart, and WebAudio.dart depends on dart.html. And this is very bad. I will have to change that. But Flutter Sound v10.0 is a very important development, and I have no time to work on that point. I am noting your requirement as something very important to address very soon. This is a priority.

lorisgir commented 3 weeks ago

Hi @Larpoux, I needed to run my flutter application on web with wasm enabled so I started digging at your code. I only use the player functionality (not using the recorder), so I just migrated that code but somehow I managed to make it work on wasm.

In the flutter_sound folder I just needed to remove dart:io from two files. In the flutter_sound_web folder I removed dart:html and package:js/js.dart.

The last packaged was the hardest to migrate since online there's basically 0 documentation, but turned out I only needed to change this file: lib/flutter_sound_player_web.dart. I dont know anything about WebAudio.dart you mentioned in your last comment, but for my use case the changes I made were enough.

You could go see my repo to check what I changed. After some cleanup I could also create a pull request on your branch.

Larpoux commented 3 weeks ago

@lorisgir . Hi Loris. Thank you so much for your contribution on Flutter Sound. I am very excited to know that Flutter Sound is compatible with WASM 👍 . Of course, I would be very happy with a PR. But if you can't or don't want, I will try to look to your code myself. Really, I appreciate.