Search code examples
iphonefile-uploadtitaniumvoice-recording

Titanium Convert TiFile Object to TiFileSystemFile Object


How to save the recorded audio file which is recorded using sound_record.js from Titanium KickenSink Source.

We have,

var file // global variable.

file = recording.stop(); // file will have recorded content which we will convert into media.sound in order to play.

var newDir = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory,'audioclips');
Ti.API.info("Created mydir: " + newDir.createDirectory());

var newFile = Titanium.Filesystem.getFile(newDir.nativePath,'newfile.wav'); 
newFile.write(file.read());

But i am able to save the file which is recorded?

I am not getting how to save this recorded file, I dont knw where i am going wrong.

Please Help, Thanks in Advance.


Solution

  • I am guessing your are having problem with saving the file. In last line just change

    newFile.write(file.read());
    

    to

     newFile.write(file);
    

    This should do the trick for you. Hope this helps.

    Edited:

    For saving the file try this code:

    var newFile =Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'your_file.wav');
    
    // Write the data.
    newFile.write( file );