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
1.93k stars 825 forks source link

Allow playing of live streamed data #1806

Open Binozo opened 1 month ago

Binozo commented 1 month ago

Checklist

Use case / Problem

Hello there 👋

currently I am developing an app for my raspberry pi running on flutter-pi. flutter-pi supports only this audio package so that's why I chose it (and it looks decent too).

In this use case the audio data is being live streamed by my server in a format like this: Stream<Uint8List>. I looked through the wiki and there is no real option for live streamed data beside BytesSource and UrlSource but those only support audio data which is already fully downloaded.

I think it would be a great addition for this package

Proposal / Solution

I would suggest a new type of Source like StreamedBytesSource for example. With that new type you would constantly add data to the buffer which is being read by this package. I think implementing this new type of source and playing the actual data like BytesSource does would be a good way to implement that.

Example Code

Example Code ```dart void main() { final player = AudioPlayer(); // Pseudo stream but could be implemented somehow like this Stream source = // stream init await player.setSource(StreamedBytesSource(source)); // Add data source.add([0, 1, 0, 1, 0, 1 /* ... */]); // being fed by an external source } ```

Affected platforms

Android, iOS, web, Windows, Linux, macOS

Platform details

I think it'll work on every platform which implements BytesSource because the way it plays the audio could be implemented like BytesSource does.

Audio Files/URLs/Sources

No response

Mockups

No response

Related issues / more information

I think this feature would be a great addition and I'm looking forward to do the actual implementation myself :)

Currently I am planning to wait for some feedback to this feature request until I do the actual implementation

Working on PR

yeah

Binozo commented 1 month ago

Took a look into the internals and it seems that that StreamedBytesSource would need a reimplementation of almost every api 😬

Most of those expect a full bytestream to feed into their dedicated audioplayer like android does