Quantcast
Viewing all articles
Browse latest Browse all 8068

Microphone doesn't work ?

Hi guys, i'm new to titanium and i try to record my voice and show the recording. I use the ios simulator for test, don't know if the problem come from it. Just have a simple button, when i click on it i want record. Nothing happen for the moment...

thx for the help.

Here the cod

var win = Titanium.UI.currentWindow;
 
Titanium.Media.audioSessionMode = Ti.Media.AUDIO_SESSION_MODE_PLAY_AND_RECORD;
 
var APP_DATA_DIR = Ti.Filesystem.applicationDataDirectory;
 
var recording = Ti.Media.createAudioRecorder({
    format: Ti.Media.AUDIO_FILEFORMAT_WAVE,
 });
 
 
var RecordBtn = Titanium.UI.createButton({
    title:'Record',
    top:350,
    width:120,
    height:120,
    font:{fontFamily:'Arial',fontWeight:'bold',fontSize:14,color:"black"}
});
RecordBtn.addEventListener('click', function(e)
    {
        if (recording.recording)
        {
            var buffer = recording.stop();
            var file = Ti.Filesystem.getFile(APP_DATA_DIR, new Date().getTime() + '.wav');
            file.remoteBackup = true;
            file.write(buffer);
            loadExistingAudioFiles();
            RecordBtn.title = "Start Recording";
            e.source.image = '../mic.png';
 
        }
        else
        {
            e.source.image = '../microphone.png',
            RecordBtn.title = "Stop Recording";
            recording.start();
        }
    });
win.add(RecordBtn);
 
function loadExistingAudioFiles() {
    var dir = ti.Filesystem.getFile(APP_DATA_DIR);
    var files = dir.getDirectoryListing();
    var tableData = [];
    for (var i = 0; i < files.length; i++) {
        var recorder = ti.Filesystem.getFile(APP_DATA_DIR, files[i]);
        var ts = newDate(recorder.createTimestamp());
        var rowLabel =
        String.formatDate(ts, 'medium') + '-' +String.formatTime(ts);
        var row =
        Ti.UI.createTableViewRow({
            title: rowLabel,
            color: '#404040',
            className : 'recorder',
            font: { fontSize: '24sp', fontWeight: 'bold'},
            fileName: APP_DATA_DIR + '/' + recorder.name
        });
        tableData.push(row);
    }
    table.setData(tableData);
}

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>