Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Android / My Android app literally can't count

Author
Message
SomeOldDude
2
Years of Service
User Offline
Joined: 21st May 2022
Location:
Posted: 5th Sep 2022 18:39 Edited at: 6th Sep 2022 00:55
Update: I renamed the original 3 files back to their old filenames and suddenly the program sees them again. I now have 17 music files acknowledged by the program. Still, the question remains: why? Why does something as mundane as renaming a file suddenly prevent the app from even seeing it?







Okay, so I'm making a program with features including a) counting the number of files in a folder, and b) listing the names of those files on screen.

I started simple, with three files. And it worked. The app picked up on all three files, displayed their names on screen (and even loaded and played them, as they were music files).

But I've designed this thing to adapt to changes in the directory. So to really test it I used a file explorer to manually add 14 more music files, so the total should've been 17. So I closed the app and restarted it. Problem is: only fourteen files show up. What's missing? The original 3. All I did was add files to the directory and rename the original 3, and for whatever reason, the app started glossing over the original three files that it was picking up on just fine before. I even modified the loop to actually tell me how many files were in the directory and it says 14. The app literally just doesn't count these specific files. Anyone else run into stuff like this? I don't think renaming the original 3 files should've done anything because the code is designed to not even really be aware of the file names other than to search for them. I even tried uninstalling and reinstalling the app, and deleting all music files and copying them back in all at once. No change.

This is what I have so far. For the record, I'm trying to make a media player. I've only been seriously working on it for about a week. It should provide great help to anyone learning to access files on Android...
One last thing: any time I export the code into an .APK and install it on my phone, the first time it runs it always fails because it has to ask me permission to access files/folders. But I close it and run it again, and it's fine.


SetErrorMode(2)
SetScissor( 0,0,0,0 )
UseNewDefaultFonts( 1 )
requestpermission("WriteExternal")

rem figure out how many files are in the folder
amount# as integer
amount# = getrawfoldernumfiles(openrawfolder("raw:/sdcard/Music"))

rem make a list of files in the folder
dim tracklist$[amount#]
for a = 1 to amount#
tracklist$[a] = getrawfolderfilename(openrawfolder("raw:/sdcard/Music"),a-1)
next a

rem set track variable
track# as integer
track# = 1

gosub _nextsong

do
for a = 1 to amount#
print(tracklist$[a])
next a
print(amount#)
if getmusicplayingogg(1) = 0
track# = track# + 1
gosub _nextsong
endif
Sync()
loop

_nextsong:
if track# > amount# then track# = 1
if getmusicexistsogg(1) then deletemusicogg(1)
song$ = "raw:/sdcard/Music/" + tracklist$[track#]
loadmusicogg(1,song$)
playmusicogg(1)
return

Login to post a reply

Server time is: 2024-11-21 09:02:54
Your offset time is: 2024-11-21 09:02:54