Can play Sound from a map script

add sound in the TutoMap
This commit is contained in:
DESKTOP-FMM8UI0\CLV 2021-04-21 16:47:19 +02:00
parent 676dbcc9d0
commit 517c0e86cb
6 changed files with 92 additions and 0 deletions

View file

@ -39,6 +39,7 @@ import {mediaManager} from "../../WebRtc/MediaManager";
import {ItemFactoryInterface} from "../Items/ItemFactoryInterface";
import {ActionableItem} from "../Items/ActionableItem";
import {UserInputManager} from "../UserInput/UserInputManager";
import {soundManager} from "./SoundManager";
import {UserMovedMessage} from "../../Messages/generated/messages_pb";
import {ProtobufClientUtils} from "../../Network/ProtobufClientUtils";
import {connectionManager} from "../../Connexion/ConnectionManager";
@ -793,6 +794,11 @@ ${escapedMessage}
this.userInputManager.disableControls();
}));
this.iframeSubscriptionList.push(iframeListener.playSoundStream.subscribe((playSoundEvent)=>
{
soundManager.playSound(this.load,this.sound,playSoundEvent.url,playSoundEvent.config);
}))
this.iframeSubscriptionList.push(iframeListener.enablePlayerControlStream.subscribe(()=>{
this.userInputManager.restoreControls();
}));

View file

@ -0,0 +1,30 @@
import LoaderPlugin = Phaser.Loader.LoaderPlugin;
import BaseSoundManager = Phaser.Sound.BaseSoundManager;
import BaseSound = Phaser.Sound.BaseSound;
import Config = Phaser.Core.Config;
import SoundConfig = Phaser.Types.Sound.SoundConfig;
class SoundManager {
public loadSound (loadPlugin: LoaderPlugin, soundManager : BaseSoundManager, soundUrl: string) : Promise<BaseSound> {
return new Promise<BaseSound>((res) => {
let sound = soundManager.get(soundUrl);
if (sound !== null) {
return res(sound);
}
loadPlugin.audio(soundUrl, soundUrl);
loadPlugin.once('filecomplete-audio-' + soundUrl, () => res(soundManager.add(soundUrl)));
loadPlugin.start();
});
}
public async playSound(loadPlugin: LoaderPlugin, soundManager : BaseSoundManager, soundUrl: string, config: SoundConfig) : Promise<void> {
console.log("play sound");
const sound = await this.loadSound(loadPlugin,soundManager,soundUrl);
sound.play(config);
console.log("j'ai joué le son");
}
}
export const soundManager = new SoundManager();