@gjsify/webaudio 0.3.20 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ var e=Object.defineProperty,__name=(t,n)=>e(t,`name`,{value:n,configurable:!0});export{__name};
@@ -1 +1 @@
1
- import{AudioNode as e}from"./audio-node.js";import{AudioParam as t}from"./audio-param.js";import{GstPlayer as n}from"./gst-player.js";import{GainNode as r}from"./gain-node.js";var i=class extends e{buffer=null;loop=!1;loopStart=0;loopEnd=0;playbackRate;onended=null;_player=null;_started=!1;constructor(){super(0,1),this.playbackRate=new t(1,.0625,16)}start(e=0,t=0,r){if(this._started)throw new DOMException(`AudioBufferSourceNode can only be started once`,`InvalidStateError`);if(this._started=!0,!this.buffer)return;let i=this._findGainNode(),a=i?i.gain.value:1;this._player=new n({audioBuffer:this.buffer,volume:a,loop:this.loop,offset:t,duration:r,playbackRate:this.playbackRate.value,onEnded:()=>{i&&i._activePlayers.delete(this._player),this._player=null,this.onended?.()}}),i&&this._player&&i._activePlayers.add(this._player)}stop(e=0){this._player&&this._player.stop()}_findGainNode(){for(let e of this._outputs){if(e instanceof r)return e;for(let t of e._outputs)if(t instanceof r)return t}return null}};export{i as AudioBufferSourceNode};
1
+ import"./_virtual/_rolldown/runtime.js";import{AudioNode as e}from"./audio-node.js";import{AudioParam as t}from"./audio-param.js";import{GstPlayer as n}from"./gst-player.js";import{GainNode as r}from"./gain-node.js";var AudioBufferSourceNode=class extends e{buffer=null;loop=!1;loopStart=0;loopEnd=0;playbackRate;onended=null;_player=null;_started=!1;constructor(){super(0,1),this.playbackRate=new t(1,.0625,16)}start(e=0,t=0,r){if(this._started)throw new DOMException(`AudioBufferSourceNode can only be started once`,`InvalidStateError`);if(this._started=!0,!this.buffer)return;let i=this._findGainNode(),a=i?i.gain.value:1;this._player=new n({audioBuffer:this.buffer,volume:a,loop:this.loop,offset:t,duration:r,playbackRate:this.playbackRate.value,onEnded:()=>{i&&i._activePlayers.delete(this._player),this._player=null,this.onended?.()}}),i&&this._player&&i._activePlayers.add(this._player)}stop(e=0){this._player&&this._player.stop()}_findGainNode(){for(let e of this._outputs){if(e instanceof r)return e;for(let t of e._outputs)if(t instanceof r)return t}return null}};export{AudioBufferSourceNode};
@@ -1 +1 @@
1
- var e=class{sampleRate;length;duration;numberOfChannels;_channelData;constructor(e){this.sampleRate=e.sampleRate,this.length=e.length,this.numberOfChannels=e.numberOfChannels,this.duration=this.length/this.sampleRate,this._channelData=[];for(let e=0;e<this.numberOfChannels;e++)this._channelData.push(new Float32Array(this.length))}getChannelData(e){if(e<0||e>=this.numberOfChannels)throw RangeError(`channel index ${e} out of range [0, ${this.numberOfChannels})`);return this._channelData[e]}copyFromChannel(e,t,n=0){let r=this.getChannelData(t),i=Math.min(e.length,r.length-n);e.set(r.subarray(n,n+i))}copyToChannel(e,t,n=0){let r=this.getChannelData(t),i=Math.min(e.length,r.length-n);r.set(e.subarray(0,i),n)}};export{e as AudioBuffer};
1
+ import"./_virtual/_rolldown/runtime.js";var AudioBuffer=class{sampleRate;length;duration;numberOfChannels;_channelData;constructor(e){this.sampleRate=e.sampleRate,this.length=e.length,this.numberOfChannels=e.numberOfChannels,this.duration=this.length/this.sampleRate,this._channelData=[];for(let e=0;e<this.numberOfChannels;e++)this._channelData.push(new Float32Array(this.length))}getChannelData(e){if(e<0||e>=this.numberOfChannels)throw RangeError(`channel index ${e} out of range [0, ${this.numberOfChannels})`);return this._channelData[e]}copyFromChannel(e,t,n=0){let r=this.getChannelData(t),i=Math.min(e.length,r.length-n);e.set(r.subarray(n,n+i))}copyToChannel(e,t,n=0){let r=this.getChannelData(t),i=Math.min(e.length,r.length-n);r.set(e.subarray(0,i),n)}};export{AudioBuffer};
@@ -1 +1 @@
1
- import{AudioNode as e}from"./audio-node.js";import{ensureGstInit as t}from"./gst-init.js";import{GainNode as n}from"./gain-node.js";import{AudioBufferSourceNode as r}from"./audio-buffer-source-node.js";import{AudioBuffer as i}from"./audio-buffer.js";import{AudioDestinationNode as a}from"./audio-destination-node.js";import{decodeAudioDataSync as o}from"./gst-decoder.js";import s from"gi://GLib?version=2.0";var c=class{state=`suspended`;sampleRate=44100;destination;listener={};_startTime;constructor(){t(),this._startTime=s.get_monotonic_time(),this.destination=new a}get currentTime(){return(s.get_monotonic_time()-this._startTime)/1e6}createGain(){return new n}createBufferSource(){return new r}createBuffer(e,t,n){return new i({numberOfChannels:e,length:t,sampleRate:n})}decodeAudioData(e,t,n){try{let n=o(e);return t?.(n),Promise.resolve(n)}catch(e){let t=e instanceof DOMException?e:new DOMException(`Unable to decode audio data`,`EncodingError`);return n?.(t),Promise.reject(t)}}async resume(){this.state=`running`}async suspend(){this.state=`suspended`}async close(){this.state=`closed`}createAnalyser(){return{connect:()=>{},disconnect:()=>{},fftSize:2048,frequencyBinCount:1024,getByteFrequencyData:()=>{},getFloatFrequencyData:()=>{}}}createDynamicsCompressor(){return new e}createBiquadFilter(){return new e}createConvolver(){return new e}createPanner(){return new e}createStereoPanner(){return new e}addEventListener(e,t){}removeEventListener(e,t){}};export{c as AudioContext};
1
+ import"./_virtual/_rolldown/runtime.js";import{AudioNode as e}from"./audio-node.js";import{ensureGstInit as t}from"./gst-init.js";import{GainNode as n}from"./gain-node.js";import{AudioBufferSourceNode as r}from"./audio-buffer-source-node.js";import{AudioBuffer as i}from"./audio-buffer.js";import{AudioDestinationNode as a}from"./audio-destination-node.js";import{decodeAudioDataSync as o}from"./gst-decoder.js";import s from"gi://GLib?version=2.0";var AudioContext=class{state=`suspended`;sampleRate=44100;destination;listener={};_startTime;constructor(){t(),this._startTime=s.get_monotonic_time(),this.destination=new a}get currentTime(){return(s.get_monotonic_time()-this._startTime)/1e6}createGain(){return new n}createBufferSource(){return new r}createBuffer(e,t,n){return new i({numberOfChannels:e,length:t,sampleRate:n})}decodeAudioData(e,t,n){try{let n=o(e);return t?.(n),Promise.resolve(n)}catch(e){let t=e instanceof DOMException?e:new DOMException(`Unable to decode audio data`,`EncodingError`);return n?.(t),Promise.reject(t)}}async resume(){this.state=`running`}async suspend(){this.state=`suspended`}async close(){this.state=`closed`}createAnalyser(){return{connect:()=>{},disconnect:()=>{},fftSize:2048,frequencyBinCount:1024,getByteFrequencyData:()=>{},getFloatFrequencyData:()=>{}}}createDynamicsCompressor(){return new e}createBiquadFilter(){return new e}createConvolver(){return new e}createPanner(){return new e}createStereoPanner(){return new e}addEventListener(e,t){}removeEventListener(e,t){}};export{AudioContext};
@@ -1 +1 @@
1
- import{AudioNode as e}from"./audio-node.js";var t=class extends e{maxChannelCount=2;constructor(){super(1,0)}};export{t as AudioDestinationNode};
1
+ import"./_virtual/_rolldown/runtime.js";import{AudioNode as e}from"./audio-node.js";var AudioDestinationNode=class extends e{maxChannelCount=2;constructor(){super(1,0)}};export{AudioDestinationNode};
@@ -1 +1 @@
1
- var e=class{_outputs=new Set;_inputs=new Set;numberOfInputs;numberOfOutputs;channelCount;constructor(e=1,t=1){this.numberOfInputs=e,this.numberOfOutputs=t,this.channelCount=2}connect(e){return this._outputs.add(e),e._inputs.add(this),e}disconnect(e){if(e)this._outputs.delete(e),e._inputs.delete(this);else{for(let e of this._outputs)e._inputs.delete(this);this._outputs.clear()}}};export{e as AudioNode};
1
+ import"./_virtual/_rolldown/runtime.js";var AudioNode=class{_outputs=new Set;_inputs=new Set;numberOfInputs;numberOfOutputs;channelCount;constructor(e=1,t=1){this.numberOfInputs=e,this.numberOfOutputs=t,this.channelCount=2}connect(e){return this._outputs.add(e),e._inputs.add(this),e}disconnect(e){if(e)this._outputs.delete(e),e._inputs.delete(this);else{for(let e of this._outputs)e._inputs.delete(this);this._outputs.clear()}}};export{AudioNode};
@@ -1 +1 @@
1
- import e from"gi://GLib?version=2.0";var t=class{defaultValue;minValue;maxValue;_onChange=null;_value;_rampTimerId=null;constructor(e=0,t=-34028235e31,n=34028235e31){this.defaultValue=e,this.minValue=t,this.maxValue=n,this._value=e}get value(){return this._value}set value(e){this._cancelRamp(),this._value=Math.max(this.minValue,Math.min(this.maxValue,e)),this._onChange?.(this._value)}setValueAtTime(e,t){return this.value=e,this}linearRampToValueAtTime(e,t){return this.value=e,this}exponentialRampToValueAtTime(e,t){return this.value=e,this}setTargetAtTime(t,n,r){if(this._cancelRamp(),r<=0)return this.value=t,this;let i=Math.max(10,Math.round(r*100));return this._rampTimerId=e.timeout_add(e.PRIORITY_DEFAULT,i,()=>{let n=t-this._value;if(Math.abs(n)<.001)return this._value=t,this._onChange?.(this._value),this._rampTimerId=null,e.SOURCE_REMOVE;let a=1-Math.exp(-i/(r*1e3));return this._value+=n*a,this._onChange?.(this._value),e.SOURCE_CONTINUE}),this}setValueCurveAtTime(e,t,n){return this}cancelScheduledValues(e){return this._cancelRamp(),this}cancelAndHoldAtTime(e){return this._cancelRamp(),this}_cancelRamp(){this._rampTimerId!==null&&(e.source_remove(this._rampTimerId),this._rampTimerId=null)}};export{t as AudioParam};
1
+ import"./_virtual/_rolldown/runtime.js";import e from"gi://GLib?version=2.0";var AudioParam=class{defaultValue;minValue;maxValue;_onChange=null;_value;_rampTimerId=null;constructor(e=0,t=-34028235e31,n=34028235e31){this.defaultValue=e,this.minValue=t,this.maxValue=n,this._value=e}get value(){return this._value}set value(e){this._cancelRamp(),this._value=Math.max(this.minValue,Math.min(this.maxValue,e)),this._onChange?.(this._value)}setValueAtTime(e,t){return this.value=e,this}linearRampToValueAtTime(e,t){return this.value=e,this}exponentialRampToValueAtTime(e,t){return this.value=e,this}setTargetAtTime(t,n,r){if(this._cancelRamp(),r<=0)return this.value=t,this;let i=Math.max(10,Math.round(r*100));return this._rampTimerId=e.timeout_add(e.PRIORITY_DEFAULT,i,()=>{let n=t-this._value;if(Math.abs(n)<.001)return this._value=t,this._onChange?.(this._value),this._rampTimerId=null,e.SOURCE_REMOVE;let a=1-Math.exp(-i/(r*1e3));return this._value+=n*a,this._onChange?.(this._value),e.SOURCE_CONTINUE}),this}setValueCurveAtTime(e,t,n){return this}cancelScheduledValues(e){return this._cancelRamp(),this}cancelAndHoldAtTime(e){return this._cancelRamp(),this}_cancelRamp(){this._rampTimerId!==null&&(e.source_remove(this._rampTimerId),this._rampTimerId=null)}};export{AudioParam};
@@ -1 +1 @@
1
- import{AudioNode as e}from"./audio-node.js";import{AudioParam as t}from"./audio-param.js";var n=class extends e{gain;_activePlayers=new Set;constructor(){super(1,1),this.gain=new t(1,0,10),this.gain._onChange=e=>{for(let t of this._activePlayers)t.setVolume(e)}}};export{n as GainNode};
1
+ import"./_virtual/_rolldown/runtime.js";import{AudioNode as e}from"./audio-node.js";import{AudioParam as t}from"./audio-param.js";var GainNode=class extends e{gain;_activePlayers=new Set;constructor(){super(1,1),this.gain=new t(1,0,10),this.gain._onChange=e=>{for(let t of this._activePlayers)t.setVolume(e)}}};export{GainNode};
@@ -1 +1 @@
1
- import{Gst as e,ensureGstInit as t}from"./gst-init.js";import{AudioBuffer as n}from"./audio-buffer.js";import"gi://GstApp?version=1.0";function r(r){if(t(),!(r instanceof ArrayBuffer)||r.byteLength===0)throw new DOMException(`Unable to decode audio data`,`EncodingError`);let i=e.parse_launch(`appsrc name=src ! decodebin ! audioconvert ! audioresample ! capsfilter caps=audio/x-raw,format=F32LE,layout=interleaved ! appsink name=sink sync=false`),a=i.get_by_name(`src`),o=i.get_by_name(`sink`);i.set_state(e.State.PLAYING);let s=new Uint8Array(r);a.push_buffer(e.Buffer.new_wrapped(s)),a.end_of_stream();let c=[],l=0,u=0;for(;;){let t=o.try_pull_sample(2*Number(e.SECOND));if(!t)break;if(l===0){let e=t.get_caps();if(e){let t=e.get_structure(0);[,l]=t.get_int(`rate`),[,u]=t.get_int(`channels`)}}let n=t.get_buffer();if(!n)continue;let[r,i]=n.map(e.MapFlags.READ);r&&(c.push(new Uint8Array(i.data)),n.unmap(i))}if(i.set_state(e.State.NULL),l===0||u===0)throw new DOMException(`Unable to decode audio data`,`EncodingError`);let d=0;for(let e of c)d+=e.length;let f=d/(4*u),p=new n({numberOfChannels:u,length:f,sampleRate:l}),m=0;for(let e of c){let t=new Float32Array(e.buffer,e.byteOffset,e.length/4),n=t.length/u;for(let e=0;e<n;e++)for(let n=0;n<u;n++)p._channelData[n][m+e]=t[e*u+n];m+=n}return p}export{r as decodeAudioDataSync};
1
+ import"./_virtual/_rolldown/runtime.js";import{Gst as e,ensureGstInit as t}from"./gst-init.js";import{AudioBuffer as n}from"./audio-buffer.js";import"gi://GstApp?version=1.0";function decodeAudioDataSync(r){if(t(),!(r instanceof ArrayBuffer)||r.byteLength===0)throw new DOMException(`Unable to decode audio data`,`EncodingError`);let i=e.parse_launch(`appsrc name=src ! decodebin ! audioconvert ! audioresample ! capsfilter caps=audio/x-raw,format=F32LE,layout=interleaved ! appsink name=sink sync=false`),a=i.get_by_name(`src`),o=i.get_by_name(`sink`);i.set_state(e.State.PLAYING);let s=new Uint8Array(r);a.push_buffer(e.Buffer.new_wrapped(s)),a.end_of_stream();let c=[],l=0,u=0;for(;;){let t=o.try_pull_sample(2*Number(e.SECOND));if(!t)break;if(l===0){let e=t.get_caps();if(e){let t=e.get_structure(0);[,l]=t.get_int(`rate`),[,u]=t.get_int(`channels`)}}let n=t.get_buffer();if(!n)continue;let[r,i]=n.map(e.MapFlags.READ);r&&(c.push(new Uint8Array(i.data)),n.unmap(i))}if(i.set_state(e.State.NULL),l===0||u===0)throw new DOMException(`Unable to decode audio data`,`EncodingError`);let d=0;for(let e of c)d+=e.length;let f=d/(4*u),p=new n({numberOfChannels:u,length:f,sampleRate:l}),m=0;for(let e of c){let t=new Float32Array(e.buffer,e.byteOffset,e.length/4),n=t.length/u;for(let e=0;e<n;e++)for(let n=0;n<u;n++)p._channelData[n][m+e]=t[e*u+n];m+=n}return p}export{decodeAudioDataSync};
@@ -1 +1 @@
1
- import e from"gi://Gst?version=1.0";let t=!1;function n(){t||=(e.init(null),!0)}export{e as Gst,n as ensureGstInit};
1
+ import"./_virtual/_rolldown/runtime.js";import e from"gi://Gst?version=1.0";let t=!1;function ensureGstInit(){t||=(e.init(null),!0)}export{e as Gst,ensureGstInit};
@@ -1 +1 @@
1
- import{Gst as e,ensureGstInit as t}from"./gst-init.js";import n from"gi://GLib?version=2.0";import"gi://GstApp?version=1.0";var r=class{_pipeline=null;_volumeElement=null;_busWatchId=null;_ended=!1;_loop;_onEnded;_audioBuffer;constructor(n){t(),this._loop=n.loop,this._onEnded=n.onEnded,this._audioBuffer=n.audioBuffer;let{audioBuffer:r,volume:i,offset:a,duration:o,playbackRate:s}=n,c=r.sampleRate,l=r.numberOfChannels,u=this._interleave(r,a,o);if(u.length===0){this._fireEnded();return}let d=`appsrc name=src caps="${`audio/x-raw,format=F32LE,rate=${c},channels=${l},layout=interleaved`}" format=3 ! audioconvert ! volume name=vol ! autoaudiosink`;this._pipeline=e.parse_launch(d),this._volumeElement=this._pipeline.get_by_name(`vol`);let f=this._pipeline.get_by_name(`src`);this._volumeElement.set_property(`volume`,Math.max(0,Math.min(i,10)));let p=this._pipeline.get_bus();this._busWatchId=p.add_watch(0,(t,n)=>(n.type===e.MessageType.EOS?this._loop&&!this._ended?this._restartPlayback(f,u):this._fireEnded():n.type===e.MessageType.ERROR&&this._fireEnded(),!0));let m=e.Buffer.new_wrapped(u),h=u.length/(4*l);m.pts=0,m.duration=Math.floor(h/c*Number(e.SECOND)),f.push_buffer(m),f.end_of_stream(),s!==1&&(this._pipeline.set_state(e.State.PAUSED),this._pipeline.seek(s,e.Format.TIME,e.SeekFlags.FLUSH|e.SeekFlags.ACCURATE,e.SeekType.SET,0,e.SeekType.NONE,-1)),this._pipeline.set_state(e.State.PLAYING)}setVolume(e){this._volumeElement&&!this._ended&&this._volumeElement.set_property(`volume`,Math.max(0,Math.min(e,10)))}setLoop(e){this._loop=e}stop(){this._ended||this._fireEnded()}get ended(){return this._ended}_restartPlayback(t,n){this._pipeline&&this._pipeline.seek_simple(e.Format.TIME,e.SeekFlags.FLUSH,0)}_fireEnded(){this._ended||(this._ended=!0,this._cleanup(),this._onEnded())}_cleanup(){let t=this._pipeline;this._pipeline=null,this._volumeElement=null,this._busWatchId=null,t&&n.idle_add(n.PRIORITY_LOW,()=>(t.set_state(e.State.NULL),n.SOURCE_REMOVE))}_interleave(e,t,n){let r=e.numberOfChannels,i=Math.min(Math.floor(t*e.sampleRate),e.length),a=e.length-i,o=n===void 0?a:Math.min(Math.floor(n*e.sampleRate),a);if(o<=0)return new Uint8Array;let s=new Float32Array(o*r);for(let t=0;t<o;t++)for(let n=0;n<r;n++)s[t*r+n]=e._channelData[n][i+t];return new Uint8Array(s.buffer)}};export{r as GstPlayer};
1
+ import"./_virtual/_rolldown/runtime.js";import{Gst as e,ensureGstInit as t}from"./gst-init.js";import n from"gi://GLib?version=2.0";import"gi://GstApp?version=1.0";var GstPlayer=class{_pipeline=null;_volumeElement=null;_busWatchId=null;_ended=!1;_loop;_onEnded;_audioBuffer;constructor(n){t(),this._loop=n.loop,this._onEnded=n.onEnded,this._audioBuffer=n.audioBuffer;let{audioBuffer:r,volume:i,offset:a,duration:o,playbackRate:s}=n,c=r.sampleRate,l=r.numberOfChannels,u=this._interleave(r,a,o);if(u.length===0){this._fireEnded();return}let d=`appsrc name=src caps="${`audio/x-raw,format=F32LE,rate=${c},channels=${l},layout=interleaved`}" format=3 ! audioconvert ! volume name=vol ! autoaudiosink`;this._pipeline=e.parse_launch(d),this._volumeElement=this._pipeline.get_by_name(`vol`);let f=this._pipeline.get_by_name(`src`);this._volumeElement.set_property(`volume`,Math.max(0,Math.min(i,10)));let p=this._pipeline.get_bus();this._busWatchId=p.add_watch(0,(t,n)=>(n.type===e.MessageType.EOS?this._loop&&!this._ended?this._restartPlayback(f,u):this._fireEnded():n.type===e.MessageType.ERROR&&this._fireEnded(),!0));let m=e.Buffer.new_wrapped(u),h=u.length/(4*l);m.pts=0,m.duration=Math.floor(h/c*Number(e.SECOND)),f.push_buffer(m),f.end_of_stream(),s!==1&&(this._pipeline.set_state(e.State.PAUSED),this._pipeline.seek(s,e.Format.TIME,e.SeekFlags.FLUSH|e.SeekFlags.ACCURATE,e.SeekType.SET,0,e.SeekType.NONE,-1)),this._pipeline.set_state(e.State.PLAYING)}setVolume(e){this._volumeElement&&!this._ended&&this._volumeElement.set_property(`volume`,Math.max(0,Math.min(e,10)))}setLoop(e){this._loop=e}stop(){this._ended||this._fireEnded()}get ended(){return this._ended}_restartPlayback(t,n){this._pipeline&&this._pipeline.seek_simple(e.Format.TIME,e.SeekFlags.FLUSH,0)}_fireEnded(){this._ended||(this._ended=!0,this._cleanup(),this._onEnded())}_cleanup(){let t=this._pipeline;this._pipeline=null,this._volumeElement=null,this._busWatchId=null,t&&n.idle_add(n.PRIORITY_LOW,()=>(t.set_state(e.State.NULL),n.SOURCE_REMOVE))}_interleave(e,t,n){let r=e.numberOfChannels,i=Math.min(Math.floor(t*e.sampleRate),e.length),a=e.length-i,o=n===void 0?a:Math.min(Math.floor(n*e.sampleRate),a);if(o<=0)return new Uint8Array;let s=new Float32Array(o*r);for(let t=0;t<o;t++)for(let n=0;n<r;n++)s[t*r+n]=e._channelData[n][i+t];return new Uint8Array(s.buffer)}};export{GstPlayer};
@@ -1 +1 @@
1
- import{Gst as e,ensureGstInit as t}from"./gst-init.js";const n=new Set([`audio/mpeg`,`audio/mp3`,`audio/wav`,`audio/x-wav`,`audio/ogg`,`audio/webm`,`audio/flac`,`audio/x-flac`,`audio/aac`,`audio/mp4`]);var r=class{src=``;volume=1;loop=!1;paused=!0;currentTime=0;duration=0;readyState=0;_pipeline=null;canPlayType(e){let t=e.split(`;`)[0].trim().toLowerCase();return n.has(t)?`maybe`:``}play(){return!this.src||(t(),this._cleanup(),this._pipeline=e.ElementFactory.make(`playbin`,`player`),!this._pipeline)?Promise.resolve():(this._pipeline.set_property(`uri`,this.src),this._pipeline.set_property(`volume`,this.volume),this._pipeline.set_state(e.State.PLAYING),this.paused=!1,Promise.resolve())}pause(){this._pipeline&&(this._pipeline.set_state(e.State.PAUSED),this.paused=!0)}load(){this._cleanup()}addEventListener(e,t){}removeEventListener(e,t){}_cleanup(){this._pipeline&&=(this._pipeline.set_state(e.State.NULL),null)}};export{r as HTMLAudioElement};
1
+ import"./_virtual/_rolldown/runtime.js";import{Gst as e,ensureGstInit as t}from"./gst-init.js";const n=new Set([`audio/mpeg`,`audio/mp3`,`audio/wav`,`audio/x-wav`,`audio/ogg`,`audio/webm`,`audio/flac`,`audio/x-flac`,`audio/aac`,`audio/mp4`]);var HTMLAudioElement=class{src=``;volume=1;loop=!1;paused=!0;currentTime=0;duration=0;readyState=0;_pipeline=null;canPlayType(e){let t=e.split(`;`)[0].trim().toLowerCase();return n.has(t)?`maybe`:``}play(){return!this.src||(t(),this._cleanup(),this._pipeline=e.ElementFactory.make(`playbin`,`player`),!this._pipeline)?Promise.resolve():(this._pipeline.set_property(`uri`,this.src),this._pipeline.set_property(`volume`,this.volume),this._pipeline.set_state(e.State.PLAYING),this.paused=!1,Promise.resolve())}pause(){this._pipeline&&(this._pipeline.set_state(e.State.PAUSED),this.paused=!0)}load(){this._cleanup()}addEventListener(e,t){}removeEventListener(e,t){}_cleanup(){this._pipeline&&=(this._pipeline.set_state(e.State.NULL),null)}};export{HTMLAudioElement};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/webaudio",
3
- "version": "0.3.20",
3
+ "version": "0.4.0",
4
4
  "description": "Web Audio API for GJS using GStreamer as audio backend",
