nativescript-transcoder
Version:
A nativescript-transcoder plugin, to transcode videos (use AVFoundation on iOS and android-transcoder on Android)
128 lines • 5.45 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var observable_1 = require("tns-core-modules/data/observable");
var decorators_1 = require("./decorators");
var TranscoderVideoCodec;
(function (TranscoderVideoCodec) {
TranscoderVideoCodec["Auto"] = "AUTO";
TranscoderVideoCodec["H264"] = "H264";
TranscoderVideoCodec["H265"] = "H265";
})(TranscoderVideoCodec = exports.TranscoderVideoCodec || (exports.TranscoderVideoCodec = {}));
var TranscoderAudioCodec;
(function (TranscoderAudioCodec) {
TranscoderAudioCodec["Aac"] = "AAC";
})(TranscoderAudioCodec = exports.TranscoderAudioCodec || (exports.TranscoderAudioCodec = {}));
var TranscoderStatus;
(function (TranscoderStatus) {
TranscoderStatus["Idle"] = "IDLE";
TranscoderStatus["Transcoding"] = "TRANSCODING";
TranscoderStatus["Completed"] = "COMPLETED";
TranscoderStatus["Failed"] = "FAILED";
TranscoderStatus["Canceled"] = "CANCELED";
})(TranscoderStatus = exports.TranscoderStatus || (exports.TranscoderStatus = {}));
var TranscoderEventList;
(function (TranscoderEventList) {
TranscoderEventList["Canceled"] = "canceled";
TranscoderEventList["Completed"] = "completed";
TranscoderEventList["Failed"] = "failed";
TranscoderEventList["Progress"] = "progress";
})(TranscoderEventList = exports.TranscoderEventList || (exports.TranscoderEventList = {}));
var TranscoderNativeTranscoder;
(function (TranscoderNativeTranscoder) {
TranscoderNativeTranscoder["Hardware"] = "HARDWARE";
})(TranscoderNativeTranscoder = exports.TranscoderNativeTranscoder || (exports.TranscoderNativeTranscoder = {}));
var TranscoderExceptionType;
(function (TranscoderExceptionType) {
TranscoderExceptionType["Canceled"] = "CANCELED";
TranscoderExceptionType["Failed"] = "FAILED";
TranscoderExceptionType["InvalidInputFormat"] = "INVALID_INPUT";
TranscoderExceptionType["InvalidOutputResolution"] = "INVALID_OUTPUT_RESOLUTION";
TranscoderExceptionType["InvalidOutputVideoCodec"] = "INVALID_OUTPUT_VIDEO_CODEC";
TranscoderExceptionType["InvalidOutputFormat"] = "INVALID_OUTPUT_FORMAT";
})(TranscoderExceptionType = exports.TranscoderExceptionType || (exports.TranscoderExceptionType = {}));
var TranscoderException = (function (_super) {
__extends(TranscoderException, _super);
function TranscoderException(type, message, nativeError) {
var _this = _super.call(this, message) || this;
_this.type = type;
_this.nativeError = nativeError;
Object.setPrototypeOf(_this, TranscoderException.prototype);
return _this;
}
return TranscoderException;
}(Error));
exports.TranscoderException = TranscoderException;
var TranscoderCommon = (function (_super) {
__extends(TranscoderCommon, _super);
function TranscoderCommon(filePath, options) {
if (options === void 0) { options = {}; }
var _this = _super.call(this) || this;
_this.progress = null;
_this.status = TranscoderStatus.Idle;
_this.error = null;
_this.filePath = filePath;
_this.options = Object.assign({
videoBitrate: null,
audioBitrate: null,
videoCodec: TranscoderVideoCodec.Auto,
audioCodec: TranscoderAudioCodec.Aac,
nativeTranscoder: TranscoderNativeTranscoder.Hardware,
resolutionConstraint: null,
}, options);
return _this;
}
Object.defineProperty(TranscoderCommon.prototype, "audioBitrate", {
get: function () {
return this.options.audioBitrate;
},
set: function (bitrate) {
if (this.status !== TranscoderStatus.Idle) {
throw new Error('Can not change bitrate while transcoding.');
}
this.options.audioBitrate = bitrate;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TranscoderCommon.prototype, "videoBitrate", {
get: function () {
return this.options.videoBitrate;
},
set: function (bitrate) {
if (this.status !== TranscoderStatus.Idle) {
throw new Error('Can not change bitrate while transcoding.');
}
this.options.videoBitrate = bitrate;
},
enumerable: true,
configurable: true
});
TranscoderCommon.prototype.transcode = function () {
if (this.status !== TranscoderStatus.Idle) {
throw new Error('Transcode has already been called');
}
this.status = TranscoderStatus.Transcoding;
return this._transcode();
};
TranscoderCommon.prototype.cancel = function () {
this.status = TranscoderStatus.Canceled;
};
TranscoderCommon.prototype._transcode = function () {
return Promise.reject(null);
};
__decorate([
decorators_1.ObservableProperty,
__metadata("design:type", Number)
], TranscoderCommon.prototype, "progress", void 0);
__decorate([
decorators_1.ObservableProperty,
__metadata("design:type", String)
], TranscoderCommon.prototype, "status", void 0);
__decorate([
decorators_1.ObservableProperty,
__metadata("design:type", Object)
], TranscoderCommon.prototype, "error", void 0);
return TranscoderCommon;
}(observable_1.Observable));
exports.TranscoderCommon = TranscoderCommon;
//# sourceMappingURL=transcoder.common.js.map
;