Channel: Appcelerator Developer Center Q&A Tag Feed (device)
Viewing all articles
Browse latest Browse all 250

How to record and store an audio file and a unique identifier for that file on device (iPhone/iPad)


Hello, I want to record an audio file (5 seconds of voice message), then store it on my device as a file and create at the same time a key of an object that I store in Properties, that let me retrieve the sound at a later time.

With this code I should record:

recordBtn.addEventListener("click", function(e) {
        var currentSessionMode = Titanium.Media.audioSessionMode;
        Titanium.Media.audioSessionMode = Ti.Media.AUDIO_SESSION_MODE_PLAY_AND_RECORD;
        var recording = Ti.Media.createAudioRecorder();
        recording.compression = Ti.Media.AUDIO_FORMAT_ULAW;
        recording.format = Ti.Media.AUDIO_FILEFORMAT_WAVE;
        var rec = Titanium.Filesystem.getFile(getScrollableViewStatus() + '.wav');
        setTimeout(function() {
            var recordedFile = recording.stop();
            var currentKey = getScrollableViewStatus();
            var currentValue = rec.nativePath;
            var obj = Ti.App.Properties.getObject("sounds")||{};
            var tempObj = obj;
            tempObj[currentKey] = currentValue;
            Ti.App.Properties.setObject("sounds", tempObj);
            // test play
            var o2 = Titanium.App.Properties.getObject("sounds");
            var k = o2[currentKey];
            var fileToPlay = Titanium.Filesystem.getFile(k);
            var sound = Titanium.Media.createSound({
                url : fileToPlay
        }, 5000);
At the moment this fails without returning any kind of error. Could you help me understand what I'm doing wrong?

Viewing all articles
Browse latest Browse all 250

Latest Images

Trending Articles

Latest Images