tav-media
Version:
Cross platform media editing framework
117 lines (116 loc) • 3.85 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { tav } from '../tav';
import { Clip } from './tav-clip';
/**
* Base class for all timed audiovisual resources created from assets or compositions. Media has a
* contentDuration property which represents its original playback duration, so changing the duration
* property of a Media will affect its playback speed.
*
* @hideconstructor
* @category Clips
*/
export class MediaClip extends Clip {
constructor() {
super(...arguments);
this.type = 'Media';
this._volume = 1;
}
/**
* @ignore
*/
get isNativeInvalidated() {
return this.nativeInvalidated;
}
release() {
var _a;
super.release();
(_a = this.asset) === null || _a === void 0 ? void 0 : _a.release();
}
updateClip(clip) {
const _super = Object.create(null, {
updateClip: { get: () => super.updateClip }
});
return __awaiter(this, void 0, void 0, function* () {
yield _super.updateClip.call(this, clip);
const media = clip;
yield tav.webAssemblyQueue.exec(media.setDuration, media, this.duration || this.contentDuration || 0);
yield tav.webAssemblyQueue.exec(media.setVolume, media, this._volume);
});
}
/**
* @ignore
*/
get asset() {
return this._asset;
}
set asset(val) {
this._asset = val;
}
/**
* Get or set the start time of the asset to be used in the clip.
*/
get contentStartTime() {
return this._contentStartTime;
}
set contentStartTime(time) {
this.setContentStartTime(time);
}
/**
* Get or set the duration of the asset to be used in the clip.
* If the content duration is different from the duration of the clip,
* the clip will change the playback speed.
*/
get contentDuration() {
return this._contentDuration;
}
set contentDuration(time) {
this.setContentDuration(time);
}
/**
* Get or set the volume of this media, which is usually in the range [0 - 1.0].
*/
get volume() {
return this._volume;
}
set volume(vol) {
var _a;
let val = vol;
if (vol < 0) {
console.error('The volume must be in the range of 0 to 1.');
val = 0;
}
else if (vol > 1) {
console.error('The volume must be in the range of 0 to 1.');
val = 1;
}
this._volume = val;
if (!this.nativeClip) {
this.invalidated();
;
return;
}
tav.webAssemblyQueue.exec((_a = this.nativeClip) === null || _a === void 0 ? void 0 : _a.setVolume, this.nativeClip, val);
}
setContentStartTime(time) {
if (this._contentStartTime === time)
return;
this._contentStartTime = time;
this._contentTimeInvalid = true;
this.invalidated();
}
setContentDuration(time) {
if (this._contentDuration === time)
return;
this._contentDuration = time;
this._contentTimeInvalid = true;
this.invalidated();
}
}