calculate overall audio played in session using audio_service plugin flutter
void _listenToPlaybackState() {
_audioHandler.playbackState.listen(
(playbackState) {
final isPlaying = playbackState.playing;
// if (isPlaying) {
// shouldShowMiniPlayerNotfier.value = true;
// if (_currentPlayingEpisode.isNegative == false) {
// var episodeId = _currentPlayingEpisode;
// log('hitting play api for episodeId: $episodeId ::: $_currentPlayingEpisode');
// _currentPlayingEpisode = -1;
// podcastsController.updatePlayCountOfEpisodeById(episodeId);
// }
// }
final processingState = playbackState.processingState;
if (processingState == AudioProcessingState.loading ||
processingState == AudioProcessingState.buffering) {
playButtonNotifier.value = ButtonState.loading;
} else if (!isPlaying) {
playButtonNotifier.value = ButtonState.paused;
log("Audio Paused ${currentMediaItemIdNotifier.value}");
} else if (processingState != AudioProcessingState.completed) {
playButtonNotifier.value = ButtonState.playing;
` // MixpanelManager.timeEvent(MixPanel.audioPlayingTimeSpent);
log("Audio Play ${currentMediaItemIdNotifier.value}");
} else if (processingState == AudioProcessingState.idle) {
playButtonNotifier.value = ButtonState.stopped;
log("Audio Stopped ${currentMediaItemIdNotifier.value}");
} else {
_audioHandler.seek(Duration.zero);
_audioHandler.pause();
}
},
);
}
I have posted a example for login event when user tries to play audio from notification panel or button. please help setting up analytics events