capacitor-audio-engine
Version:
High-quality audio recording Capacitor plugin with native iOS & Android support. Features pause/resume, microphone management, real-time monitoring, audio trimming, and comprehensive mobile audio recording capabilities.
2 lines (1 loc) • 8.6 kB
JavaScript
;var e,o,r,n=require("@capacitor/core");function s(e){if(!e.startsWith("data:"))return{isCompressed:!1,data:e,mimeType:"audio/m4a"};const[o,r]=e.split(",",2);return o.includes("lzfse:")?{isCompressed:!0,algorithm:"lzfse",data:r,mimeType:o.split(";")[0].replace("data:","")}:{isCompressed:!1,data:r,mimeType:o.split(";")[0].replace("data:","")}}exports.PermissionStatus=void 0,(e=exports.PermissionStatus||(exports.PermissionStatus={})).GRANTED="granted",e.DENIED="denied",e.DENIED_PERMANENTLY="denied_permanently",e.NOT_DETERMINED="not_determined",e.LIMITED="limited",e.RESTRICTED="restricted",e.REQUESTING="requesting",e.UNSUPPORTED="unsupported",exports.AudioPermissionType=void 0,(o=exports.AudioPermissionType||(exports.AudioPermissionType={})).MICROPHONE="microphone",o.NOTIFICATIONS="notifications",exports.WaveLevelEmissionInterval=void 0,(r=exports.WaveLevelEmissionInterval||(exports.WaveLevelEmissionInterval={}))[r.REALTIME=50]="REALTIME",r[r.VERY_FAST=100]="VERY_FAST",r[r.FAST=200]="FAST",r[r.MEDIUM=500]="MEDIUM",r[r.DEFAULT=1e3]="DEFAULT";const t=n.registerPlugin("CapacitorAudioEngine",{web:()=>Promise.resolve().then(function(){return a}).then(e=>new e.CapacitorAudioEngineWeb)});class i extends n.WebPlugin{async resetRecording(){throw console.warn("resetRecording is not supported on web platform. For web implementation, consider using MediaRecorder or WebAudio directly."),new Error("resetRecording is not supported on web platform")}async checkPermissions(){return console.warn("checkPermissions is not fully supported on web platform. For web implementation, consider using navigator.permissions.query API directly."),{granted:!1,status:exports.PermissionStatus.UNSUPPORTED}}async checkPermissionMicrophone(){return console.warn("checkPermissionMicrophone is not fully supported on web platform. For web implementation, consider using navigator.permissions.query API directly."),{granted:!1,status:exports.PermissionStatus.UNSUPPORTED}}async checkPermissionNotifications(){return console.warn("checkPermissionNotifications is not fully supported on web platform. Notifications not applicable for web audio recording."),{granted:!1,status:exports.PermissionStatus.UNSUPPORTED}}async requestPermissions(e){return console.warn("requestPermissions is not fully supported on web platform. For web implementation, consider using navigator.mediaDevices.getUserMedia API directly."),this.checkPermissions()}async addListener(e,o){console.warn(`${e} event is not supported on web platform. Callback will not be invoked. For web implementation, consider using MediaRecorder events directly.`);return{remove:()=>Promise.resolve()}}async isMicrophoneBusy(){throw console.warn("isMicrophoneBusy is not supported on web platform."),new Error("isMicrophoneBusy is not supported on web platform")}async getAvailableMicrophones(){throw console.warn("getAvailableMicrophones is not supported on web platform."),new Error("getAvailableMicrophones is not supported on web platform")}async switchMicrophone(e){throw console.warn(`switchMicrophone is not supported on web platform. Attempted to switch to microphone ID: ${e.microphoneId}`),new Error("switchMicrophone is not supported on web platform")}async removeAllListeners(){console.warn("removeAllListeners is not supported on web platform.")}async configureWaveform(e){var o;return console.warn("configureWaveform is not supported on web platform. Waveform data is not available for web recordings. Consider using MediaRecorder events and manual amplitude analysis."),{success:!1,configuration:{emissionInterval:null!==(o=null==e?void 0:e.EmissionInterval)&&void 0!==o?o:1e3}}}async destroyWaveform(){console.warn("destroyWaveform is not supported on web platform. No waveform resources to clean up.")}async preloadTracks(e){console.warn("preloadTracks is not supported on web platform. For web implementation, consider using HTML5 Audio API directly.");return{tracks:e.tracks.map(e=>({url:e,loaded:!1,duration:0,size:0,mimeType:"unknown"}))}}async playTrack(e){throw console.warn("playAudio is not supported on web platform. For web implementation, consider using HTML5 Audio API directly."),new Error("playAudio is not supported on web platform")}async pauseTrack(e){throw console.warn("pauseAudio is not supported on web platform. For web implementation, consider using HTML5 Audio API directly."),new Error("pauseAudio is not supported on web platform")}async resumeTrack(e){throw console.warn("resumeAudio is not supported on web platform. For web implementation, consider using HTML5 Audio API directly."),new Error("resumeAudio is not supported on web platform")}async stopTrack(e){throw console.warn("stopAudio is not supported on web platform. For web implementation, consider using HTML5 Audio API directly."),new Error("stopAudio is not supported on web platform")}async seekTrack(e){throw console.warn("seekAudio is not supported on web platform. For web implementation, consider using HTML5 Audio API directly."),new Error("seekAudio is not supported on web platform")}async skipToNext(){throw console.warn("skipToNext is not supported on web platform. For web implementation, consider using HTML5 Audio API directly."),new Error("skipToNext is not supported on web platform")}async skipToPrevious(){throw console.warn("skipToPrevious is not supported on web platform. For web implementation, consider using HTML5 Audio API directly."),new Error("skipToPrevious is not supported on web platform")}async skipToIndex(e){throw console.warn("skipToIndex is not supported on web platform. For web implementation, consider using HTML5 Audio API directly."),new Error("skipToIndex is not supported on web platform")}async getPlaybackInfo(){throw console.warn("getPlaybackInfo is not supported on web platform. For web implementation, consider using HTML5 Audio API directly."),new Error("getPlaybackInfo is not supported on web platform")}async destroyPlayback(){console.log("destroyPlayback called on web (no-op)")}async openSettings(){console.warn("openSettings is not fully supported on web platform. Showing alert with instructions.");alert('To manage app permissions:\n\n1. Click the lock icon in your browser\'s address bar\n2. Select "Site settings" or "Permissions"\n3. Adjust microphone and other permissions as needed\n\nOr access browser settings directly through the browser menu.')}async startRecording(e){return console.warn("startRecording is not supported on web platform."),{uri:""}}async stopRecording(){throw console.warn("stopRecording is not supported on web platform."),new Error("stopRecording is not supported on web platform")}async pauseRecording(){throw console.warn("pauseRecording is not supported on web platform."),new Error("pauseRecording is not supported on web platform")}async resumeRecording(){throw console.warn("resumeRecording is not supported on web platform."),new Error("resumeRecording is not supported on web platform")}async getRecordingStatus(){throw console.warn("getRecordingStatus is not supported on web platform."),new Error("getRecordingStatus is not supported on web platform")}async trimAudio(e){throw console.warn("trimAudio is not fully supported on web platform. Consider using Web Audio API for client-side audio processing."),new Error("trimAudio is not supported on web platform")}async getAudioInfo(){throw console.warn("getAudioInfo is not supported on web platform."),new Error("getAudioInfo is not supported on web platform")}async micAvailable(){try{if("enumerateDevices"in navigator.mediaDevices){const e=await navigator.mediaDevices.enumerateDevices();return{isAvailable:e.filter(e=>"audioinput"===e.kind).length>0}}return console.warn("navigator.mediaDevices.enumerateDevices is not available on this browser."),{isAvailable:!1}}catch(e){return console.error("Error checking microphone availability:",e),{isAvailable:!1}}}}var a=Object.freeze({__proto__:null,CapacitorAudioEngineWeb:i});exports.CapacitorAudioEngine=t,exports.base64ToBlob=function(e){const o=s(e),r=atob(o.data),n=new Array(r.length);for(let e=0;e<r.length;e++)n[e]=r.charCodeAt(e);const t=new Uint8Array(n);return new Blob([t],{type:o.mimeType})},exports.getCompressionInfo=function(e){const o=s(e);if(!o.isCompressed)return{isCompressed:!1};const r=Math.floor(3*o.data.length/4);return{isCompressed:!0,algorithm:o.algorithm,compressedSize:r}},exports.getDataURL=function(e){return e.startsWith("data:")?e:`data:audio/m4a;base64,${e}`},exports.getRawBase64Data=function(e){return s(e).data},exports.isCompressedBase64=function(e){return s(e).isCompressed},exports.parseBase64Data=s;