5
5
  "type": "module",
6
6
  "module": "lib/esm/index.js",
@@ -36,17 +36,17 @@
36
36
  "audio-api"
37
37
  ],
38
38
  "dependencies": {
39
- "@gjsify/dom-events": "^0.3.20"
39
+ "@gjsify/dom-events": "^0.4.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@girs/gjs": "4.0.0-rc.14",
43
- "@girs/glib-2.0": "2.88.0-4.0.0-rc.14",
44
- "@girs/gst-1.0": "1.28.1-4.0.0-rc.14",
45
- "@girs/gstapp-1.0": "1.0.0-4.0.0-rc.14",
46
- "@girs/gstaudio-1.0": "1.0.0-4.0.0-rc.14",
47
- "@girs/gstbase-1.0": "1.0.0-4.0.0-rc.14",
48
- "@gjsify/cli": "^0.3.20",
49
- "@gjsify/unit": "^0.3.20",
42
+ "@girs/gjs": "4.0.0-rc.15",
43
+ "@girs/glib-2.0": "2.88.0-4.0.0-rc.15",
44
+ "@girs/gst-1.0": "1.28.1-4.0.0-rc.15",
45
+ "@girs/gstapp-1.0": "1.0.0-4.0.0-rc.15",
46
+ "@girs/gstaudio-1.0": "1.0.0-4.0.0-rc.15",
47
+ "@girs/gstbase-1.0": "1.0.0-4.0.0-rc.15",
48
+ "@gjsify/cli": "^0.4.0",
49
+ "@gjsify/unit": "^0.4.0",
50
50
  "@types/node": "^25.6.2",
51
51
  "typescript": "^6.0.3"
52
52
  }