app-inventor

How to get sound duration in AppInventor?


Is it possible to obtain information on the duration (in milliseconds) of a sound file used in AppInventor, or does it have to be hardcoded (for example, 90000ms for song.mp3)?

I need that information to be able to set a looping background music with the clock component. The logic is that the TimerInterval property is set dynamically to chosen sound duration - it could be 60000ms if one song is chosen, it could be something else if another song is chosen, etc.


Solution

  • The built in Player component does not offer that feature but there is the Player extension, which offers a Duration property.

    However to be able to loop some music you do not need the duration of the music, just set property Loop of the built in Player component to true and the music loops automatically... btw. the extension also offers a Loop event in case you need it...