Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 具有上传功能的录音机-为什么";var myRecording“;不包含任何录音?_Javascript_File Upload_Makefile_Audio Recording_Titanium Mobile - Fatal编程技术网

Javascript 具有上传功能的录音机-为什么";var myRecording“;不包含任何录音?

Javascript 具有上传功能的录音机-为什么";var myRecording“;不包含任何录音?,javascript,file-upload,makefile,audio-recording,titanium-mobile,Javascript,File Upload,Makefile,Audio Recording,Titanium Mobile,我正在开发一个简单的音频录制代码,该代码可以将录制的音频上传到另一个上传功能——上传到web服务器。该代码基于KitchenSinks音频记录器。问题是“var myRecording”似乎不包含记录。我的代码遗漏了什么?我如何获取录音文件、存储它,然后再次获取并上传它?有录音机/上传机的例子吗? 以下是我的一些代码: var myRecording = null; var buttonUpload = Titanium.UI.createButton({ title: 'Upload

我正在开发一个简单的音频录制代码,该代码可以将录制的音频上传到另一个上传功能——上传到web服务器。该代码基于KitchenSinks音频记录器。问题是“var myRecording”似乎不包含记录。我的代码遗漏了什么?我如何获取录音文件、存储它,然后再次获取并上传它?有录音机/上传机的例子吗? 以下是我的一些代码:

var myRecording = null;

var buttonUpload = Titanium.UI.createButton({
    title: 'Upload Recording'
});

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;

Ti.Media.addEventListener('recordinginput', function(e) {
    Ti.API.info('Input availability changed: '+e.available);
    if (!e.available && recording.recording) {
        b1.fireEvent('click', {});
    }
});

var file;
var sound;

var b1 = Titanium.UI.createButton({
    title:'Start Recording',
    width:200,
    height:40,
    top:20
});

b1.addEventListener('click', function(){
    if (recording.recording)
    {
        file = recording.stop();
        var f = Ti.Filesystem.getFile(file.path);
        var m = f.move(Ti.Filesystem.applicationDataDirectory + '/audio.m4a');
        b1.title = "Make New Recording";
        b2.show();
        pause.hide();
    }
    else
    {
        if (!Ti.Media.canRecord) {
            Ti.UI.createAlertDialog({
                title:'Error!',
                message:'No microphone is found.'
            }).show();
            return;
    }
        b1.title = "Stop Recording";
        recording.start();
        b2.hide();
        pause.show();       
    }
});
win.add(b1);

var pause = Titanium.UI.createButton({
    title:'Pause Recording',
    width:200,
    height:40,
    top:80
});
win.add(pause);
pause.hide();

pause.addEventListener('click', function(){
    if (recording.paused) {
        pause.title = 'Pause Recording';
        recording.resume();
    }
    else {
        pause.title = 'Continue Recording';
        recording.pause();
    }
});

var b2 = Titanium.UI.createButton({
    title:'Play recording',
    width:200,
    height:40,
    top:80
});

win.add(b2);
b2.hide();
b2.addEventListener('click', function(){
    if (sound && sound.playing)
    {
        sound.stop();
        sound.release();
        sound = null;
        b2.title = 'Play recording';
    }
    else
    {
        Ti.API.info("recording file size: "+file.size);
        sound = Titanium.Media.createSound({sound:file});
        if(Ti.Platform.osname == 'iphone'){
        win.rightNavButton = buttonUpload;
        }else{
        buttonUpload.right = 20;
        buttonUpload.top = 20;
        }
        sound.addEventListener('complete', function(){
            b2.title = 'Play recording';
        });
        sound.play();
        b2.title = 'Stop Playback';

    }
});

buttonUpload.addEventListener('click', function(e){
        myRecording = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, '/audio.m4a');
        if(myRecording != null) {
        myPostFunction();
        }else{
        alert('Nothing is recorded!');
        }
});

function myPostFunction(){ continues here…

您是否检查了控制台中的错误消息?是否在设备上进行测试?这在模拟器上不起作用。我正在iPhone设备上测试它,上传进度正常,但速度太快了,我得到的信息是服务器上没有保存任何东西。我怀疑“var myRecording”是空的或没有录音,并且它没有找到或捕获我的音频。有没有其他方法可以从厨房水槽的录音机中获取音频?我找不到任何其他音频录制示例应用程序(iOS)可供学习。有你认识的人吗?