In my chat app I added a feature to record audio using flutter_sound package. Now I need to show timer when user playback that record. It worked fine before dart migration and before the package update. Now I can't get it to work.
Here is the code after the package update and after the migration to null safety.
void _addListeners(messageProvider) {
cancelPlayerSubscriptions();
_playerSubscription = _myPlayer?.onProgress!.listen((e) {
print('test inside');
if (e != null) {
debugPrint('playback position here');
maxDuration = e.duration as double;
if (maxDuration <= 0) maxDuration = 0.0;
var date = DateTime.fromMillisecondsSinceEpoch(
int.parse(e.position.toString()),
isUtc: true);
String txt = DateFormat('mm:ss:SS', 'en_GB').format(date);
messageProvider.playerText = txt.substring(0, 8);
if (int.parse(e.position.toString()) == maxDuration) {
messageProvider.currentIcon = 0;
}
}
});
}
This is the code before the dart migration and package update
void _addListeners(messageProvider) {
cancelPlayerSubscriptions();
_playerSubscription = playerModule.onPlayerStateChanged.listen((e) {
if (e != null) {
maxDuration = e.duration;
if (maxDuration <= 0) maxDuration = 0.0;
DateTime date = new DateTime.fromMillisecondsSinceEpoch(
e.currentPosition.toInt(),
isUtc: true);
String txt = DateFormat('mm:ss:SS', 'en_GB').format(date);
messageProvider.playerText = txt.substring(0, 8);
if (e.currentPosition.toInt() == maxDuration) {
messageProvider.currentIcon = 0;
}
}
});
}
my main problem is not printing 'test inside'. That means it's not going inside that. Any of you guys have an idea about this?