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

24 lines
995 B
TypeScript
Raw Normal View History

import {audio as naudio} from "tc-native/connection";
2020-03-18 18:33:28 -04:00
import * as paths from "path";
import {SoundFile} from "tc-shared/sound/Sounds";
2020-03-18 18:33:28 -04:00
export async function play_sound(file: SoundFile) : Promise<void> {
await 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, file.path);
2020-03-18 18:33:28 -04:00
2020-08-09 09:03:52 -04:00
console.log("replaying %s (volume: %f)", file.path, file.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,
2020-08-09 09:03:52 -04:00
volume: file.volume || 1
2020-03-18 18:33:28 -04:00
});
});
}