audioplayers
audioplayers copied to clipboard
Support for SetSourceBytes on IOS
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
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
Is it much more problematic than with Android phones ? What is the problem ?
I found one way to work around the problem.
-
I check platform : if ANDROID platform then, I use the SourceBytes system.
-
If IOS, then I download my file and store it in a Uint8list variable** "myAudioFileasBytes".
-
Using DART IO package : I create an empty file :
myAudioFile = File('${(await getApplicationDocumentsDirectory()).path}/XXXXXX.mp3');
-
Then I actually 'write' the file from the stored Bytes :
myAudioFile.writeAsBytes(myAudioFileasBytes);
-
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.
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