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

Error after playing music several times with AudioCache #843

Closed
wenxiangjiang opened this issue Apr 10, 2021 · 17 comments · Fixed by #844
Closed

Error after playing music several times with AudioCache #843

wenxiangjiang opened this issue Apr 10, 2021 · 17 comments · Fixed by #844
Labels
AudioCache Concerning the AudioCache bug platform-android Affects the android platform stale Automatically close this issue, if no activity is recognized waiting for report Wait for the author to respond to the conversation

Comments

@wenxiangjiang
Copy link
Contributor

Error after playing music several times with AudioCache.

Full Description

By executing the following code, an error occurs when press the button several times.

I found that there are already related issues:

#773 #682 #766

I think the reason of the issue is at play method of AudioCache.

Future<AudioPlayer> play(
    String fileName, {
    double volume = 1.0,
    bool? isNotification,
    PlayerMode mode = PlayerMode.MEDIA_PLAYER,
    bool stayAwake = false,
    bool recordingActive = false,
    bool? duckAudio,
  }) async {
    String url = await getAbsoluteUrl(fileName);
    AudioPlayer player = _player(mode);
    player.setReleaseMode(ReleaseMode.STOP); // this line
    await player.play(
      url,
      volume: volume,
      respectSilence: isNotification ?? respectSilence,
      stayAwake: stayAwake,
      recordingActive: recordingActive,
      duckAudio: duckAudio ?? this.duckAudio,
    );
    return player;
  }

This line was added because #618 . That is a good PR, but it will cause errors when not using fixedPlayer. Maybe due to large amount of AudioPlayer will not be released.

I think we should add a judgment like this:

Future<AudioPlayer> play(
    String fileName, {
    double volume = 1.0,
    bool? isNotification,
    PlayerMode mode = PlayerMode.MEDIA_PLAYER,
    bool stayAwake = false,
    bool recordingActive = false,
    bool? duckAudio,
  }) async {
    String url = await getAbsoluteUrl(fileName);
    AudioPlayer player = _player(mode);
    
    // this three lines
    if (fixedPlayer != null) {
      player.setReleaseMode(ReleaseMode.STOP);
    }
    
    await player.play(
      url,
      volume: volume,
      respectSilence: isNotification ?? respectSilence,
      stayAwake: stayAwake,
      recordingActive: recordingActive,
      duckAudio: duckAudio ?? this.duckAudio,
    );
    return player;
  }

If my idea meets the needs, I'm interested in working on a PR for this.

Code to Reproduce

// Create a reference
final AudioCache _audioCache = AudioCache(prefix: 'assets/audio/');

// Press several times, an error occurs
TextButton(
  onPressed: () {
    _audioCache.play('demo.mp3');
  },
  child: Text('Play'),
),

Log Errors

D/MediaPlayer( 5024): setSubtitleAnchor in MediaPlayer
E/MediaPlayer( 5024): error (1, -19)
E/MediaPlayer( 5024): Error (1,-19)
E/MediaPlayer( 5024): pause called in state 0, mPlayer(0x83798720)
E/MediaPlayer( 5024): error (-38, 0)
E/MediaPlayer( 5024): Attempt to perform seekTo in wrong state: mPlayer=0x83798720, mCurrentState=0
E/MediaPlayer( 5024): error (-38, 0)
E/MediaPlayer( 5024): Error (-38,0)
E/MediaPlayer( 5024): Error (-38,0)

Files/URLs/Sources

None.

Screenshots

None.

Platforms

  • OS: Android
  • OS version: 7.1.2
  • Device: physical device. Internal model.
  • flutter version: 2.0.3
  • audioplayers version: 0.18.3
  • release or not release: release and debug modes.
  • does the error occur and does it have any peculiarities: No.
@erickzanardo
Copy link
Member

This changes seems to make sense for me @wenxiangjiang, would you be willing to put a PR for that?

@wenxiangjiang
Copy link
Contributor Author

@erickzanardo sure. I will do it soon.

@AhmedNourJamalElDin
Copy link

This still happens to me using the repo as dart dependency i.e. not the published version of the package.

audioplayers:
      git:
          url: git://github.com/luanpotter/audioplayers.git
          ref: master
          path: packages/audioplayers

@wenxiangjiang
Copy link
Contributor Author

@AhmedNourJamalElDin It works well for me. Can you confirm whether the code has been updated to the latest?

@AhmedNourJamalElDin
Copy link

AhmedNourJamalElDin commented May 5, 2021

Yup

Error (1, -19)
Error (-38, 0)

@luanpotter
Copy link
Member

Reopening since it appears there is still some issues (might be fixed by @fdietze 's PR)

@luanpotter luanpotter reopened this May 15, 2021
@Marvin10193
Copy link

Any update regarding this issue?

@tamoyal
Copy link

tamoyal commented Jun 16, 2021

I'm still getting this issue as well:

E/MediaPlayerNative( 9491): error (1, -19)
E/MediaPlayer( 9491): Error (1,-19)
E/MediaPlayerNative( 9491): pause called in state 0, mPlayer(0x7f05f6e0)
E/MediaPlayerNative( 9491): error (-38, 0)
E/MediaPlayerNative( 9491): Attempt to perform seekTo in wrong state: mPlayer=0x7f05f6e0, mCurrentState=0
E/MediaPlayerNative( 9491): error (-38, 0)
2
E/MediaPlayer( 9491): Error (-38,0)

I also have not been able to figure out a workaround yet.

@lyseiha
Copy link

lyseiha commented Jun 17, 2021

any update yet bro?

@fdietze
Copy link
Contributor

fdietze commented Jun 17, 2021

Have you tried using this PR? #872

@tamoyal
Copy link

tamoyal commented Jun 20, 2021

@fdietze Well the maintainer seems to think that's not the issue but I'm certainly going to try it. I noticed the latest version had a potential fix for audio failing after repeat usage but I'm still seeing the errors come in after updating to the latest. I also wonder if just waiting 500ms after setting the url would work. That's ok for my use case, maybe not other people's

@Marvin10193
Copy link

I havent seen the problem again with the latest update, but no excessive testing has been done yet on my end

@tamoyal
Copy link

tamoyal commented Jun 20, 2021

@Marvin10193 I have done extensive testing and still get the issue. Does your build include the aforementioned PR?

@Marvin10193
Copy link

No, I did not include that PR.

@Gustl22 Gustl22 added the platform-android Affects the android platform label Sep 27, 2022
@Gustl22
Copy link
Collaborator

Gustl22 commented Sep 27, 2022

Can you reconfirm with audioplayers: ^1.1.0. This release also includes waiting for the prepare statement.

@Gustl22 Gustl22 added the waiting for report Wait for the author to respond to the conversation label Sep 27, 2022
@Marvin10193
Copy link

Hey,
sorry I am no longer working on the App as it only was semester task and currently I have no time to reconfirm. GL for the future though :)

@Gustl22 Gustl22 added AudioCache Concerning the AudioCache stale Automatically close this issue, if no activity is recognized labels Jan 21, 2023
@Gustl22
Copy link
Collaborator

Gustl22 commented Apr 24, 2023

Likely fixed with #1191

@Gustl22 Gustl22 closed this as completed Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AudioCache Concerning the AudioCache bug platform-android Affects the android platform stale Automatically close this issue, if no activity is recognized waiting for report Wait for the author to respond to the conversation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants