Cannot stop recording audio in KitchenSink and my app

You must Login before you can answer or comment on any questions.

If I fire up KitchenSink on iPhone and goto Phone Tab, Sound, Record and hit Start Recording...I am unable to stop the app recording, I hit Stop Recording and the time continues counting. My app has a function to record audio loosely based on the Kitchen Sink code and it does the same.

Is this a bug? Is there any way to stop the thing recording as it just goes on and on and on. I don't want to remove a very popular feature of my app but I cannot see a fix if the Kitchen Sink code doesn't work either, anyone know?

— asked 10 months ago by Stephen Page
6 Comments
  • Missing from your question are a number of important pieces of information. I suggest you take a look at the Using Questions and Answers article, specifically the Q&A Question Checklist. The missing information is critical to reproducing problems in a test environment and often indicates other factors that cause the undesirable outcome you are experiencing.


    Specifically absent are your environment details, the SDK you are using, the hardware you are testing on, and code snippets detailing how you are calling Ti.Media.AudioRecorder

    — commented 10 months ago by Stephen Feather

  • Ti SDK is 2.1.1.GA, Testing on the iPhone 4 (not S), My code is irrelevant as it fails in the code I was given (below) AND with Kitchen Sink, so its more than just my code at issue here, hence why I didn't supply it (I normally do)

    — commented 10 months ago by Stephen Page

  • I've just upgraded XCode and am building to iOS 5.1 and my all aslo fails for recording. This is with I've attempted to build using Ti 1.8.2 through 2.1.2 and none of them work.

    — commented 9 months ago by Sosh Howell

  • Show 3 more comments

7 Answers

Answered here.

— answered 10 months ago by David Bankier
answer permalink
5 Comments
  • I am hoping this works (looks like it will) as every tried so far could not replicate it.

    — commented 10 months ago by Malcolm Hollingsworth

  • That is to do with PLAYING a sound, I am talking about RECORDING a sound. Playing works fine, recording does not.

    — commented 10 months ago by Stephen Page

  • Judging by your error logs below, e.g.

    Error: AudioFileCreateWithURL failed

    and

    Symbol not found: ___CFObjCIsCollectable

    it definitely relates. Try it on a device and prove me wrong.

    — commented 10 months ago by David Bankier

  • Show 2 more comments

All this used to work great. But now I keep getting a file size of 0 and sometimes the following error:

AudioFileCreateWithURL failed (-50)

I'm using Xcode 4.4.1 and Titanium SDK 2.1.2.GA

I don't know what is going on...

I'm having the same issue. I've isolated the problem to the line recording.start(); My setup is 2.1.3RC w/ XCode 4.5, iOS 6 simulator. This used to work fine before upgrading to the latest sdk & xcode.

I haven't tried w/ an actual iOS 6 device as I don't want to loose Google Maps on my phone :/

It seems you'll need to update your Xcode in order to fix it.

Quoting: http://stackoverflow.com/questions/7961840/what-does-this-gdb-output-mean

"This issue is finally fixed within Xcode Version 4.5 (4G182), iOS SDK 6.0. Note: The issue persists even in Xcode Version 4.5 when used in conjunction with the iOS 5.1 (or lower) simulator."

— answered 4 months ago by Joseandro Luiz
answer permalink
2 Comments
  • I just updated my XCode to the all the latest and I'm sill getting the recording fail on the simulator. Did this fix it for you?

    — commented 4 months ago by Kosso .

  • I have only tried to record it, but it seems the output I was saw was just garbage. I tried the Kitchen Sink example but it also failed.

    Do you know if there is a ticket opened for this issue?

    — commented 4 months ago by Joseandro Luiz

Hi Stephen

Without a code snippet I am going to have to guess the detail of your bug.

Having reviewed the Kitchen Sink code (v2.1.1) the audio recorder, plays, pauses and stops.

The code from their example (shortened) to achieve this would be.

To play

var sound = Titanium.Media.createSound({sound:file});
sound.play();
To stop
sound.stop();
sound.release();
sound = null;
They really want this to stop - with three separate commands :)

These worked fine in my tests.

If this has not given you enough information, provide a code snippet I will try and find an answer for you.

