one
Version:
One is a React framework for web, iOS, and Android apps.
331 lines (328 loc) • 9.12 kB
JavaScript
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: true
});
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var player_native_exports = {};
__export(player_native_exports, {
AudioPlayer: () => AudioPlayer,
createPlayer: () => createPlayer
});
module.exports = __toCommonJS(player_native_exports);
var import_nativeError = require("../nativeError.native.js");
var import_events = require("./events.native.js");
var import_hybrid = require("./hybrid.native.js");
var import_validate = require("./validate.native.js");
function _class_call_check(instance, Constructor) {
if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _create_class(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
function _define_property(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value,
enumerable: true,
configurable: true,
writable: true
});
} else obj[key] = value;
return obj;
}
function native() {
return (0, import_hybrid.audioNative)();
}
function sync(work) {
try {
return work();
} catch (error) {
return (0, import_nativeError.rethrowNativeError)(error);
}
}
var AudioPlayer = /* @__PURE__ */ (function() {
"use strict";
function AudioPlayer2(id, updateIntervalMs) {
var _this = this;
_class_call_check(this, AudioPlayer2);
_define_property(this, "playerId", void 0);
_define_property(this, "removed", false);
_define_property(this, "events", void 0);
this.playerId = id;
this.events = (0, import_events.createPlayerEvents)(function() {
return _this.getStatus();
}, updateIntervalMs);
}
_create_class(AudioPlayer2, [
{
key: "id",
get: function get() {
return this.playerId;
}
},
{
key: "currentTime",
get: function get() {
return this.status().currentTime;
}
},
{
key: "duration",
get: function get() {
return this.status().duration;
}
},
{
key: "playing",
get: function get() {
return this.status().playing;
}
},
{
key: "paused",
get: function get() {
return this.status().paused;
}
},
{
key: "isLoaded",
get: function get() {
return this.status().isLoaded;
}
},
{
key: "isBuffering",
get: function get() {
return this.status().isBuffering;
}
},
{
key: "isAudioSamplingSupported",
get: function get() {
return false;
}
},
{
key: "loop",
get: function get() {
return this.status().loop;
},
set: function set(value) {
var _this = this;
this.assertUsable("loop");
(0, import_validate.assertFlag)(value, "AudioPlayer.loop");
sync(function() {
return native().setPlayerLoop(_this.playerId, value);
});
}
},
{
key: "muted",
get: function get() {
return this.status().muted;
},
set: function set(value) {
var _this = this;
this.assertUsable("muted");
(0, import_validate.assertFlag)(value, "AudioPlayer.muted");
sync(function() {
return native().setPlayerMuted(_this.playerId, value);
});
}
},
{
key: "volume",
get: function get() {
return this.status().volume;
},
set: function set(value) {
var _this = this;
this.assertUsable("volume");
(0, import_validate.assertVolume)(value, "AudioPlayer.volume");
sync(function() {
return native().setPlayerVolume(_this.playerId, value);
});
}
},
{
key: "playbackRate",
get: function get() {
return this.status().playbackRate;
}
},
{
key: "shouldCorrectPitch",
get: function get() {
return this.status().shouldCorrectPitch;
},
set: function set(value) {
var _this = this;
this.assertUsable("shouldCorrectPitch");
(0, import_validate.assertFlag)(value, "AudioPlayer.shouldCorrectPitch");
sync(function() {
return native().setPlayerPitchCorrection(_this.playerId, value);
});
}
},
{
key: "play",
value: function play() {
var _this = this;
this.assertUsable("play");
sync(function() {
return native().playerPlay(_this.playerId);
});
}
},
{
key: "pause",
value: function pause() {
var _this = this;
this.assertUsable("pause");
sync(function() {
return native().playerPause(_this.playerId);
});
}
},
{
key: "seekTo",
value: function seekTo(seconds, toleranceMillisBefore, toleranceMillisAfter) {
this.assertUsable("seekTo");
(0, import_validate.assertSeconds)(seconds, "AudioPlayer.seekTo");
if (toleranceMillisBefore !== void 0) {
(0, import_validate.assertTolerance)(toleranceMillisBefore, "AudioPlayer.seekTo");
}
if (toleranceMillisAfter !== void 0) {
(0, import_validate.assertTolerance)(toleranceMillisAfter, "AudioPlayer.seekTo");
}
return native().playerSeek(this.playerId, seconds, toleranceMillisBefore, toleranceMillisAfter).catch(import_nativeError.rethrowNativeError);
}
},
{
key: "replace",
value: function replace(source) {
var _this = this;
this.assertUsable("replace");
var normalized = (0, import_validate.normalizeSource)(source, "AudioPlayer.replace");
sync(function() {
return native().playerReplace(_this.playerId, normalized.uri, normalized.headers);
});
}
},
{
key: "remove",
value: function remove() {
var _this = this;
if (this.removed) return;
this.removed = true;
this.events.removeAll();
sync(function() {
return native().removePlayer(_this.playerId);
});
}
},
{
key: "getStatus",
value: function getStatus() {
var _status_error;
var status = this.status();
return {
currentTime: status.currentTime,
didJustFinish: status.didJustFinish,
duration: status.duration,
error: (_status_error = status.error) !== null && _status_error !== void 0 ? _status_error : null,
id: this.playerId,
isBuffering: status.isBuffering,
isLoaded: status.isLoaded,
loop: status.loop,
mute: status.muted,
playbackRate: status.playbackRate,
playing: status.playing,
shouldCorrectPitch: status.shouldCorrectPitch
};
}
},
{
key: "setPlaybackRate",
value: function setPlaybackRate(rate, pitchCorrectionQuality) {
var _this = this;
this.assertUsable("setPlaybackRate");
(0, import_validate.assertRate)(rate, "AudioPlayer.setPlaybackRate");
if (pitchCorrectionQuality !== void 0) {
(0, import_validate.assertPitchQuality)(pitchCorrectionQuality, "AudioPlayer.setPlaybackRate");
}
sync(function() {
return native().setPlayerRate(_this.playerId, rate, pitchCorrectionQuality);
});
}
},
{
key: "addListener",
value: function addListener(event, listener) {
this.assertUsable("addListener");
return this.events.add(event, listener);
}
},
{
key: "removeAllListeners",
value: function removeAllListeners() {
this.events.removeAll();
}
},
{
key: "status",
value: function status() {
var _this = this;
this.assertUsable("status");
return sync(function() {
return native().getPlayerStatus(_this.playerId);
});
}
},
{
key: "assertUsable",
value: function assertUsable(verb) {
if (this.removed) throw new Error(`AudioPlayer.${verb}: the player was removed`);
}
}
]);
return AudioPlayer2;
})();
function createPlayer() {
var source = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : null, options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
var normalized = (0, import_validate.normalizeSource)(source, "Audio.createPlayer");
var updateIntervalMs = (0, import_validate.resolveUpdateInterval)(options, "Audio.createPlayer");
(0, import_validate.assertCrossOrigin)(options.crossOrigin, "Audio.createPlayer");
var id = sync(function() {
return native().createPlayer(normalized.uri, normalized.headers);
});
return new AudioPlayer(id, updateIntervalMs);
}
//# sourceMappingURL=player.native.js.map