-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 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,40 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>alternative html5 playlist</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<style> | ||
body { | ||
font-family: "Lucida Console", monospace; | ||
background-color: plum; | ||
} | ||
|
||
.container { | ||
width: 30em; | ||
margin: auto; | ||
padding: 1em; | ||
background-color: #FFCC66; | ||
} | ||
|
||
audio { | ||
width: 98%; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>alternative approach</h1> | ||
<p>Just include one magical javascript, some audio tags and everything works as expected:</p> | ||
<p>Anke</p> | ||
<audio controls src="02-anke.mp3" preload="auto"></audio> | ||
<p>Metalik</p> | ||
<audio controls src="09-metalik.mp3" preload="metadata"></audio> | ||
<p>Regenschori</p> | ||
<audio controls src="14-regenschori.mp3" preload="metadata"></audio> | ||
<p>(alternative version of <a href="https://github.com/severak/html5-playlist">severak/html5-playlist</a>)</p> | ||
<p>(<a href="index.html">original version</a>)</p> | ||
</div> | ||
<script src="auto-playlist.js"></script> | ||
</body> | ||
</html> |
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,25 @@ | ||
// Automatic playlist for HTML5 audio tags. | ||
// | ||
// Based on code by lijnenspel posted on lines forum (https://llllllll.co/t/izzzzi-net-username-sharing/69588/239) | ||
|
||
pauseOthers = (e) => { | ||
document.querySelectorAll("audio").forEach((a) => { | ||
if (e.target != a) { | ||
a.pause() | ||
} | ||
}) | ||
} | ||
|
||
playNext = (e) => { | ||
let allaudio = Array.from(document.querySelectorAll("audio")); | ||
let nextid = allaudio.indexOf(e.target) + 1 | ||
if(allaudio[nextid]){ | ||
allaudio[nextid].play() | ||
} | ||
} | ||
|
||
document.querySelectorAll("audio") | ||
.forEach((a) => { | ||
a.addEventListener("play", pauseOthers) | ||
a.addEventListener("ended", playNext) | ||
}) |
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