— answered 10 months ago by Malcolm Hollingsworth
answer permalink
10 Comments
  • You've told me how to stop PLAYBACK but what I asked about was hot to stop RECORDING, that does not appear to work even in Kitchen Sink.

    — commented 10 months ago by Stephen Page

  • Sorry - been at this a while.

    I am going to put together a test app and see what happens.

    — commented 10 months ago by Malcolm Hollingsworth

  • I have created a test app and it works fine. The code is readable but not pretty, but I have included it at the bottom of this comment for reference.

    Setup stuff

    var recording = Ti.Media.createAudioRecorder();
    recording.compression = Ti.Media.AUDIO_FORMAT_ULAW;
    recording.format = Ti.Media.AUDIO_FILEFORMAT_WAVE;
    var file, timer, duration = 0;;
    I started recording with
    recording.start();
    I stopped it using
    file = recording.stop();
    Ti.API.info('file size', file.size); // shows size of audio file in bytes
    // extra goes here
    I also added this to where is says 'extra'
    var newDir = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory);
    var newFile = Titanium.Filesystem.getFile(newDir.nativePath,'audio.wav');
    newFile.write(file);
    This saves the file to the local file system.

    I created a test button to play this file back.'Test Playback' - you can see that in the code below.

    This is raw code - no re-factoring has occurred so do not judge me! Simply add this to a project with at least a reference to a window called win. It does however include all the captions for level and volume etc.

    function showLevels()
    {
        var peak = Ti.Media.peakMicrophonePower;
        var avg = Ti.Media.averageMicrophonePower;
        duration = duration + 1;
        label.setText('duration: ' + duration + ' seconds\npeak power: ' + peak + '\navg power: ' + avg);
    }
     
    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 file, sound, timer, duration = 0;;
     
     
    function lineTypeToStr() {
        var type = Ti.Media.audioLineType;
        switch (type) {
            case Ti.Media.AUDIO_HEADSET_INOUT:
                return "headset";
            case Ti.Media.AUDIO_RECEIVER_AND_MIC:
                return "receiver/mic";
            case Ti.Media.AUDIO_HEADPHONES_AND_MIC:
                return "headphones/mic";
            case Ti.Media.AUDIO_HEADPHONES:
                return "headphones";
            case Ti.Media.AUDIO_LINEOUT:
                return "lineout";
            case Ti.Media.AUDIO_SPEAKER:
                return "speaker";
            case Ti.Media.AUDIO_MICROPHONE:
                return "microphone";
            case Ti.Media.AUDIO_MUTED:
                return "silence switch on";
            case Ti.Media.AUDIO_UNAVAILABLE:
                return "unavailable";
            case Ti.Media.AUDIO_UNKNOWN:
                return "unknown";
        }
    }
     
     
     
    var btnRecord = Titanium.UI.createButton({
        height: 40,
        top: 20,
        title: 'Record',
        width: 200
    });
    win.add(btnRecord);
    btnRecord.addEventListener('click', function (e) {
        if (recording.recording) {
            Ti.API.info('record', 'stopped');
            file = recording.stop();
            Ti.API.info('file size', file.size);
            var newDir = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory);
            var newFile = Titanium.Filesystem.getFile(newDir.nativePath,'audio.wav');
            newFile.write(file);
            btnRecord.title = "Record";
            Ti.Media.stopMicrophoneMonitor();
            clearInterval(timer);
        } else {    
            Ti.API.info('record', 'recording');
            if (!Ti.Media.canRecord) {
                Ti.UI.createAlertDialog({
                    title:'Error!',
                    message:'No audio recording hardware is currently connected.'
                }).show();
                return;
            }
            btnRecord.title = "Stop";
            recording.start();
            Ti.Media.startMicrophoneMonitor();
            duration = 0;
            showLevels();
            timer = setInterval(showLevels,1000);
        }
    });
     
    var label = Titanium.UI.createLabel({
        text:'Levels here',
        top:150,
        color:'#999',
        textAlign:'center',
        width:'auto',
        height:'auto'
    });
    win.add(label);
     
    var linetype = Titanium.UI.createLabel({
        text: "audio line type: "+lineTypeToStr(),
        bottom: 20,
        color:'#999',
        textAlign:'center',
        width:'auto',
        height:'auto'
    });
    win.add(linetype);
     
    var volume = Titanium.UI.createLabel({
        text: "volume: " + Ti.Media.volume,
        bottom: 70,
        color: '#999',
        textAlign: 'center',
        width: 'auto',
        height: 'auto'
    });
    win.add(volume);
     
    Ti.Media.addEventListener('linechange', function (e) {
        linetype.setText("audio line type: " + lineTypeToStr());
    });
    Ti.Media.addEventListener('volume', function (e) {
        volume.text = "volume: " + e.volume;
    });
     
    var btnTest = Titanium.UI.createButton({
        height: 40,
        bottom: 100,
        title: 'Test Playback',
        width: 200
    });
    win.add(btnTest);
    btnTest.addEventListener('click', function (e) {
        //var audiofile = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory, 'cricket.wav');
        var audiofile = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'audio.wav');
        var testsound = Titanium.Media.createSound({url:audiofile});
        testsound.play();
    });

    — commented 10 months ago by Malcolm Hollingsworth

  • Show 7 more comments

Same problem

— answered 8 months ago by Max Wang
answer permalink
2 Comments
  • me too

    — commented 4 months ago by Paulo Filipak

  • Whenever i check the recording object for the property recording, it never seems to return true. if I bypass that check..and go straight and call stop()......i get a file size of 0

    Any thoughts??

    — commented 3 months ago by Peter Ladis

Your Answer

Think you can help? Login to answer this question!