UNPKG

tav-media

Version:

Cross platform media editing framework

66 lines (65 loc) 2.52 kB
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 { FileSystem } from '../io/file-system'; import { Path } from '../io/path'; import { tav } from '../tav'; import { Asset } from './tav-asset'; /** * PAGAsset is an asset that can be used to play PAG file. * @hideconstructor * @category Assets */ export class PAGAsset extends Asset { constructor() { super(...arguments); this.type = 'PAGAsset'; } /** * Creates a PAG asset object from a specified range of a pag file, return null if the file does * not exist or it's not a valid pag file. * @param path The path of the pag file. * @returns The PAGAsset object. */ static MakeFromPath(path) { return __awaiter(this, void 0, void 0, function* () { const pagAsset = new PAGAsset(null, path); yield pagAsset.prepare(); const asset = yield pagAsset.build(); if (!asset) { pagAsset.release(); return null; } return pagAsset; }); } getPathForPAGEffect() { return this.localPath || this.path; } doPrepare() { const _super = Object.create(null, { doPrepare: { get: () => super.doPrepare } }); return __awaiter(this, void 0, void 0, function* () { yield _super.doPrepare.call(this); this.localPath = this.path; if (tav.PLATFORM === 'wx' || tav.PLATFORM === 'browser') { this.localPath = Path.getLocalFileName(this.path); yield FileSystem.download(this.localPath, this.path); } }); } createAsset() { return __awaiter(this, void 0, void 0, function* () { if (!this.localPath) return undefined; return tav.PAGAsset.MakeFromPath(this.localPath); }); } }