Skip to content
This repository was archived by the owner on Nov 25, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions js/canvas-video-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ var CanvasVideoPlayer = function(options) {
audio: false,
timelineSelector: false,
resetOnLastFrame: true,
loop: false
loop: false,
muted: false
};

for (i in options) {
Expand Down Expand Up @@ -50,7 +51,7 @@ var CanvasVideoPlayer = function(options) {
if (this.options.audio) {
if (typeof(this.options.audio) === 'string'){
// Use audio selector from options if specified
this.audio = document.querySelectorAll(this.options.audio)[0];
this.audio = document.querySelector(this.options.audio);

if (!this.audio) {
console.error('Element for the "audio" not found');
Expand All @@ -70,6 +71,8 @@ var CanvasVideoPlayer = function(options) {
// User have to manually start the audio
this.options.autoplay = false;
}

this.muted = this.options.muted;
}

// Canvas context
Expand Down Expand Up @@ -206,7 +209,7 @@ CanvasVideoPlayer.prototype.play = function() {
if (this.options.audio) {
// Resync audio and video
this.audio.currentTime = this.video.currentTime;
this.audio.play();
if (!this.muted) this.audio.play();
}
};

Expand All @@ -227,6 +230,18 @@ CanvasVideoPlayer.prototype.playPause = function() {
}
};

CanvasVideoPlayer.prototype.mute = function (setMute) {
if (setMute !== true && setMute !== false) setMute = !this.muted;
this.muted = setMute;
if (!this.audio) return;
if (this.muted) {
this.audio.pause();
} else {
this.audio.currentTime = this.video.currentTime;
this.audio.play();
}
}

CanvasVideoPlayer.prototype.loop = function() {
var self = this;

Expand Down