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.35 kB
JavaScript
import{registerPlugin as o,WebPlugin as e}from"@capacitor/core";var r,n,t;function s(o){if(!o.startsWith("data:"))return{isCompressed:!1,data:o,mimeType:"audio/m4a"};const[e,r]=o.split(",",2);return e.includes("lzfse:")?{isCompressed:!0,algorithm:"lzfse",data:r,mimeType:e.split(";")[0].replace("data:","")}:{isCompressed:!1,data:r,mimeType:e.split(";")[0].replace("data:","")}}function i(o){return s(o).data}function a(o){return s(o).isCompressed}function p(o){const e=s(o);if(!e.isCompressed)return{isCompressed:!1};const r=Math.floor(3*e.data.length/4);return{isCompressed:!0,algorithm:e.algorithm,compressedSize:r}}function c(o){const e=s(o),r=atob(e.data),n=new Array(r.length);for(let o=0;o<r.length;o++)n[o]=r.charCodeAt(o);const t=new Uint8Array(n);return new Blob([t],{type:e.mimeType})}function d(o){return o.startsWith("data:")?o:`data:audio/m4a;base64,${o}`}!function(o){o.GRANTED="granted",o.DENIED="denied",o.DENIED_PERMANENTLY="denied_permanently",o.NOT_DETERMINED="not_determined",o.LIMITED="limited",o.RESTRICTED="restricted",o.REQUESTING="requesting",o.UNSUPPORTED="unsupported"}(r||(r={})),function(o){o.MICROPHONE="microphone",o.NOTIFICATIONS="notifications"}(n||(n={})),function(o){o[o.REALTIME=50]="REALTIME",o[o.VERY_FAST=100]="VERY_FAST",o[o.FAST=200]="FAST",o[o.MEDIUM=500]="MEDIUM",o[o.DEFAULT=1e3]="DEFAULT"}(t||(t={}));const l=o("CapacitorAudioEngine",{web:()=>Promise.resolve().then(function(){return u}).then(o=>new o.CapacitorAudioEngineWeb)});var u=Object.freeze({__proto__:null,CapacitorAudioEngineWeb:class extends e{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:r.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:r.UNSUPPORTED}}async checkPermissionNotifications(){return console.warn("checkPermissionNotifications is not fully supported on web platform. Notifications not applicable for web audio recording."),{granted:!1,status:r.UNSUPPORTED}}async requestPermissions(o){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(o,e){console.warn(`${o} 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(o){throw console.warn(`switchMicrophone is not supported on web platform. Attempted to switch to microphone ID: ${o.microphoneId}`),new Error("switchMicrophone is not supported on web platform")}async removeAllListeners(){console.warn("removeAllListeners is not supported on web platform.")}async configureWaveform(o){var e;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!==(e=null==o?void 0:o.EmissionInterval)&&void 0!==e?e:1e3}}}async destroyWaveform(){console.warn("destroyWaveform is not supported on web platform. No waveform resources to clean up.")}async preloadTracks(o){console.warn("preloadTracks is not supported on web platform. For web implementation, consider using HTML5 Audio API directly.");return{tracks:o.tracks.map(o=>({url:o,loaded:!1,duration:0,size:0,mimeType:"unknown"}))}}async playTrack(o){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(o){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(o){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(o){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(o){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(o){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(o){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(o){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 o=await navigator.mediaDevices.enumerateDevices();return{isAvailable:o.filter(o=>"audioinput"===o.kind).length>0}}return console.warn("navigator.mediaDevices.enumerateDevices is not available on this browser."),{isAvailable:!1}}catch(o){return console.error("Error checking microphone availability:",o),{isAvailable:!1}}}}});export{n as AudioPermissionType,l as CapacitorAudioEngine,r as PermissionStatus,t as WaveLevelEmissionInterval,c as base64ToBlob,p as getCompressionInfo,d as getDataURL,i as getRawBase64Data,a as isCompressedBase64,s as parseBase64Data};