Flutter Audio Player cannot play audio file from the Device File Path in IOS

2.3k Views Asked by At

I'm using flutter audio player package https://pub.dev/packages/audioplayers to play audio file from the Device File Path. The problem is I cannot Play Audio File in IOS. But it's working fine in Android. Please Help me how to play audio File from Device File Path in IOS.

I already try to change the file extension to mp3,aac,acc,m4a,wav. But it still doesn't play in IOS.

2

There are 2 best solutions below

2
mppz On BEST ANSWER

I was solved by adding "temp.mp3" at the end of the dir path.

var file = File(path);

   Uint8List bytes = file.readAsBytesSync();

   var buffer = bytes.buffer;

   var unit8 = buffer.asUint8List(32, bytes.lengthInBytes - 32);
   Directory dir = await getApplicationDocumentsDirectory();

   var tmpFile = "${dir.path}/tmp.mp3";
   var writeFile = File(tmpFile).writeAsBytesSync(unit8);
   var urlSource = DeviceFileSource(tmpFile);
   audioPlayer.play(urlSource); 
0
Ndiaga GUEYE On
DeviceFileSource deviceFileSource = DeviceFileSource(audioPath);
await audioPlayer.play(deviceFileSource);