24 lines
943 B
TypeScript
24 lines
943 B
TypeScript
import {audio as naudio} from "tc-native/connection";
|
|
import * as paths from "path";
|
|
import {SoundFile} from "tc-shared/sound/Sounds";
|
|
|
|
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);
|
|
|
|
console.log(path);
|
|
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: file.volume
|
|
});
|
|
});
|
|
} |