UNPKG

tav-media

Version:

Cross platform media editing framework

69 lines (68 loc) 3.23 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()); }); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import { tav } from '../tav'; import { MediaClip } from './tav-media-clip'; import { makeClipAssetPath } from '../utils/clip-asset-path'; /** * A Media which has a audio output only. * @hideconstructor * @category Clips */ export class AudioClip extends MediaClip { constructor() { super(...arguments); this.type = 'Audio'; } /** * Creates a Audio Clip object from a Audio asset, return null if the asset does * not exist or it's not a valid audio asset. */ static MakeFromAsset(asset, contentStartTime, contentDuration) { return __awaiter(this, void 0, void 0, function* () { if (!(asset === null || asset === void 0 ? void 0 : asset.path) || (asset === null || asset === void 0 ? void 0 : asset.type) !== 'AudioAsset') { return null; } const audioClip = new AudioClip(); audioClip.contentStartTime = contentStartTime; audioClip.contentDuration = contentDuration; const myAsset = asset; myAsset.path = makeClipAssetPath(audioClip.id, asset.path); yield myAsset.build(); audioClip._asset = myAsset; return audioClip; }); } clone() { const newAudio = new AudioClip(); const _a = this, { _nativeObject: _nativeClip, parent, id, nativeInvalidated } = _a, otherProperties = __rest(_a, ["_nativeObject", "parent", "id", "nativeInvalidated"]); return Object.assign(newAudio, otherProperties); } createClip() { var _a, _b; return __awaiter(this, void 0, void 0, function* () { if (!((_a = this.asset) === null || _a === void 0 ? void 0 : _a.path) || ((_b = this.asset) === null || _b === void 0 ? void 0 : _b.type) !== 'AudioAsset') { return undefined; } const nativeAsset = yield this.asset.build(); return yield tav.Audio.MakeFrom(nativeAsset, this.contentStartTime || 0, this.contentDuration || this.duration || 0); }); } }