1

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.

mppz
  • 31
  • 4
  • Please provide enough code so others can better understand or reproduce the problem. – bqubique Mar 24 '23 at 23:27
  • Does this happen to all ```assets``` files (files inside ```assets/``` folder)? Or are you trying to play an audio file from some other path? – bqubique Mar 24 '23 at 23:33
  • No its not assets file. It is from the Device File Path . But it is now solve by adding "tmp.mp3" at the end of the dir path.Thank You. @bqubique – mppz Mar 25 '23 at 18:39

1 Answers1

1

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); 
mppz
  • 31
  • 4