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

Asset sound only plays the first time #584

Open
rocboronat opened this issue Jul 15, 2021 · 6 comments
Open

Asset sound only plays the first time #584

rocboronat opened this issue Jul 15, 2021 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@rocboronat
Copy link

Flutter Version

Flutter 2.2.1 • channel stable

Lib Version

^3.0.3+3

Platform (Android / iOS / web) + version

Android

Describe the bug

If you play an asset sound, it works. But if you play it again, it doesn't sound anymore. It only plays the first time you opened it. Maybe something is leaking the audio file? By the way, I'm disposing the AudioPlayer when needed.

Small code to reproduce

player = AssetsAudioPlayer.newPlayer();
      player.open(
        Audio("assets/mp3/disconnect.mp3"),
        autoStart: true,
        showNotification: false,
        volume: 0.3,
      );
@rocboronat rocboronat added the bug Something isn't working label Jul 15, 2021
@rocboronat
Copy link
Author

I've also tried playing the sound manually when load finishes with the same result:

      player = AssetsAudioPlayer.newPlayer();
      player
          .open(
            Audio("assets/mp3/disconnect.mp3"),
            autoStart: false,
            showNotification: false,
            volume: 0.3,
          )
          .then((value) => player.play())
          .catchError((e) => print("ERROR playing the disconnecting sound"));

@rocboronat
Copy link
Author

rocboronat commented Jul 15, 2021

Playing it natively worked great 😯

MethodChannel(flutterEngine.dartExecutor.binaryMessenger, SOUND_CHANNEL).setMethodCallHandler { call, result ->
  val method = call.method

  if (method == "disconnect") {
    val mp: MediaPlayer = MediaPlayer.create(this, R.raw.disconnect)
    mp.start()
    mp.setOnCompletionListener {
      mp.release()
    }
  }
}

@kalismeras61
Copy link
Collaborator

Can you try Audio.file instead of using only Audio. and open method is future use await for initializing correctly.

Here is the edited your code.

  await player
          .open(
            Audio.file("assets/mp3/disconnect.mp3"),
            autoStart: false,
            showNotification: false,
            volume: 0.3,
          )
          .then((value) => player.play())
          .catchError((e) => print("ERROR playing the disconnecting sound"));

@rocboronat
Copy link
Author

I'll try! :·)

@BadReese
Copy link

I'll try! :·)

and ?

@rocboronat
Copy link
Author

Never did 😅 I ran it natively and my iOS colleague did it too. Sorry for the broken expectations! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants