I’m playing mp3s in Flutter code a trivial way, using the dependencies line audioplayers: ^6.0.0
in my pubspec.yaml
:
import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/material.dart';
void main() async {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
final player = AudioPlayer();
return MaterialApp(
home: Scaffold(
body: Center(
child:Column(
children: [
SizedBox(height: 100,),
ElevatedButton(
onPressed: () async {
await player.play(AssetSource('sfx/click2.mp3'));
},
child: Text('Click 2!'),
),
ElevatedButton(
onPressed: () async {
await player.play(AssetSource('sfx/click3.mp3'));
},
child: Text('Click 3!'),
)
]
)
),
),
);
}
}
Click3
works, but Click2
throws this error:
PlatformException (PlatformException(AndroidAudioError, Failed to set source. For troubleshooting, see:
https://github.com/bluefireteam/audioplayers/blob/main/troubleshooting.md, MEDIA_ERROR_UNKNOWN {what:1}, MEDIA_ERROR_SYSTEM, null))
click2.mp3
was made from click3.mp3
by reducing the wave to ~30 milliseconds, from ~300 milliseconds, removing only trailing silence from the clip. Both clips play fine on a typical mp3 player, like Windows Media Player.
Okay, so it’s no biggie adding a 100ms of silence to a clip, but aside from that workaround, does anyone see something I may be missing? I didn’t find any info on this in the audioplayers docs, or the troubleshooting link referenced in the exception description.