Mysterious file management

My project is simple:
1- Download an .mp3 file from a folder on Google Drive (Shared with anyone who has the link)
2- Play this .mp3 file with "Taifun Player".

I've seen problems with ASD from Android 10 and above.
However, I'm not sure this is my case (although it looks like it) because:
1- My phone is running Android 9
2- It works fine at first, and only after a (variable) number of reads of different files, I get an error message and no more readings.

On my complete application, I get the following message:
"Attempt to invoke virtual method 'void android.media.MediaPlayer.setAudioStreamType(int)' on a null object reference" "MIT App Inventor"

On a small test application (which uses the default "player" element instead of Taifun), I get the message:
error 702 unable to prepare /storage/emulated/0/Android/data/edu.mit.appinventor.aicompanion3/files

When my full application starts to bug, the small test application becomes unusable.
--> Disconnecting "ai compagnon" then reconnecting it changes nothing.

Everything recovers itself later... I don't know how.

I have the impression that it's a saturation problem, my application can no longer write my temporary file after a while... But I don't understand why, because I systematically overwrite the previous temporary file...
I went to check out this temporary file: it's fine on its own and it's light... (Some .mp3 are under 3 seconds long.)

Does anyone understand?

Have you got SaveResponse ticked in the Designer properties for your Web component? I do not see it in the blocks....

Yes, in my big project and in the little test project.
Capture d’écran du 2023-11-09 18-35-54

For your second error message, does it not show the filename at the end - just the path as you have shown ?

I must have forgotten to copy it because I typed it by hand while looking at the phone. I just reproduced the bug and it looks like this:

I just saw that I had forgotten the block that determines the name of the temporary file in my main code. :woozy_face:

I corrected.

However, bug remains...

My guess is that the setting of the player source requires a little bit of time before it is ready . Add a clock timer with an interval of 500ms, and put player start in the clock timer event. Start the clock in your current block, and stop the clock in the clock timer event.

Do you still get the error?

I did it:

Capture d’écran du 2023-11-09 19-22-41

But the bug remains...

When my important program bugs, I disconnect "AI companion" because it crashed anyway. When I reconnect "AI companion" with my little test program, it no longer works either.

Nearly, but you need to separate setting the source with starting playback with the clock timer. Like so:

If this works, then try reducing the timer interval to 250ms, or 100ms, and see if that works as well....

I improved my program as you suggested, but the bug remains... I also modified it so that it can reproduce the crash more easily. I created a list of sounds for my students to listen to (I'm an elementary school teacher). Every time "Télécharger mp3" is pressed, it plays the next file in the list. After 2 or 3 readings of the complete list (it takes a little time...) it no longer reads the mp3 and the error message returns. My entire class was a victim of this bug, so it's the problem is present with a fairly wide variety of Android...
Here's where to download my corrected test program:
https://drive.google.com/file/d/1wlic0EsmXS0ek-vg51y_rGDL_rrVMWxC/view?usp=drive_link

Some sounds last 1 min, others 1 second.

Please provide the aia project here, it is impossible to debug a compiled project.

I have been unable to replicate your issue in my tests

No issues / bug with your APK on Android 13. But all MP3 files are saved with the same file name:

So there is always only one MP3 file in the ASD, which is constantly being overwritten.
On which device with which Android version are you testing? Does the problem also arise with Companion?

Hello

> Please provide the aia project here, it is impossible to debug a compiled project.
Ok :
Essai_DL_mp3_V2.aia (4.5 KB)

> No issues / bug with your APK on Android 13.

I took notes: the bug comes back each time after reading my list of 14 mp3s two and a half times = after 35 mp3 readings in a row.

> But all MP3 files are saved with the same file name. So there is always only one MP3 file in the ASD, which is constantly being overwritten.

Yes, that's what I want. In the program that the children actually use, the links to the audios are given by QR codes that the children flash to listen to the audios. So, overwriting the downloaded files never overloads the parents' phone. This program that I am sending you is a smaller program that I use to isolate the bug.

> On which device with which Android version are you testing?

Android 9

But it should be noted that the application encountered the same problem for all 17 of my students' Android phones, of which there are probably some variety of versions.

> Does the problem also arise with Companion?

I did some tests, the bug appears in the same way whether with AI companion or with the installed application.

If I trigger the bug with the test app and then immediately try the children's app, it also gets stuck. If I trigger the bug with the children's app and launch it right after I launch the test app, it too is stuck.

Two things:

  1. Ensure that the player is stopped before fetching the next file ?

  2. Try deleting the MAELtemp.mp3 before downloading the next one ?

After a certain number (in my case 39) of downloads the MP3s are broken. This is why the error message occurs. I don't know if it's Google Drive, but I assume so. The problem arises with Companion & the APK.

In my case it is file number 39, but with another test it was 50.

1 Like

Although we would like to get to the bottom of the problem, I suggest zipping all MP3s (MP3.zip), downloading this file, unzipping it into the ASD and then playing the MP3s from there. (To relieve the memory, you can delete the files again at the end.)

1 Like

> I suggest zipping all MP3s (MP3.zip), downloading this file, unzipping it into the ASD

I can try that, however, this application if it works well should be used by other teachers who will find the process too complicated and ultimately will not use the application anymore.
I searched: it seems that Google Drive does not limit the number of downloads.

When the application my students use is blocked, so is the test application and vice versa. Could it be that Android itself considers this increase in downloads as abnormal behavior and blocks downloads?

This could also explain why the application starts working on its own after a while...

I just did a new test:

1- I downloaded / read files until they blocked (40 this time, but I replaced the long files with short ones...)
--> I get the same thing as Anke: corrupted file...

2- I sent myself the links of my list by WhatsApp: it manages to download and then read these same .mp3 files that MIT App Inventor is no longer able to download...

3- I go back to the test application: it can't read, I go back to WhatsApp, it can read...

So, I guess it's neither Google Drive nor Android itself...

> Ensure that the player is stopped before fetching the next file ?
I did it by hand, taking my time. So I think it was good.

> Try deleting the MAELtemp.mp3 before downloading the next one ?
I'll try that as soon as I have time.