native-audio icon indicating copy to clipboard operation
native-audio copied to clipboard

Loop function does not play the audio, only sets loop variable

Open parolaraul opened this issue 1 year ago • 3 comments

Confusing documentation / Wrong behavior

I added this library to my project and I found out that my audio file was not being played. I thought it was due to the file location and the "assetPath" variable, buy I realized it was caused by a "bug" in the .loop() method I was calling. I was expecting for the audio to reproduce with the loop call, but this was not the actual behavior. Its confusing and it does not correspond with the documentation:


/**

  • This method will loop the audio file for playback.
  • @param assetId - identifier of the asset
  • @returns void */ NativeAudio.loop({ assetId: 'fire', });

I would suggest calling the play() method in the AudioAsset.java file after setting the loop variable or fixing the documentation.

https://github.com/capacitor-community/native-audio/blob/8cfe67ba954748ae54aab8e6394757d65125b493/android/src/main/java/com/getcapacitor/community/audio/AudioAsset.java#L105

STR:

  • Preload an audio file with an assetId (NativeAudio.preload())
  • Call the loop function with the same assetId.

Expected behavior: The audio file will be reproduced in loop mode.

Actual behavior: Nothing happens after loop is invoked.

parolaraul avatar Sep 13 '23 10:09 parolaraul

Yeah, it was a bit confusing for me too. A good solution would be for loop function to check if the audio file is already being played and if not start playing it.

orhan-swe avatar Nov 18 '23 11:11 orhan-swe

Have you found a solution for this bug?, I need this method. Apparently it works well on an HTML page, but on Android nothing happens, nor does it show an error.

rondybrandao avatar Dec 28 '23 15:12 rondybrandao

@rondybrandao First you call preload(), then you call play(), now music should start playing, and then you call loop(), so now it will also loop.

orhan-swe avatar Dec 29 '23 06:12 orhan-swe