Skip to content

Commit

Permalink
fix: make Audio and Video tags work with remote files
Browse files Browse the repository at this point in the history
  • Loading branch information
justusmattern27 committed Mar 13, 2024
1 parent 36cd521 commit 84a809c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions packages/2d/src/lib/components/Audio.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {DependencyContext, PlaybackState} from '@motion-canvas/core';
import {DependencyContext, PlaybackState, viaProxy} from '@motion-canvas/core';
import {computed, nodeName} from '../decorators';
import {Media, MediaProps} from './Media';

Expand All @@ -24,11 +24,12 @@ export class Audio extends Media {

@computed()
protected audio(): HTMLAudioElement {
const src = this.src();
const src = viaProxy(this.src());
const key = `${this.key}/${src}`;
let audio = Audio.pool[key];
if (!audio) {
audio = document.createElement('audio');
audio.crossOrigin = 'anonymous';
audio.src = src;
Audio.pool[key] = audio;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/2d/src/lib/components/Video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
SerializedVector2,
SignalValue,
SimpleSignal,
viaProxy,
} from '@motion-canvas/core';
import {computed, initial, nodeName, signal} from '../decorators';
import {DesiredLength} from '../partials';
Expand Down Expand Up @@ -81,11 +82,12 @@ export class Video extends Media {

@computed()
private video(): HTMLVideoElement {
const src = this.src();
const src = viaProxy(this.src());
const key = `${this.key}/${src}`;
let video = Video.pool[key];
if (!video) {
video = document.createElement('video');
video.crossOrigin = 'anonymous';
video.src = src;
Video.pool[key] = video;
}
Expand Down

0 comments on commit 84a809c

Please sign in to comment.