@alecefe/platzimediaplayer
Version:
An implementation of a MediaPlayer through the Professional Javascript Course
44 lines (43 loc) • 1.46 kB
JavaScript
;
exports.__esModule = true;
var MediaPlayer = /** @class */ (function () {
function MediaPlayer(config) {
this.media = config.el;
this.plugins = config.plugins || [];
this.initPlayer();
this.initPlugins();
}
MediaPlayer.prototype.play = function () {
this.media.play();
};
MediaPlayer.prototype.pause = function () {
this.media.pause();
};
MediaPlayer.prototype.togglePlay = function () {
(this.media.paused) ? this.media.play() : this.media.pause();
};
MediaPlayer.prototype.initPlayer = function () {
this.container = document.createElement('div');
this.media.parentNode.insertBefore(this.container, this.media);
this.container.appendChild(this.media);
this.container.style.position = 'relative';
};
MediaPlayer.prototype.initPlugins = function () {
var _this = this;
this.plugins.forEach(function (plugin) {
plugin.run(_this);
});
};
MediaPlayer.prototype.mute = function () {
this.media.muted = true;
};
MediaPlayer.prototype.unmute = function () {
this.media.muted = false;
};
MediaPlayer.prototype.toggleMute = function () {
// (this.media.muted)? this.media.muted = false : this.media.muted = true;
(this.media.muted) ? this.unmute() : this.mute();
};
return MediaPlayer;
}());
exports["default"] = MediaPlayer;