Audio_service: Demonstrating how to reset MediaItem duration in the example app

Created on 3 Dec 2020  路  4Comments  路  Source: ryanheise/audio_service

To which pages does your suggestion apply?

I'm considering the example app with its comment docs as documentation since it is quite useful for learning how to use audio_service and combine it with an audio player.

The section in the FAQs is helpful since this does in fact appear to be a frequently asked question (#5, #126, #229, #279, #310, #384). However, without a full example, it's still difficult to understand.

Quote the sentences(s) from the documentation to be improved (if any)

The MediaLibrary in the example app hardcodes the duration:

class MediaLibrary {
  final _items = <MediaItem>[
    MediaItem(
      ...
      duration: Duration(milliseconds: 5739820),

This is in contrast to the advice found in the FAQs, which shows how to update the media item after the duration is known:

modifiedMediaItem = mediaItem.copyWith(duration: duration);

Describe your suggestion

I realize that audio_service doesn't itself play audio and however one chooses to use an audio player is an implementation detail. However, given (1) the example app already shows one implementation with just_audio and (2) needing to update the audio duration after it's known from the audio player is a common problem, I'd like to suggest that we use the example app to demonstrate passing in a list of media items with unknown duration. Then update the media item and queue with the new duration once it is known.

1 backlog documentation

Most helpful comment

Thanks for your reply and checking on that code. Since it seems to be working and there is at least a link to an example here, I guess there isn't a big rush to add it to the repo example, but I imagine people will still find it useful.

All 4 comments

I agree this is worth doing.

However, I'll have to get around to https://github.com/ryanheise/just_audio/issues/141 first.

I added a Stack Overflow Q&A for this topic:

It seems to be working but if anyone has time to give me a code review, that would be helpful. I was kind of grasping in the dark.

Your StackOverflow answer is the correct idea.

I was hoping to implement https://github.com/ryanheise/just_audio/issues/141 first, since the demo example contains a playlist and ideally I could display the duration next to all media items in a list.

Currently, just_audio has to start decoding audio in order to discover its duration, and because the playlist is loaded lazily, we won't know the duration of the second item in the playlist until we reach it.

In ExoPlayer, it is in some cases possible to read the duration without decoding the audio, but that would unfortunately not be the case in the audio_service example, so perhaps you're right, I should not need to wait for that just_audio feature to be implemented before adding an example of updating the media item duration in audio_service.

I'll see what I can do.

Thanks for your reply and checking on that code. Since it seems to be working and there is at least a link to an example here, I guess there isn't a big rush to add it to the repo example, but I imagine people will still find it useful.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eAvio picture eAvio  路  7Comments

MohamedAbdallah-14 picture MohamedAbdallah-14  路  7Comments

hemalmoradiya picture hemalmoradiya  路  4Comments

hpuriamanesh picture hpuriamanesh  路  7Comments

AhmadAbdollah picture AhmadAbdollah  路  6Comments