QNimate

  • CoursesVideos
  • WP PremiumPlugins
  • DemosLab
  • Home
  • QIdea
  • QTrack
Home Carbon Ads Find Recorded Audio File Location in Cordova

Find Recorded Audio File Location in Cordova

Many people use the Media Plugin to record audio in cordova apps. Here is an sample code that shows how to record:

var extension = null;

document.addEventListener("deviceready", function(){
         
    if(device.platform == "iOS")
    {
        extension = ".wav";
    }
    else if(device.platform == "Android")
    {
        extension = ".amr";
    }

}, false);

var audio = new Media("filename" + extension, function(e){console.log(e, "success");}, function(e){console.log(e, "error");});

//start recording
audio.startRecord();

//stop recording
audio.stopRecord();

In case you want to upload or manipulate the file after recording then here is the code to find the file location:

if(device.platform == "iOS")
{
    var path = cordova.file.tempDirectory;
}
else if(device.platform == "Android")
{
    var path = cordova.file.externalRootDirectory;
}

alert("File path is: " + path + "filename" + extension);

In iOS the file is stored in temporary directory. Files in this directory can be deleted by the operation system any time therefore its recommended to store files in documents directory using. Below code shows how to record and put file in documents directory:

var myMedia = new Media("documents://beer.mp3")

And then to find location of the file we can use cordova.file.documentsDirectory instead of cordova.file.tempDirectory.

Note: Make sure you have file plugin installed.

Jan 12, 2016Narayan Prusty
ES6 Reflect API TutorialPointing Domain to AWS Elastic Load Balancing
Comments: 2
  1. Farzad
    5 years ago

    Thanks, that really helped :)

    ReplyCancel
  2. Chris
    6 years ago

    Hello Sir,

    Thanks for this! You’ve helped me immensely to be able to find the location of recorded audio files for upload.

    Cheers!

    ReplyCancel

Leave a Reply Cancel reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

Narayan Prusty

I am a software engineer specialising in Blockchain, DevOps and Go/JavaScript. This is my personal blog where I write about things that I learn and feel interesting to share.

7 years ago 2 Comments Cordova
Share this
0
GooglePlus
0
Facebook
0
Twitter
0
Linkedin
Related Articles
  • Working with File System using Intel XDK
  • Push Notification in Intel XDK using Push Plugin
  • Retrieve Device Information Using Intel XDK
  • Record Microphone Audio using Intel XDK
  • Building Intel XDK APP for Adhoc and App Store
Our Sponsor
My Books

2014 - 2015 © QNimate
All tutorials MIT license