Audio_service: Duration of a file

Created on 30 Jun 2020  路  4Comments  路  Source: ryanheise/audio_service

Checklist

  • [x] The question is not already in the FAQ.
  • [x] The question is not too narrow or specific to a particular application.

Suggested Question

Write the question here.
Is there any way to get the duration of a song if you don't know it ahead of time? I know there's a duration stream for just audio, but how could I use that with the audio service plugin?

1 backlog question

Most helpful comment

That was probably a more appropriate question for the just_audio project I would imagine, in that case since audio_service is only concerned with how to manage the duration once you've got it. But glad you figured it out.

All 4 comments

I think I just figured a way with custom event streams:
Duration length;
var durationSubscription = _audioPlayer.durationStream.listen((lengthOfSong) {
length = lengthOfSong ?? Duration.zero;
AudioServiceBackground.sendCustomEvent(length);
});

Though there may be a better solution out there.

Thank you for your time.

If you search the FAQ for the word "duration", you will find how the duration can be updated.

So assuming you know how to get the duration from just_audio, which it seems you do, once you have that new duration, you can update it as per the example in the FAQ.

Thank you very much. Yeah I was mostly stuck on getting the duration in the first place, but figured a way to do it not long after I posted. Thank you for your time, again.

That was probably a more appropriate question for the just_audio project I would imagine, in that case since audio_service is only concerned with how to manage the duration once you've got it. But glad you figured it out.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

erickcchoi picture erickcchoi  路  6Comments

mrxten picture mrxten  路  5Comments

MahdiPishguy picture MahdiPishguy  路  5Comments

Okladnoj picture Okladnoj  路  6Comments

pblinux picture pblinux  路  5Comments