Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Soundboard, saving sounds to SD from app

IS it possible to save sounds to the SD card that are attached to buttons in the app? on the android phone.
so they can set it as a ring tone of notification.

i found this
but it relates to saving images not sounds
is it about the same?

So for my first app i made a soundboard with sounds my friends and I made, that we could use when hanging out.

this is what i did:

I made buttons then on 'click' functions that played a sound when clicked on

i had trouble when you put the phone into landscape that the buttons were cut off
so i found a way to make a scrollable view
and createview

then adding the view to the scroll view
and adding each button to the view

and it works, it scrolls perfectly

if anyone has any suggestions to make this flow more smoothly i'd love to hear it. I am here to learn.

again you guys have been so helpful
i am addicted to This stuff now
if anyone wants to download my app and check it out for some constructive criticism i uploaded it here


— asked September 26th 2010 by Luke Haviland
  • android
  • save
  • soundboard
  • sounds

3 Answers

  • okay, does anyone know if this is even possible in Titanium?
    or can I create a custom function to handle it?

    — answered September 27th 2010 by Luke Haviland
  • so i've been trying to save the sound file using the Filesystem.get

    anyone know if this will work, i cant seem to get it to work at all.

    but1.addEventListener('dblclick', function(e)

    var saves = Titanium.Filesystem.getFile
    (Titanium.Filesystem.resourcesDirectory, 'eh1.wav');
    var dir_target = Ti.Filesystem.externalStorageDirectory;
    var file_target = Ti.filesystem.getFile(dir_target,eh1.wav);
    if (file_target.exists()) {file_target.deleteFile();}


    — answered September 27th 2010 by Luke Haviland
    1 Comment
    • you need to use file_target.write, not Titanium.Filesystem.write

      — commented September 28th 2010 by Don Thorp
  • Im not sure if you are still looking for this answer, but this is how I have done sound saving myself, I have tested it on 5 different phones with 4 different size SD cards:
    It is heavily commented to show what almost every line does. Hopefully this can be used by more people to show how this is done easier.

    var data = [
    {name:'For the Ancients', sound:'sound_immortal_atk_1', type:'.ogg'}
    //name is what is saves as and what shows when double clicked
    //sounds is the name of the sound in the resource folder (sound_immortal_atk_1.ogg)
    //type is the file type of the sound being used (sound_immortal_atk_1.ogg)
    //all the above sets the sound information that is going to be used.
    //I put the following into a double click action for a button I am using, if you don't know how to use even listeners, learn that first!
    if (Ti.Filesystem.isExternalStoragePresent) { //checks to make sure sdcard is present.
                dbRootPath = Titanium.Filesystem.resourcesDirectory + 'mp3/'+data[t].sound+data[t].type; //sets the variable of the folder and file location of the sound wanting to be saved.
        file_loc = Titanium.Filesystem.getFile(dbRootPath); //gets the folder info of the sound wanting saved
        save_image = file_loc; //sets the old image to a variable
        result = '0'; //just to get the result variable set as something.
        result1=false; //Changes to true if the file is correctly saved, other wise doesn't change.
                sdcard=Titanium.Filesystem.externalStorageDirectory //gets the directory of the sdcard, testing if I can just use /sdcard/ to get root of the sd card, so far, nothing works but this.
                scheck=Ti.Filesystem.getFile(sdcard + 'notifications/'); //used to check to make sure the new folder exists
                scheck.createDirectory(); //creates the new folder if it doesn't exist, this prevents errors when saving to a non existant folder (tested in 1.7.2, no folder=FAIL)
                new_file=Titanium.Filesystem.externalStorageDirectory + 'notifications/'+data[t].name+data[t].type //sets where the new file should be placed.
                f = Ti.Filesystem.getFile(new_file); //gets the directory of the new file
              if(file_loc.exists()==true) { //Checks to make sure the resource file exists (The sound being copied)
                result1 = f.write(save_image);  //writes the sound to the notifications folder under the app folder.
                result= 'Saved Notification as:   '+data[t].name  //sets a variable to what the new sound was saved as
              } else { //if the resource file doesn't exist it lets the user know in a nice alert instead of a nasty looking error
                  result = "App Resource File Doesn't Exist"; //Lets the user know the sound doesn't exist in the app, this is so if the sound is missing, the app doesn't crash.
             alert(result); //displays the alert, rather is be telling where the new sound is, or saying the resource doesn't exist.
         //alert(result1); remove // to show if the file was saved correctly, true:yes, false:no
               } else {
        alert("There is no SD card which is needed to save this sound."); //Shows alert if no SD card is present, to avoid error and force closes.
    — answered October 19th 2011 by Hackerz Games
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.