Here is my code. With this the Final_Paul,mp4 does not load at all anymore and the Oscar_Wilde_-_Made_with_Clipchamp_1.mp4 opens but freezes on the first frame.
import * as ecs from ‘@8thwall/ecs’
ecs.registerComponent({
name: ‘video_Autoplay’,
schema: {},
schemaDefaults: {},
data: {},
stateMachine: ({world, eid}) => {
ecs
.defineState(‘setup’)
.initial()
.onEvent(world.events.globalId, ‘reality.imageloaded’, () => {
// This state ensures our component is ready to handle imagefound events
// after the reality engine has fully initialized.
ecs.VideoControls.set(world, eid, {
paused: false,
})
})
.listen(world.events.globalId, ‘reality.imagefound’, (e: {detail: {name: string}}) => {
try {
const imageName: string = e.detail.name
let videoSrc: string | null = null
if (imageName === 'paulverlainestill.jpg') {
videoSrc = 'Final_Paul.mp4'
} else if (imageName === 'Wilde.jpg') {
videoSrc = 'Oscar_Wilde_-_Made_with_Clipchamp_1.mp4'
}
if (videoSrc) {
ecs.VideoControls.set(world, eid, {
paused: false,
src: videoSrc,
})
}
} catch (error) {
// You may want to handle this error in a way that doesn't use console.error
}
})
.listen(world.events.globalId, 'reality.imagelost', (e) => {
// Pause when image is lost (optional, keeps position so resume works)
ecs.VideoControls.set(world, eid, {
paused: true,
})
})
},
})