Audio_service: AudioServiceBackground.setMediaItem() not work well

Created on 2 Mar 2021  路  9Comments  路  Source: ryanheise/audio_service

Which API doesn't behave as documented, and how does it misbehave?
I use just_audio and audio_service packages at the same time.
Then I create a playlist of MediaItem and put a Map value in the extra field of mediaItem like the following code:

MediaItem(
          id: track.audioPath.trackUrl,
          album: track.albumName,
          title: track.name,
          artist: track.getArtistNames,
          artUri: track.coverImagePath.smallImage,
          duration: Duration(milliseconds: track.durationInMs),
          extras: {
           "value" : {'key' : 'value'},
          },
        ),

Then I play this playlist.
In the Background code, I wrote this piece of code in the onStart method:

_currentIndexStream = _player.currentIndexStream.listen(
      (itemIndex) {
        if (itemIndex != null) {
          AudioServiceBackground.setMediaItem(_queue[itemIndex]);
        }
      },
    );

But when I listen to currentMediaItemStream in ui and print that extra field, it returns null:

AudioService.currentMediaItemStream.listen(
      (mediaItem) {
       //it always returns null
        print(mediaItem?.extras[Statics.metaDataMediaItemExtra]);
      },
    );

But if I send int or string instead of Map, everything will work fine. Even if I convert that Map to json using json.encode () and send it, it is still not a problem, but until I send the Map itself, it nulls that field.
AudioServiceBackground.setMediaItem seems to be having trouble with Map type.

Minimal reproduction project
Provide a link here using one of two options:

  1. Fork this repository and modify the example to reproduce the bug, then provide a link here.
  2. If the unmodified official example already reproduces the bug, just write "The example".

To Reproduce (i.e. user steps, not code)
Steps to reproduce the behavior:

  1. create mediaItem List
  2. in MediaItem extras field put the Map value
  3. listen to AudioServiceBackground.setMediaItem in ui
  4. print that extras field

Error messages
None

Expected behavior
work with Map type

Screenshots
None

Runtime Environment (please complete the following information if relevant):

  • Device: Huawie mate 10 lite
  • OS: Android 8.0.0

Flutter SDK version
1.22.5

Additional context
None

1 backlog bug

All 9 comments

Hi @AliHoseinpoor I am not convinced this is a bug in audio_service. It is likely the case that you have a bug in your own app, and you will need to do some debugging to figure out why.

If you are going to submit a bug report, you must follow the instructions and provide clear evidence that there is an actual bug in audio_service and provide a minimal reproduction project that allows me to reproduce this bug.

I'll close this since it does not provide what is expected in a bug report.

Hi @ryanheise just want to know how you replay to issues so fast? :-)
By the way your work is great.

Thanks! GitHub issues is one of the few things where I have notifications turned on, so that if a bug is reported, I can look into it quickly.

Hi @AliHoseinpoor I am not convinced this is a bug in audio_service. It is likely the case that you have a bug in your own app, and you will need to do some debugging to figure out why.

If you are going to submit a bug report, you must follow the instructions and provide clear evidence that there is an actual bug in audio_service and provide a minimal reproduction project that allows me to reproduce this bug.

I'll close this since it does not provide what is expected in a bug report.

https://github.com/AliHoseinpoor/audio_service/blob/master/example/lib/main.dart
@ryanheise please check this link

Hi @AliHoseinpoor As mentioned above, I am not convinced this is a bug in audio_service itself.

I will copy and paste below point 1 from the instructions:

  1. A bug report must demonstrate a bug in the plugin, and not merely a
    bug in your app. Understand that this plugin WILL throw exceptions
    or otherwise misbehave if not used in accordance with the
    documentation. In order to verify that you have indeed found a bug,
    you will need to make a reference to the documentation in order to
    explain how the actual behaviour you experienced is different from
    the behaviour that was documented. If the behaviour you want is
    undocumented, please submit either a documentation request or a
    feature request instead, whichever is more appropriate.

Unless you can meet the requirements for the first section of the bug report, it does not qualify in a bug, and I unfortunately don't have time to debug other people's apps, only audio_service itself.

Hi @AliHoseinpoor As mentioned above, I am not convinced this is a bug in audio_service itself.

I will copy and paste below point 1 from the instructions:

  1. A bug report must demonstrate a bug in the plugin, and not merely a
    bug in your app. Understand that this plugin WILL throw exceptions
    or otherwise misbehave if not used in accordance with the
    documentation. In order to verify that you have indeed found a bug,
    you will need to make a reference to the documentation in order to
    explain how the actual behaviour you experienced is different from
    the behaviour that was documented. If the behaviour you want is
    undocumented, please submit either a documentation request or a
    feature request instead, whichever is more appropriate.

Unless you can meet the requirements for the first section of the bug report, it does not qualify in a bug, and I unfortunately don't have time to debug other people's apps, only audio_service itself.

not this not my project. this is a minimal reproduction project

Hi @AliHoseinpoor,

you use

extras: {
        'data': {'key1': 'value1'}
      }),

but the API states

/// A map of additional metadata for the media item.
///
/// The values must be integers or strings.
final Map<String, dynamic> extras;

In your case, the value is another map. Did not test the code, but try to use only int or String as values in extras.

not this not my project. this is a minimal reproduction project

I'm not sure if you read the instructions I quoted, but please read them carefully. For example, please note the following sentence:

In order to verify that you have indeed found a bug,
you will need to make a reference to the documentation in order to
explain how the actual behaviour you experienced is different from
the behaviour that was documented.

I have checked again and you have not done this. Please do this to ensure that you have found a legitimate bug before asking me to debug it, thanks.

Edit: Thanks to @mvolpato who has pointed out the documentation in question. This is why it is important that you cross reference the documentation - to check whether it really is a bug or intended behaviour - in section 1 of the bug report.

not this not my project. this is a minimal reproduction project

I'm not sure if you read the instructions I quoted, but please read them carefully. For example, please note the following sentence:

In order to verify that you have indeed found a bug,
you will need to make a reference to the documentation in order to
explain how the actual behaviour you experienced is different from
the behaviour that was documented.

I have checked again and you have not done this. Please do this to ensure that you have found a legitimate bug before asking me to debug it, thanks.

Edit: Thanks to @mvolpato who has pointed out the documentation in question. This is why it is important that you cross reference the documentation - to check whether it really is a bug or intended behaviour - in section 1 of the bug report.

Thank you for your help.

Was this page helpful?
0 / 5 - 0 ratings