Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
fix playAudio node
Browse files Browse the repository at this point in the history
  • Loading branch information
HexaField committed Sep 1, 2023
1 parent 307f0d4 commit dadc9c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ import { FollowCameraComponent } from '../../../../../camera/components/FollowCa
import { Engine } from '../../../../../ecs/classes/Engine'
import { Entity } from '../../../../../ecs/classes/Entity'
import { SceneServices } from '../../../../../ecs/classes/Scene'
import { getComponent, hasComponent, setComponent } from '../../../../../ecs/functions/ComponentFunctions'
import {
getComponent,
getMutableComponent,
hasComponent,
setComponent
} from '../../../../../ecs/functions/ComponentFunctions'
import { StandardCallbacks, getCallback } from '../../../../../scene/components/CallbackComponent'
import { MediaComponent } from '../../../../../scene/components/MediaComponent'
import { VideoComponent } from '../../../../../scene/components/VideoComponent'
Expand Down Expand Up @@ -157,7 +162,8 @@ export const playAudio = makeFlowNodeDefinition({
volume: volume,
playMode: playMode!
}) // play
const component = getComponent(entity, MediaComponent)
const component = getMutableComponent(entity, MediaComponent)
component.paused.set(false)
commit('flow')
}
})
Expand Down
4 changes: 4 additions & 0 deletions packages/engine/src/scene/components/MediaComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { Entity } from '../../ecs/classes/Entity'
import {
ComponentType,
defineComponent,
getComponent,
getMutableComponent,
getOptionalComponent,
hasComponent,
Expand Down Expand Up @@ -239,6 +240,9 @@ export function MediaReactor() {
// This must be outside of the normal ECS flow by necessity, since we have to respond to user-input synchronously
// in order to ensure media will play programmatically
const handleAutoplay = () => {
// handle when we dont have autoplay enabled but have programatically started playback
if (!media.autoplay.value && !media.paused.value) getComponent(entity, MediaElementComponent)?.element.play()
// handle when we have autoplay enabled but have paused playback
if (media.autoplay.value && media.paused.value) media.paused.set(false)
window.removeEventListener('pointerdown', handleAutoplay)
window.removeEventListener('keypress', handleAutoplay)
Expand Down

0 comments on commit dadc9c7

Please sign in to comment.