Skip to content

Commit

Permalink
simplify getDuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattk70 committed Nov 6, 2024
1 parent 73ee7d6 commit 00beaa8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
12 changes: 4 additions & 8 deletions js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ const setupFfmpegCommand = ({
const command = ffmpeg('file:' + file)
.format(format)
.audioChannels(channels)
.audioFrequency(sampleRate);
// .addInputOptions([`-ar=${sampleRate}`, '-filter_type', "'kaiser'" ] )
.audioFrequency(sampleRate)
//.audioFilters('aresample=filter_type=kaiser:kaiser_beta=9.90322');

// Add filters if provided
additionalFilters.forEach(filter => {
Expand Down Expand Up @@ -1027,15 +1027,11 @@ const getDuration = async (src) => {
let audio;
return new Promise(function (resolve, reject) {
audio = new Audio();

audio.src = src.replaceAll('#', '%23').replaceAll('?', '%3F'); // allow hash and ? in the path (https://github.com/Mattk70/Chirpity-Electron/issues/98)
audio.addEventListener("loadedmetadata", function () {
const duration = audio.duration === Infinity ? Number.MAX_SAFE_INTEGER : audio.duration;
audio = undefined;
// Tidy up - cloning removes event listeners
const old_element = document.getElementById("audio");
const new_element = old_element.cloneNode(true);
old_element.parentNode.replaceChild(new_element, old_element);

audio.remove();
resolve(duration);
});
audio.addEventListener('error', (error) => {
Expand Down
1 change: 0 additions & 1 deletion worker.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<title>Worker</title>
</head>
<body>
<audio id="audio"></audio>
<script type="module" src="./js/worker.js"></script>
</body>
</html>

0 comments on commit 00beaa8

Please sign in to comment.