xcode - ionic Cordova Failed recording audio on IOS using Media plugin -
i'm working on ionic app , need record audio files , used cordova-plugin-media , worked fine android when tried on ios error :
{"message":"failed start recording using avaudiorecorder","code":1}
here code :
var extension = '.wav'; var name = 'filename'; var audio = null; var filepath; $scope.startrecording = function() { name = utils.generatefilename(); if(device.platform == "ios") { //var path = "documents://"; //var path = cordova.file.documentsdirectory; //var path = cordova.file.cachedirectory; var path = cordova.file.datadirectory; path = path.replace("file:///", "cdvfile://"); } else if(device.platform == "android") { var path = cordova.file.externalapplicationstoragedirectory; } var filename = name + extension; filepath = path + filename; audio = new media(filepath, function(e){console.log(e, "success media");},function(e){console.log(e, "error");}); audio.startrecord(); }; $scope.sendaudiomsg = function() { audio.stoprecord(); audio.release(); };
when console log path :
cdvfile://var/mobile/containers/data/application/f47a76ad-e776-469f-8efa-85b0a0f14754/library/nocloud/djzsapeu6k16hv7egrd06l29njzcocvzhcutrcjeditcf7uungmchchecwfgls3v88p85ij0nukv0kvagevbgh3lwwsefmao8unq.wav
can 1 me??
try following android.
var path = "android/data/"+your_app_id+"/files/"+filename+".wav"; var mymedia = new media(path, success, error); mymedia.startrecord();
to access file after done recording
var path = cordova.file.externalapplicationstoragedirectory+"files/"+filename+".wav"; var mymedia1 = new media(path, success, error); mymedia1.play();
your_app_id com.test.app
ios, see following
var filename = "myrec.wav"; var mymedia = new media(path, success, error); mymedia.startrecord();
to access file
window.requestfilesystem(localfilesystem.temporary, 0, function (filesystem){ filesystem.root.getfile(filename, null, function (fileentry){ fileentry.file(function onfileentry(file){ // file actual recorded file, path , play or base64 string var reader = new filereader(); reader.onloadend = function(evt) { evt.target.result; // base64 string }; reader.readasdataurl(file); }, error); }, error); }, error);
Comments
Post a Comment