TeaSpeak-Client/modules/renderer/audio/Sounds.ts

27 lines
1.1 KiB
TypeScript

import {audio as naudio} from "tc-native/connection";
import {SoundBackend, SoundFile} from "tc-shared/audio/Sounds";
import * as paths from "path";
export class NativeSoundBackend implements SoundBackend {
playSound(sound: SoundFile): Promise<void> {
return new Promise((resolve, reject) => {
let pathname = paths.dirname(decodeURIComponent(location.pathname));
if(pathname[0] === '/' && pathname[2] === ':') //e.g.: /C:/test...
pathname = pathname.substr(1);
const path = paths.join(pathname, sound.path);
console.log("replaying %s (volume: %f)", sound.path, sound.volume);
naudio.sounds.playback_sound({
callback: (result, message) => {
if(result == naudio.sounds.PlaybackResult.SUCCEEDED)
resolve();
else
reject(naudio.sounds.PlaybackResult[result].toLowerCase() + ": " + message);
},
file: path,
volume: typeof sound.volume === "number" ? sound.volume : 1
});
});
}
}