Sound assets in project?

I posted something like this before, but I thought I’d clean it up a little. You can queue up multiple wav or mp3 files and download them. These examples are small wav files, so they download faster than you can queue them up. If you have larger mp3 files, then you can queue them up to download one by one. Just tap a file name to queue/download it. The files are saved in the Codea Dropbox folder. You can load them from the Dropbox folder into a projects Project folder. Open the project you want the files to go into. At the beginning of the program put sound() or music() statements. Then depending on what kind of file you downloaded, tap within the () of sound or music to show the asset list. Select Dropbox, then in the upper right, select Edit. Tap each file you want to move to the Project folder, then tap Add To at the lower right. Then tap the Project folder name. The files should be copied to the Project folder and can be Deleted from the Dropbox folder when done. Then remove the sound or music statement you added to the code. The tune table should contain the url of the file to download and the name you want to save it as. Include the .wav or .mp3 extension with the name.

PS. The files don’t show up in this code until you close and reopen it. They should show when you open the project you want to move them to.

displayMode(STANDARD)

function setup()
    rectMode(CENTER)  
    
    -- table of addresses and the names to save them as. 
    tuneTable={
        {"https://www.wavsource.com/snds_2020-06-10_7014036401687385/sfx/car_x.wav","carStarting.wav"},
        {"https://www.wavsource.com/snds_2020-06-10_7014036401687385/sfx/cork_pop_x.wav","corkPop.wav"},
        {"https://www.wavsource.com/snds_2020-06-10_7014036401687385/sfx/cuckoo_clock1_x.wav","cuckoo.wav"},}

    queTable={} -- table of files waiting to download
end

function draw()
    background(40, 40, 50)
    fill(255)
    text("Selection",100,HEIGHT-10)
    for a,b in pairs(tuneTable) do
        fill(255)
        rect(100,HEIGHT-40*a,200,30)
        fill(255,0,0)
        text(b[2],100,HEIGHT-40*a)
    end
    fill(255)
    text("To download",350,HEIGHT-10)
    for a,b in pairs(queTable) do
        text(tuneTable[b][2],350,HEIGHT-30*a-50)
    end    
    if #queTable>0 then
        if not downloading then            
            pos=queTable[1]
            downloading=true
            http.request(tuneTable[pos][1],didLoadMusic,notFound)
        end
        text("Downloading --  "..tuneTable[pos][2],WIDTH/2,100)
    end
end

function touched(t)
    if t.state==BEGAN then
        for z=1,#tuneTable do
            if t.x>0 and t.x<200 and 
                    t.y>HEIGHT-40*z-20 and t.y<HEIGHT-40*z+20 then
                table.insert(queTable,z)               
            end
        end
    end
end

function notFound()
    print("error with file..."..tuneTable[pos][1])
    downloading=false
    table.remove(queTable,1)
end

function didLoadMusic(data,status,headers)
    writeFile(tuneTable[pos][2],data)
    downloading=false
    table.remove(queTable,1)
end

function writeFile(fileName, data)
    print("begin write file")
    local file=os.getenv("HOME").."/Documents/Dropbox.assets/"..fileName
    local wFd, err=io.open(file, "w")
    if wFd==nil then
        print("Error creating file "..fileName.."\
\
Error: "..err)
    else
        wFd:write(data)
        wFd:close()
    end
    print("done writing  "..fileName)
end

OK, thanks…I finally got it, but I don’t even know how I figured it out…one more question or spot to show, when I get to the documents section, I have no buttons or arrow to go back…Is it just me ?..I get stuck right at the documents, then I have to close codea pgm down and restart over…

@kendog400 just tap outside the asset selector to close it. No need to reset program

I tried to tap everywhere, I think because I’m using an i-phone (6s), some of the screen is tucked away…I had an i-pad 5 long ago, but it became outdated, and codea PGM wouldn’t run, now i got I-pad everything runs but screen missing some realestate…