Skip to content

Commit

Permalink
Remove unnecessary autoplay and loop video flags
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Aug 9, 2023
1 parent a197395 commit 81229b6
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 17 deletions.
3 changes: 1 addition & 2 deletions src/bit-systems/video-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { AudioSystem } from "../systems/audio-system";
import { findAncestorWithComponent } from "../utils/bit-utils";
import { Emitter2Audio, Emitter2Params, makeAudioEntity } from "./audio-emitter-system";
import { takeSoftOwnership } from "../utils/take-soft-ownership";
import { VIDEO_FLAGS } from "../inflators/video";

enum Flags {
PAUSED = 1 << 0
Expand All @@ -34,7 +33,7 @@ export function videoSystem(world: HubsWorld, audioSystem: AudioSystem) {
mediaVideoEnterQuery(world).forEach(function (videoEid) {
const videoObj = world.eid2obj.get(videoEid) as Mesh;
const video = MediaVideoData.get(videoEid)!;
if (MediaVideo.flags[videoEid] & VIDEO_FLAGS.AUTOPLAY) {
if (video.autoplay) {
video.play().catch(() => {
// Need to deal with the fact play() may fail if user has not interacted with browser yet.
console.error("Error auto-playing video.");
Expand Down
12 changes: 1 addition & 11 deletions src/inflators/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,26 @@ import { EntityID } from "../utils/networking-types";
import { Texture } from "three";

export const VIDEO_FLAGS = {
AUTOPLAY: 1 << 0,
LOOP: 1 << 1,
CONTROLS: 1 << 2
};

export interface VideoParams {
texture: Texture;
ratio: number;
projection: ProjectionMode;
autoPlay: boolean;
video: HTMLVideoElement;
loop: boolean;
controls: boolean;
}

export function inflateVideo(world: HubsWorld, eid: EntityID, params: VideoParams) {
const { texture, ratio, projection, autoPlay, video, loop, controls } = params;
const { texture, ratio, projection, video, controls } = params;
const mesh =
projection === ProjectionMode.SPHERE_EQUIRECTANGULAR
? create360ImageMesh(texture)
: createImageMesh(texture, ratio);
addObject3DComponent(world, eid, mesh);
addComponent(world, MediaVideo, eid);

if (autoPlay) {
MediaVideo.flags[eid] |= VIDEO_FLAGS.AUTOPLAY;
}
if (loop) {
MediaVideo.flags[eid] |= VIDEO_FLAGS.LOOP;
}
if (controls) {
MediaVideo.flags[eid] |= VIDEO_FLAGS.CONTROLS;
}
Expand Down
2 changes: 0 additions & 2 deletions src/utils/load-audio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ export function* loadAudio(world: HubsWorld, eid: EntityID, url: string) {
video={{
texture,
ratio,
autoPlay,
projection,
video,
loop,
controls
}}
></entity>
Expand Down
2 changes: 0 additions & 2 deletions src/utils/load-video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ export function* loadVideo(world: HubsWorld, eid: EntityID, url: string, content
video={{
texture,
ratio,
autoPlay,
projection,
video,
loop,
controls
}}
></entity>
Expand Down

0 comments on commit 81229b6

Please sign in to comment.