Skip to content

Commit 794b7fc

Browse files
committed
Исправление накладок аудио при воспроизведении
1 parent 6a6c447 commit 794b7fc

11 files changed

Lines changed: 28 additions & 22 deletions

File tree

ReleaseNotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
* ✨ Каждая фотография интерактивного элемента может содержать собственную озвучку
2+
* 🐛 Исправлено одновременное воспроизведение фонового аудио с аудио из интерактивных элемнетов
23
* ➕ Добавлен biome для лингинга кода и проверки ошибок

src/Models/BackgroundAudio/BackgroundAudioView.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class BackgroundAudioView {
1212
private packs: Map<string, AudioContainer> = new Map();
1313
private currentAudioPack: AudioContainer | null = null;
1414
private eventTrigger: IBackgroundAudioEventTrigger | null = null;
15-
private triggerInterval: any;
15+
private triggerInterval: NodeJS.Timeout;
1616

1717
private get isPlay(): boolean {
1818
return this.currentAudioPack?.isPlaying() === true;
@@ -22,6 +22,7 @@ export class BackgroundAudioView {
2222
private scene: Scene,
2323
private sceneUrl: string,
2424
private fullScreenUI: FullScreenGUI,
25+
private onStartPlaying: () => void,
2526
) {
2627
fullScreenUI.onPlayPauseBackgroundAudioClickObservable.add(() => {
2728
if (this.currentAudioPack) {
@@ -65,6 +66,7 @@ export class BackgroundAudioView {
6566

6667
public play() {
6768
this.currentAudioPack?.play(true);
69+
this.onStartPlaying();
6870
}
6971

7072
public pause() {

src/Models/FieldItem.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,11 @@ export class FieldItem extends LinkToState {
176176
this.fieldItemInfo.videos[0], // TODO: handle all videos
177177
backgroundPlane,
178178
FieldItem.containerSize * 1.6,
179-
FieldItem.containerSize,
180179
() => {
181180
this.onPlayMedia();
182181
this.audioContent?.pauseAudio();
183182
},
184183
this.gui3Dmanager,
185-
this.assetsManager,
186184
this.scene,
187185
);
188186
this.contentList.push(videoContent);

src/Models/FieldItemContents/AudioContent.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ export class AudioContent implements FieldItemContent {
161161
}
162162

163163
public setAudioContent(audioContent: FieldItemAudioContent) {
164+
this.setIsVisible(true);
165+
if (audioContent.src === this.audioInfo?.src) {
166+
return;
167+
}
164168
this.audioInfo = audioContent;
165169
const audio = new Sound(
166170
"audio_content",
@@ -173,6 +177,9 @@ export class AudioContent implements FieldItemContent {
173177

174178
this.playPauseButtonText.text = ExcursionConstants.PlayIcon;
175179
this.currentPositionTimer = setInterval(() => {
180+
this.playPauseButtonText.text = this.audio?.isPlaying
181+
? ExcursionConstants.PauseIcon
182+
: ExcursionConstants.PlayIcon;
176183
this.currentPositionText.text = this.getCurrentPositionText();
177184
}, 500);
178185
},

src/Models/FieldItemContents/ImagesContent.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ export class ImagesContent implements FieldItemContent {
151151
}
152152
this.currentImage = index;
153153
if (this.images[index].audio) {
154-
this.parentAudioContent.setAudioContent(this.images[index].audio);
154+
this.parentAudioContent?.setAudioContent(this.images[index].audio);
155+
} else {
156+
this.parentAudioContent?.setIsVisible(false);
155157
}
156158
}
157159

src/Models/FieldItemContents/VideoContent.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { Color3 } from "@babylonjs/core/Maths/math.color";
77
import type { Mesh } from "@babylonjs/core/Meshes/mesh";
88
import { MeshBuilder } from "@babylonjs/core/Meshes/meshBuilder";
99
import type { TransformNode } from "@babylonjs/core/Meshes/transformNode";
10-
import type { AssetsManager } from "@babylonjs/core/Misc/assetsManager";
1110
import type { Scene } from "@babylonjs/core/scene";
1211
import { TextWrapping } from "@babylonjs/gui/2D/controls";
1312
import { TextBlock } from "@babylonjs/gui/2D/controls/textBlock";
@@ -32,13 +31,11 @@ export class VideoContent implements FieldItemContent {
3231
private playPauseButton: CustomHolographicButton;
3332
private playPauseButtonText: TextBlock;
3433
constructor(
35-
private videoUrl: string,
34+
videoUrl: string,
3635
private parent: TransformNode,
3736
private contentWidth: number,
38-
private contentHeight: number,
3937
private onPlay: () => void,
4038
private gui3Dmanager: GUI3DManager,
41-
private assetsManager: AssetsManager,
4239
private scene: Scene,
4340
) {
4441
this.loadVideoResources(videoUrl);

src/Models/IconBottom.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import type { Scene } from "@babylonjs/core/scene";
66
import type { BottomImageConfiguration } from "../Configuration/Configuration";
77

88
export class IconBottom {
9-
constructor(
10-
_scene: Scene,
11-
config: BottomImageConfiguration,
12-
) {
9+
constructor(_scene: Scene, config: BottomImageConfiguration) {
1310
const bottomPlane = MeshBuilder.CreatePlane(
1411
`background_image_plane`,
1512
{

src/Models/PrefetchResourcesManager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ export class PrefetchResourcesManager {
1010
return;
1111
}
1212
const preloadLink = window.document.createElement("link");
13-
preloadLink["rel"] = "prefetch";
14-
preloadLink["as"] = "fetch";
15-
preloadLink["href"] = link;
13+
preloadLink.rel = "prefetch";
14+
preloadLink.as = "fetch";
15+
preloadLink.href = link;
1616
this.linksContainer.appendChild(preloadLink);
1717
this.addedLinks.add(link);
1818
}

src/TempTimerLogic.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ export class TempTimerLogic {
9393
scene,
9494
0,
9595
() => {
96-
imageToShow!.imagePlane.animations.push(showAnimation);
97-
scene.beginAnimation(imageToShow!.imagePlane, 0, frameRate, true);
96+
imageToShow.imagePlane.animations.push(showAnimation);
97+
scene.beginAnimation(imageToShow.imagePlane, 0, frameRate, true);
9898
},
9999
);
100100
await assetsManager.loadAsync();
101101
onContentCreated(imageToShow);
102102
},
103103
async () => {
104-
scene.beginAnimation(imageToShow!.imagePlane, frameRate, 0, true);
104+
scene.beginAnimation(imageToShow.imagePlane, frameRate, 0, true);
105105
setTimeout(() => {
106106
imageToShow.dispose();
107107
}, 1500);

src/Viewer.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ export class Viewer {
8989
scene,
9090
this.configuration.sceneUrl,
9191
this.fullScreenGUI,
92+
() => {
93+
this.links.pauseAllAudios();
94+
},
9295
);
9396
let spacePressed = false;
9497
scene.onKeyboardObservable.add((ev) => {
@@ -292,9 +295,8 @@ export class Viewer {
292295
this.currentPicture = targetPicture;
293296
this.cleanResources();
294297
this.prefetchAudio(targetPicture);
295-
await this.drawImage(
296-
targetPicture,
297-
() => actionBeforeChange?.(targetPicture),
298+
await this.drawImage(targetPicture, () =>
299+
actionBeforeChange?.(targetPicture),
298300
);
299301

300302
this.fullScreenGUI.setFastReturnToFirstStateVisible(

0 commit comments

Comments
 (0)