Skip to content

Commit

Permalink
refactor: Convert audioControl.js to TypeScript (#1255)
Browse files Browse the repository at this point in the history
  • Loading branch information
drikusroor authored Sep 9, 2024
1 parent 6a3912b commit 7ebb8c8
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import Section from "@/types/Section";
import * as audio from "./audio";
import * as webAudio from "./webAudio";
import { PlaybackArgs } from "@/types/Playback";

export const playAudio = (section, playMethod, playheadShift=0) => {
export const playAudio = (section: Section, playMethod: PlaybackArgs['play_method'], playheadShift = 0) => {
let latency = 0;

if (playMethod === 'BUFFER') {

// Determine latency for current audio device
latency = webAudio.getTotalLatency()
// Play audio
webAudio.playBufferFrom(section.id, playheadShift);
webAudio.playBufferFrom(section.id.toString(), playheadShift);

return latency
} else {
} else {

// Only initialize webaudio if section is hosted local
if (playMethod !== 'EXTERNAL') {
// Determine latency for current audio device
latency = webAudio.getTotalLatency()
webAudio.initWebAudio();
webAudio.initWebAudio();
}

// Volume 1
Expand All @@ -28,15 +30,15 @@ export const playAudio = (section, playMethod, playheadShift=0) => {
audio.loadUntilAvailable(section.url, () => {
audio.playFrom(Math.max(0, playheadShift));
});

return latency
}
}

export const pauseAudio = (playMethod) => {
export const pauseAudio = (playMethod: PlaybackArgs['play_method']) => {
if (playMethod === 'BUFFER') {
webAudio.stopBuffer();
} else {
audio.stop();
}
}
}

0 comments on commit 7ebb8c8

Please sign in to comment.