-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: output file on mac, break out js form html for testing in the fu…
…ture
- Loading branch information
jaredkotoff
committed
May 17, 2021
1 parent
6081507
commit d1f6930
Showing
4 changed files
with
118 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const player = document.getElementById("videoPlayer1"); | ||
const player2 = document.getElementById("videoPlayer2"); | ||
player.addEventListener("ended", () => playNext(player2, player), {passive: true}); | ||
player2.addEventListener("ended", () => playNext(player, player2), {passive: true}); | ||
|
||
/* Initial logic */ | ||
|
||
const mp4Source = player.getElementsByClassName("mp4Source")[0]; | ||
let video = `${mediaFolder}${mediaFiles[0]}`; | ||
// check if we played this video last run | ||
if (mediaFiles.length > 1 && localStorage.getItem("lastPlayed") === video) { | ||
video = `${mediaFolder}${mediaFiles[1]}`; | ||
} | ||
mp4Source.setAttribute("src", video); | ||
player.load(); | ||
|
||
playNext(player, player2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const mediaFolder = "{{ .MediaFolder }}"; | ||
const initMediaFiles = ["{{ StringsJoin .MediaFiles "\", \"" }}"]; | ||
const transitionVideo = "{{ .TransitionVideo }}"; | ||
const playOnlyOne = {{ .PlayOnlyOne }}; | ||
const loopFirstVideo = {{ .LoopFirstVideo }}; | ||
const mediaFiles = shuffleArr(initMediaFiles); | ||
let count = 0; | ||
let isTransition = true; | ||
function shuffleArr(a) { | ||
var j, x, i; | ||
for (i = a.length - 1; i > 0; i--) { | ||
j = Math.floor(Math.random() * (i + 1)); | ||
x = a[i]; | ||
a[i] = a[j]; | ||
a[j] = x; | ||
} | ||
return a; | ||
} | ||
function playNext(player, nextPlayer) { | ||
const nextMp4Source = nextPlayer.getElementsByClassName("mp4Source")[0]; | ||
const currentMp4Source = player.getElementsByClassName('mp4Source')[0]; | ||
if(!loopFirstVideo) { | ||
if (!transitionVideo || !isTransition) { | ||
count++; | ||
if (count > mediaFiles.length - 1) count = 0; | ||
} | ||
} | ||
if (playOnlyOne) { | ||
if (count > 1) { | ||
// Remove video after playing once | ||
currentMp4Source.removeAttribute('src'); | ||
nextMp4Source.removeAttribute('src'); | ||
player.load(); | ||
nextPlayer.load(); | ||
} | ||
} else { | ||
// TODO: we can use this opacity to crossfade between mediaFiles | ||
player.style["z-index"] = 1; | ||
player.style["opacity"] = 1; | ||
nextPlayer.style["z-index"] = 0; | ||
nextPlayer.style["opacity"] = 0; | ||
let video = `${mediaFolder}${mediaFiles[count]}`; | ||
const transitionVideoPath = `${mediaFolder}${transitionVideo}` | ||
if (transitionVideo && transitionVideo !== "" && isTransition) { | ||
video = transitionVideoPath; | ||
isTransition = false; | ||
} else { | ||
isTransition = true; | ||
} | ||
nextMp4Source.setAttribute("src", video); | ||
nextPlayer.load(); | ||
nextPlayer.pause(); | ||
const currentVideo = currentMp4Source.getAttribute("src"); | ||
if (currentVideo !== transitionVideoPath) { | ||
localStorage.setItem("lastPlayed", currentVideo); | ||
} | ||
player.play(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters