Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not play with asset source and lowLatency mode (BUG) #1193

Closed
under3415 opened this issue Jun 25, 2022 · 24 comments · Fixed by #1224 or #1272
Closed

Does not play with asset source and lowLatency mode (BUG) #1193

under3415 opened this issue Jun 25, 2022 · 24 comments · Fixed by #1224 or #1272

Comments

@under3415
Copy link

under3415 commented Jun 25, 2022

Low Latency mode does not work on Android

Full Description

Using sound player with AssetSource and lowLatency mode does not work. No sound is played. No error either, it just doesn't do anything.

Code to Reproduce

 await _soundPlayer.play(
          AssetSource('sounds/long_beep.mp3'),
          mode: PlayerMode.lowLatency,
        );

Log Errors
No errors, just does not play sound

Files/URLs/Sources
N/A

Screenshots
N/A

Platforms
Android

  • OS: android
  • OS version: android version 11 on physical device. Also emulator Pixel 4 API 31 Android 12
  • Device: Samsung Galaxy A20
  • flutter version: 3.0.2
  • audioplayers version: 1.0.1
  • release or not release: debug mode
  • does the error occur and does it have any peculiarities: easy to reproduce

** workaround**
Commenting out PlayerMode resolves the issue.

@Gustl22
Copy link
Collaborator

Gustl22 commented Jun 25, 2022

Plz use issue template! Also which platform you running the app? See also the parity table

@under3415
Copy link
Author

Plz use issue template! Also which platform you running the app? See also the parity table

I have provided more info using bug form. This is on Android.

@vinz-mehra
Copy link

Same issue with me

@g5applicationdev
Copy link

This problem also exists for me
In the real Android phone and emulator

@tupats
Copy link

tupats commented Jul 1, 2022

Same, lowlatency just does not work. On real device and emulator.

@under3415 under3415 changed the title Does not play with asset source and lowLatency mode Does not play with asset source and lowLatency mode (BUG) Jul 3, 2022
@lidaweicn
Copy link

Same issue on Android 10

@Ephenodrom
Copy link

Looks like the same issue as #1176 !

@under3415
Copy link
Author

under3415 commented Jul 5, 2022 via email

@leongkeng
Copy link

has anyone found a solution to this issue?

@under3415
Copy link
Author

has anyone found a solution to this issue?

As a workaround you can remove the low latency mode. Hopefully it will get fixed one day

@leongkeng
Copy link

As a workaround you can remove the low latency mode. Hopefully it will get fixed one day

As I am working on a percussion based system I need my sounds to overlay one another. Removing the low latency mode gives me lots of delays :( yeah hopefully we get an update soon

@under3415
Copy link
Author

@Gustl22 are you going to consider fixing this issue or not? Not much activity since your comment that the proper form should be used, which I have done...

@pmella16
Copy link

same .

@Gustl22
Copy link
Collaborator

Gustl22 commented Jul 21, 2022

@under3415 I currently working on some tests which touches all implementations of the various platforms, and will also include tests for lowLatency at some point. As this feature is only available on Android, this has not high priority for me personally. I eventually have time to fix it, when coming to this point, but you or someone else may have an attempt to fix it by themselves and create a Pull-Request, it's easier than you might think. That's the good thing with open source, if something bothers you, you can fix it, but someone has to invest their spare time :)

@Ephenodrom
Copy link

Can we get a new release on pub.dev with this fix ?

@leongkeng
Copy link

yes please. Can we have an update release? I need this to be fixed desperately:(

@Gustl22
Copy link
Collaborator

Gustl22 commented Sep 2, 2022

We still have some open Merge Requests which include fixes.

In the mean time you can override your dependencies in pubspec.yaml, e.g.:

dependency_overrides: 
  audioplayers:
    git: 
      url: https://github.com/bluefireteam/audioplayers.git
      path: 'packages/audioplayers'
  audioplayers_platform_interface:
    git: 
      url: https://github.com/bluefireteam/audioplayers.git
      path: 'packages/audioplayers_platform_interface'
  audioplayers_android:
    git: 
      url: https://github.com/bluefireteam/audioplayers.git
      path: 'packages/audioplayers_android'

@leongkeng
Copy link

leongkeng commented Sep 4, 2022

After overriding it doesnt seemed to work for me.

In my pubspec.yaml:

dependencies:
flutter:
sdk: flutter

audioplayers: ^1.0.1

dependency_overrides:
audioplayers:
git:
url: https://github.com/bluefireteam/audioplayers.git
path: 'packages/audioplayers'
audioplayers_platform_interface:
git:
url: https://github.com/bluefireteam/audioplayers.git
path: 'packages/audioplayers_platform_interface'
audioplayers_android:
git:
url: https://github.com/bluefireteam/audioplayers.git
path: 'packages/audioplayers_android'

The play audio function that i called:

static void play(MY_SAMPLE sample) => _player.play(AssetSource(samples[sample]! + _ext), mode: PlayerMode.lowLatency);

Same issue, no sound after adding the PlayMode.lowLatency. May I know if I did something wrong here?

@Gustl22
Copy link
Collaborator

Gustl22 commented Sep 4, 2022

@leongkeng I noticed you can play a file in lowLatency, but not reusing the player, or play a sample twice. There still seems to be something off. Let's track this in #1176

Gustl22 added a commit that referenced this issue Sep 8, 2022
* ignoring live stream
* reset streamId on stop
Gustl22 added a commit that referenced this issue Sep 8, 2022
* ignoring live stream
* reset streamId on stop
Gustl22 added a commit that referenced this issue Sep 8, 2022
* ignoring live stream
* reset streamId on stop
Gustl22 added a commit that referenced this issue Sep 12, 2022
…) (#1272)

* fix(android): lowLatency bugs (closes #1176, closes #1193, closes #1165)

* ignoring live stream
* reset streamId on stop

* make formatter happy
@Gustl22
Copy link
Collaborator

Gustl22 commented Sep 12, 2022

@leongkeng can you test again with current main? Don't forget to delete pub git cache or add ref to overridden dependencies in order to get the latest changes.

@leongkeng
Copy link

leongkeng commented Sep 12, 2022

@leongkeng can you test again with current main? Don't forget to delete pub git cache or add ref to overridden dependencies in order to get the latest changes.

I did 'flutter clean' and 'flutter pub cache repair', then flutter pub get. Also I did overriding my dependencies following your previous comments but still did not work. I managed to play one sound then it stops playing, its the same issue.

this is my console output after i tried to play a second audio

D/CCodec (25605): allocate(c2.android.raw.decoder)
I/CCodec (25605): Created component [c2.android.raw.decoder]
D/CCodecConfig(25605): read media type: audio/raw
D/ReflectedParamUpdater(25605): extent() != 1 for single value type: algo.buffers.max-count.values
D/ReflectedParamUpdater(25605): extent() != 1 for single value type: output.subscribed-indices.values
D/ReflectedParamUpdater(25605): extent() != 1 for single value type: input.buffers.allocator-ids.values
D/ReflectedParamUpdater(25605): extent() != 1 for single value type: output.buffers.allocator-ids.values
D/ReflectedParamUpdater(25605): extent() != 1 for single value type: algo.buffers.allocator-ids.values
D/ReflectedParamUpdater(25605): extent() != 1 for single value type: output.buffers.pool-ids.values
D/ReflectedParamUpdater(25605): extent() != 1 for single value type: algo.buffers.pool-ids.values
I/CCodecConfig(25605): query failed after returning 8 values (BAD_INDEX)
D/CCodecConfig(25605): c2 config diff is Dict {
D/CCodecConfig(25605): c2::u32 coded.bitrate.value = 64000
D/CCodecConfig(25605): c2::u32 input.buffers.max-size.value = 65536
D/CCodecConfig(25605): c2::u32 input.delay.value = 0
D/CCodecConfig(25605): string input.media-type.value = "audio/raw"
D/CCodecConfig(25605): string output.media-type.value = "audio/raw"
D/CCodecConfig(25605): c2::u32 raw.channel-count.value = 2
D/CCodecConfig(25605): c2::u32 raw.pcm-encoding.value = 0
D/CCodecConfig(25605): c2::u32 raw.sample-rate.value = 44100
D/CCodecConfig(25605): }
D/CCodec (25605): [c2.android.raw.decoder] buffers are bound to CCodec for this session
D/CCodecConfig(25605): no c2 equivalents for durationUs
D/CCodecConfig(25605): no c2 equivalents for track-id
D/CCodecConfig(25605): no c2 equivalents for bits-per-sample
D/CCodecConfig(25605): no c2 equivalents for channel-mask
D/CCodecConfig(25605): no c2 equivalents for flags
D/CCodecConfig(25605): c2 config diff is c2::u32 raw.channel-count.value = 1
W/Codec2Client(25605): query -- param skipped: index = 1107298332.
D/CCodec (25605): setup formats input: AMessage(what = 0x00000000) = {
D/CCodec (25605): int32_t channel-count = 1
D/CCodec (25605): int32_t max-input-size = 65536
D/CCodec (25605): string mime = "audio/raw"
D/CCodec (25605): int32_t pcm-encoding = 2
D/CCodec (25605): int32_t sample-rate = 44100
D/CCodec (25605): } and output: AMessage(what = 0x00000000) = {
D/CCodec (25605): int32_t channel-count = 1
D/CCodec (25605): string mime = "audio/raw"
D/CCodec (25605): int32_t pcm-encoding = 2
D/CCodec (25605): int32_t sample-rate = 44100
D/CCodec (25605): int32_t channel-mask = 0
D/CCodec (25605): }
W/Codec2Client(25605): query -- param skipped: index = 1342179345.
W/Codec2Client(25605): query -- param skipped: index = 2415921170.
E/FMQ (25605): grantorIdx must be less than 3
E/FMQ (25605): grantorIdx must be less than 3
D/CCodecBufferChannel(25605): [c2.android.raw.decoder#368] Created input block pool with allocatorID 16 => poolID 27 - OK (0)
D/BufferPoolAccessor2.0(25605): bufferpool2 0xf67ce388 : 0(0 size) total buffers - 0(0 size) used buffers - 0/5 (recycle/alloc) - 1/2 (fetch/transfer)
D/BufferPoolAccessor2.0(25605): Destruction - bufferpool2 0xf67ce388 cached: 0/0M, 0/0% in use; allocs: 5, 0% recycled; transfers: 2, 50% unfetched
I/CCodecBufferChannel(25605): [c2.android.raw.decoder#368] Created output block pool with allocatorID 16 => poolID 944 - OK
D/CCodecBufferChannel(25605): [c2.android.raw.decoder#368] Configured output block pool ids 944 => OK
E/FMQ (25605): grantorIdx must be less than 3
D/CCodecBufferChannel(25605): [c2.android.raw.decoder#368] MediaCodec discarded an unknown buffer
I/chatty (25605): uid=10122(com.my.project) NDK MediaCodec_ identical 1 line
D/CCodecBufferChannel(25605): [c2.android.raw.decoder#368] MediaCodec discarded an unknown buffer
I/hw-BpHwBinder(25605): onLastStrongRef automatically unlinking death recipients
D/BufferPoolAccessor2.0(25605): bufferpool2 0xf67d07a8 : 0(0 size) total buffers - 0(0 size) used buffers - 0/5 (recycle/alloc) - 3/6 (fetch/transfer)
D/BufferPoolAccessor2.0(25605): evictor expired: 2, evicted: 1

@Gustl22
Copy link
Collaborator

Gustl22 commented Sep 12, 2022

@leongkeng can you recheck with our example. The tests run fine, so I'm not sure, why it shouldn't work

Note that you have to call stop before play again, because the lowlatency player does not know, when a sample is finished playing (no duration available).
Or provide a minimal reproduction example in your own repo and post the link.

@leongkeng
Copy link

leongkeng commented Sep 12, 2022

@Gustl22

I tried running the example file and the output doesn't seem to be what I needed. It does allow me to play multiple audio but the first audio cuts when the second audio plays. Like you mentioned, I have to call 'stop' before play again means that I cannot have multiple audios playing concurrently?

It used to work in audioplayers: ^0.15.1 version. Where the audio files are able to overlap one another, without cutting off whenever subsequent audios are played at the same time.

This is what i want to achieve, https://drive.google.com/file/d/1bGp0TZdqE9qlamf0560m7pLq3J9I2G5y/view?usp=sharing
Its basically 5 'crash' buttons pressed.

This is the Github repo that I found and referrered to for my project https://github.com/kenreilly/flutter-drum-machine-demo

@Gustl22
Copy link
Collaborator

Gustl22 commented Sep 18, 2022

@leongkeng I checked the old implementation. I think this was more a bug than a feature. For each concurrent sound you should use a different instance of an AudioPlayer now. This also ensures that you can release the resources properly after closing the application.

Back then (<= v0.20.x) you could not control the sound in LOW_LATENCY correctly or just pause / stop the last of the sounds which were played concurrently with only one player. This was caused by overwriting the streamId inside the player, although the stream of the old id was still playing. This worked but as soon as the streamId is replaced you could not control the old stream anymore with the player or properly release it.

@luanpotter @spydon correct me if I'm wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
9 participants