UNPKG

tav-media

Version:

Cross platform media editing framework

157 lines (156 loc) 5.18 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; 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 { allowCallNativeAnytime, TAVObject } from '../types/tav-object'; import { tav } from '../tav'; /** * A light weight container for audiovisual media. * @hideconstructor * @category Assets */ export class Asset extends TAVObject { /** * Constructors are used by parsers, don't use it in your code. */ constructor(id, path) { super(id); /** * Returns the type of this asset */ this.type = 'Asset'; this._path = ''; this._path = path !== null && path !== void 0 ? path : ''; } /** * Build the native asset based on the path. * @returns The native asset object */ build() { return __awaiter(this, void 0, void 0, function* () { if (!this.prepared) { yield this.prepare(); } if (this.nativeInvalidated) { this._nativeObject = null; } if (this._nativeObject && this._nativeObject.path === this.path) { return this._nativeObject; } const asset = yield tav.webAssemblyQueue.exec(this.createAsset, this, null); if (!asset) return undefined; asset.path = this.path; this.updateAsset(asset); this._nativeObject = asset; this.nativeInvalidated = false; return asset; }); } /** * Release the native asset. */ release() { var _a; if ((_a = this._nativeObject) === null || _a === void 0 ? void 0 : _a.delete) { this._nativeObject.delete(); } this._nativeObject = null; } /** * Call native methods to create the native asset object. */ createAsset() { return __awaiter(this, void 0, void 0, function* () { return undefined; }); } /** * Update the native asset object based on the properties of this asset. * @param asset The native asset object */ updateAsset(asset) { this._nativeObject = asset; } /** * Get or set the path of this asset. * Setting the path will invalidate the native asset. * You */ get path() { return this._path; } set path(path) { this._path = path; this._nativeObject = null; this.prepared = false; this.invalidated(); } /** * Get the native asset object */ get nativeAsset() { return this._nativeObject; } /** * Returns true if this asset has audio output. */ get hasAudio() { var _a; return ((_a = this.nativeAsset) === null || _a === void 0 ? void 0 : _a.hasAudio()) || false; } /** * Returns true if this asset has video output. */ get hasVideo() { var _a; return ((_a = this.nativeAsset) === null || _a === void 0 ? void 0 : _a.hasVideo()) || false; } /** * Returns the duration of this asset. */ get duration() { var _a; return ((_a = this.nativeAsset) === null || _a === void 0 ? void 0 : _a.duration()) || 0; } /** * Returns the width of this asset. */ get width() { var _a; return ((_a = this.nativeAsset) === null || _a === void 0 ? void 0 : _a.width()) || 0; } /** * Returns the height of this asset. */ get height() { var _a; return ((_a = this.nativeAsset) === null || _a === void 0 ? void 0 : _a.height()) || 0; } } __decorate([ allowCallNativeAnytime ], Asset.prototype, "hasAudio", null); __decorate([ allowCallNativeAnytime ], Asset.prototype, "hasVideo", null); __decorate([ allowCallNativeAnytime ], Asset.prototype, "duration", null); __decorate([ allowCallNativeAnytime ], Asset.prototype, "width", null); __decorate([ allowCallNativeAnytime ], Asset.prototype, "height", null);