audioplayers icon indicating copy to clipboard operation
audioplayers copied to clipboard

Support for SetSourceBytes on IOS

Open sylvainjack opened this issue 1 year ago • 4 comments

Checklist

  • [X] I made sure that the issue I am raising doesn't already exist

Use case / Problem

Hi everyone 🙂 I am developing a flutter app. It's an app that tests a student's proficiency of English as a second language. So there is one part to test oral comprehension. I use Audioplayers to do that part. I just finished it and everything works fine on android phones. I am just a beginner at programming. And I really loved how Audioplayers was easy to work with. But here is my problem : I just tried it on macbook to test on IOS... and catastrophe !! apparently, it's telling me : "SetSourceBytes is not currently implemented on IOS"... What can I do ? It's so handy to work with SourceBytes.

Do you think this feature will soon be available for IOS as well ?

Proposal / Solution

Unfortunaly as a beginner there is little I can offer as a solution.... Implementing support for SetSourceBytes on IOS would be a solution for my problem :)

Example Code

Example Code
void main() {
}

Affected platforms

iOS

Platform details

No response

Audio Files/URLs/Sources

No response

Mockups

No response

Related issues / more information

No response

Working on PR

no way

sylvainjack avatar Nov 05 '23 18:11 sylvainjack

Unfortunately we don't have these capacities at the moment to implement it. But feel free to help us out. See also this: https://github.com/bluefireteam/audioplayers/issues/1269#issuecomment-1666675161

Gustl22 avatar Nov 05 '23 18:11 Gustl22

Is it much more problematic than with Android phones ? What is the problem ?

sylvainjack avatar Nov 05 '23 19:11 sylvainjack

I found one way to work around the problem.

  1. I check platform : if ANDROID platform then, I use the SourceBytes system.

  2. If IOS, then I download my file and store it in a Uint8list variable** "myAudioFileasBytes".

  3. Using DART IO package : I create an empty file : myAudioFile = File('${(await getApplicationDocumentsDirectory()).path}/XXXXXX.mp3');

  4. Then I actually 'write' the file from the stored Bytes : myAudioFile.writeAsBytes(myAudioFileasBytes);

  5. Then with AudioPlayers : I use the DeviceFileSource method: await _player.play(DeviceFileSource('${(await getApplicationDocumentsDirectory()).path}/${myAudioFile}.mp3'));

I tried it on my iPhone and it worked.

sylvainjack avatar Nov 05 '23 20:11 sylvainjack

Maybe it is somehow possible to override AVAsset to use a Audio AVAssetTrack with AVAudioBuffer. But that's only an assumption. Else we have to provide a workaround. AVAudioPlayer supports playing from a buffer.

See also: https://stackoverflow.com/questions/50012567/how-to-convert-data-to-avasset

Gustl22 avatar Nov 21 '23 10:11 Gustl22