Issue with playing multiple sounds

Hi,

I have a bunch of mp3 sound file snippets (~ 40, size ~20K) on my webspace, which I want to play with via the app in a controlled sequence. Loading and saving these files works fine.

I use the sound component to play those files. What I noticed is that when I set up a loop
with (.. pseudo code ;o)
for each soundfile_n in soundfiles
{
set.sound.source = soundfile_n
call sound.play
}
I get timing issues when playing the files, sometimes 703 error.

A workaround seems to be a previous initializing
for each sound in sounds
{
set.sound.source = soundfile_n
}

After this playing the sounds in a loop works fine most of the times, but not always. It depends, if the call sound.play is placed in a timer loop or in a procedure called from the timer loop. (Second way yields to a 703 error, but only in the first run of the loop).

Here the block diagramm

and aia file
play_sound_web_file.aia (18.1 KB)

..

Any hints are appreciated very much.
Thanks - Thomas

You are using the sound component.

The Player component has events that fir after reaching the end of the current sound file.

Combined with lists of sounds this avoids overlap.

Sample project using text to speech but same idea ...

Thanks AGB! But I don't think the problem is related to overlaps. I use 5 sound components and each mp3 snippet of the sequence is assigned to a new sound component (modulo 5 .., see the routine clock1.timer in my example). It seems, that a call of the set.Sound.Source needs "some time" until the sound component is available and the call Sound.Play succeeds without error: After a first run of the loop with an "error 703: unable to play soundfile x .." the next run of the loop works fine ..
Even stranger is that this error only occurs, when I put the set Source and call Sound.Play in a separate procedure outside the clock1.timer loop

Is there a general mistake of my code in handling sound playing?

This is a long standing requirement for sound components.

They need to be told their sound file names ahead of time, as a sort of "rehearsal" to save time later when they are asked to play the sounds/music files.

I don't have a FAQ for this.

Searching for '703' here might yield more information.

Let me suggest you to download those sound snippets into the ASD - application specific directory on first run of your app and play them from there...

Alternatively upload the sound snippets into the assets of your app...

Taifun

Thanks Taifun!

  1. I modified the Web1.ResponseFileName with a PATH as you suggested on http://puravidaapps.com/filebyfile.php When I look at the filename of the stored file I get something like /storage/emulated/0/PATH/soundfile.mp3 So it seems, that the file is not stored on the sd card in contrast to what you say on filebyfile.php.
    On https://appinventor.mit.edu/explore/ai2/concepts/images-and-sounds.html
    they say:
    ".. App Inventor doesn't (yet) include any way to store files on the SD card. .."
    Issue "cannot play soundfile .." is still the same on the first run of the loop

  2. I would like to avoid to upload the sound snippets to the assets in my app. First I won't to be more flexibel by just uplaoding new sounds to the webspace without changing the app code. Second I tried this method and experienced the same "cannot play soundfile" issue when I increased the number of sound components above 32(?) May be this (32) happened by chance or is related to the app inv coding structure.

To me it seems, that there is something missing like a Call Back Event Handler
"when set sound.Source.completed" (-> call sound.Play)
Or am I missing something completely?

Any additional suggestions for a workaround are highly appreciated.
(By the way: to get an idea what I like to achieve: beta mbits on google play)

Thomas

Post the relevant blocks and / or create a small (as simple as possible) test app (aia) that shows / reproduces your problem.

To download the sound files without READ_ / WRITE permissions to the ASD and play them from there, you can also use this extension:

@Anke please have a look at the aia file and the block image in my first post. Please have a look at clock1.Timer, the procedural call of set sound.Source followed by the call Sound. The issue does not always reproduce. I just experienced the error appearing after opening a second app on my mobile. It seems to be related the timing and memory allocation setting. After a set sound.source the call sound is not always available at once. Please reread my previous post.
Thanks - Thomas

we are talking here about the internal (emulated) sdcard and not about the external (removable) sdcard

If you are asking for help, I recommend you to make it as easy for others to be able to help you ...
You probably will get more feedback then...

which means in your case post a screenshot of your relevant blocks...

To download the aia file, upload it to App Inventor, open it, do some bug hunting for you, etc... this takes time, and most people will not do that...
Thank you.

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

1 Like