HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div id='app'>
<div id='player-wrapper' :data-show-list="(show_list) ? 'true' : 'false'" :data-show-info="(show_info) ? 'true' : 'false'">
<div id='ripple-effect-list' :class="{active: show_list == true}"></div>
<div class='toolbar'>
<div id='ripple-effect-info' :class="{active: show_info == true}"></div>
<div id='close' :class="{show: show_list == true || show_info == true}" @click='show_list = false; show_info = false'>
<i class="fas fa-times"></i>
</div>
<div class='list-icon' @click='show_list = !show_list' v-if='show_list == false && show_info == false'>
<i class="fas fa-stream"></i>
</div>
<div class='info-icon' @click='show_info = !show_info' v-if='show_list == false && show_info == false'>
<i class="fas fa-info-circle"></i>
</div>
</div>
<div class='info-container'>
<div class='info-wrapper' v-html='info'></div>
</div>
<div class='playlist-container'>
<div class='list-container'>
<div class='list-item' v-for='(c, i) in book.chapters' @click='audio_index = i' :class="{active: audio_index == i}">
<div class='loading' v-if='is_loading == true'> </div>
<div class="title">{{c.name}}</div>
<div class='meta'>
<span class=''>{{c.reader}}</span>
<span class=''>{{c.duration}}</span>
</div>
</div>
</div>
</div>
<div class='player-container'>
<div class="title-container">
<div class="title">{{book.title}}</div>
<div class="author">{{book.author}}</div>
</div>
<div class="cover-wrapper">
<div class='prev-next'>
<div class='prev' :class="{disabled: audio_index <= 0}" @click='playPrev'>
<i class="fas fa-backward"></i>
</div>
<div class='next' :class="{disabled: audio_index >= book.chapters.length - 1}" @click='playNext'>
<i class="fas fa-forward"></i>
</div>
</div>
<spectrum :pins='normlizeAudioPins' v-on:avarage="updateAvarage($event)"></spectrum>
<div class='cover' :style='coverArtTransition'>
<img src='https://mir-s3-cdn-cf.behance.net/project_modules/1400_opt_1/eee14d97766991.5ecd1593d2cbb.jpg'>
</div>
</div>
<div class="chapter">{{book.chapters[audio_index].name}}</div>
<div class="audio-bar-wrapper">
<div class="audio-bar-container" @mousedown='barClick'>
<div class="bar" ref='bar'>
<span class='loading' v-if='is_loading == true'></span>
<span class='played' :style="{width:handlePosition}"></span>
<span class='buffered' v-for='b in buffered' :style="{left: b.left, width: b.width}"></span>
</div>
<div class="handle" id='handle' :style="{left: handlePosition}"></div>
</div>
<div class="time-container">
<div class="current">{{currentTime}}</div>
<div class="end">{{endTime}}</div>
</div>
</div>
<div class='options'>
<div class='speed' @click="toggleSpeed"> {{speed}}x </div>
<div class='repeat' @click="repeat = !repeat" :class="{active: repeat == true}">
<i class='material-icons'>repeat</i>
</div>
<div class="auto-playlist" @click="list_play = !list_play" :class="{active: list_play == true}">
<i class="material-icons">playlist_play</i>
</div>
</div>
<div class='controls'>
<div class="decrease-minute" @click="moveAudio('decrease', '60')" :class='{inactive: current_time < 60}'>-1m</div>
<div class="decrease-seconds" @click="moveAudio('decrease', '30')" :class='{inactive: current_time < 30}'>-30s</div>
<div class="play-pause" @click='playAudio()'>
<i class="fas fa-play" v-if='is_playing == false'></i>
<i class="fas fa-pause" v-if='is_playing == true'></i>
</div>
<div class="increase-seconds" @click="moveAudio('increase', '30')" :class='{inactive: leftTime < 30}'>+30s</div>
<div class="increase-minute" @click="moveAudio('increase', '60')" :class='{inactive: leftTime < 60}'>+1m</div>
</div>
</div>
<div id='error-box' :class="{show: is_error == true}">
{{this.error_msg}}
</div>
</div>
</div>
<template id='spectrum-template'>
<svg id='spectrum'>
<polygon x="0" y="0" :points="points"></polygon>
</svg>
</template>
@import url("https://fonts.googleapis.com/css2?family=Roboto:wght@400&display=swap");
@import url("https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.0-2/css/all.min.css");
@import url("https://fonts.googleapis.com/icon?family=Material+Icons");
* {
box-sizing: border-box;
&::after,
&::before {
box-sizing: border-box;
}
}
$bg-color: hsl(53, 10%, 30%);
:root {
--bg-hue: 53; //53
--bg-color: linear-gradient(
to top,
hsl(var(--bg-hue), 20%, 18%),
hsl(var(--bg-hue), 7%, 24%)
);
--text-color: hsl(var(--bg-hue), 0%, 70%);
--hover-bg: rgba(255, 255, 255, 0.1);
--audio-bar-bg: hsl(calc(var(--bg-hue) - 10), 50%, 10%);
--audio-bar-played-bg: hsl(calc(var(--bg-hue) - 10), 30%, 40%);
--audio-bar-buffered-bg: hsl(calc(var(--bg-hue) - 10), 30%, 30%);
--audio-bar-loading-bg: rgba(255, 255, 255, 0.3);
--audio-handle-bg: #{lighten($bg-color, 30%)};
--spectrum-color: hsl(calc(var(--bg-hue) + 10), 15%, 35%);
--active-color: hsl(calc(var(--bg-hue) - 50), 50%, 70%);
--active-bg: hsl(calc(var(--bg-hue) + 10), 20%, 30%);
--scrollbar-foreground: hsl(calc(var(--bg-hue)), 20%, 30%);
--scrollbar-background: transparent;
}
html {
font-size: 80.5%;
user-select: none;
}
body {
height: 100%;
width: 100%;
font-family: "Roboto", "Arial", sans-serif;
background: url(https://www.toptal.com/designers/subtlepatterns/patterns/herringbone.png);
}
@mixin scrollbars(
$size: 4px,
$foreground-color: var(--scrollbar-foreground),
$background-color: var(--scrollbar-background)
) {
// For Google Chrome
&::-webkit-scrollbar {
width: $size;
height: $size;
}
&::-webkit-scrollbar-thumb {
background: $foreground-color;
border-radius: 0.3rem;
}
&::-webkit-scrollbar-track {
background: $background-color;
}
// For Internet Explorer
& {
scrollbar-face-color: $foreground-color;
scrollbar-track-color: $background-color;
// firefox
scrollbar-width: thin;
scrollbar-color: $foreground-color $background-color;
}
}
#ripple-effect-list,
#ripple-effect-info {
position: absolute;
top: 2%;
right: 4%;
height: 4em;
width: 4em;
background: var(--bg-color);
border-radius: 50%;
transition: all 0.3s ease-in-out;
z-index: 6;
transition-delay: 0.2s;
transform: scale(0);
&.active {
transform: scale(30);
}
}
#ripple-effect-info {
left: 4%;
}
#player-wrapper {
border-radius: 2rem;
height: 50rem;
width: 25rem;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
box-shadow: 1px 1px 10px 2px rgba(0, 0, 0, 0.2);
background: var(--bg-color);
overflow: hidden;
&[data-show-list="true"] {
#ripple-effect-list {
transition-delay: 0s;
}
.playlist-container {
pointer-events: initial;
.list-container {
opacity: 1;
transition-delay: 0.35s;
}
}
}
&[data-show-info="true"] {
#ripple-effect-info {
transition-delay: 0s;
}
.info-container {
pointer-events: initial;
.info-wrapper {
opacity: 1;
transition-delay: 0.35s;
}
}
}
.toolbar {
.list-icon,
.info-icon {
font-size: 1.3rem;
display: flex;
justify-content: flex-end;
margin-bottom: 0.1em;
position: absolute;
top: 2%;
right: 4%;
color: var(--text-color);
z-index: 8;
i {
padding: 1.2rem;
cursor: pointer;
transition: background-color 0.3s;
border-radius: 50%;
&:hover {
background-color: var(--hover-bg);
}
}
}
#close {
font-size: 1.5rem;
position: absolute;
top: -2%;
left: 50%;
color: var(--text-color);
z-index: 8;
transform: translate(-50%, -100%);
transition: all 0.3s;
&.show {
transform: translate(-50%, 0);
top: 2%;
}
i {
display: flex;
height: 2.35em;
width: 2.35em;
flex-direction: column;
justify-content: center;
align-items: center;
border-radius: 50%;
cursor: pointer;
transition: background-color 0.3s;
&:hover {
background-color: var(--hover-bg);
}
}
}
.info-icon {
left: 4%;
right: unset;
font-size: 1.5rem;
}
}
.info-container {
height: inherit;
width: inherit;
border-radius: inherit;
position: absolute;
display: flex;
flex-direction: column;
color: var(--text-color);
align-items: center;
font-size: 1.1rem;
padding: 5em 2.3em 2em;
pointer-events: none;
z-index: 6;
left: 0;
top: 0;
.info-wrapper {
opacity: 0;
overflow: auto;
transition: all 0.2s;
padding: 0 2em 0 0;
line-height: 1.7em;
@include scrollbars();
p {
margin: 0;
margin-bottom: 1.4em;
}
}
}
.playlist-container {
height: inherit;
width: inherit;
border-radius: inherit;
position: absolute;
display: flex;
flex-direction: column;
color: var(--text-color);
align-items: center;
font-size: 2rem;
padding: 3em 1em 1.5em;
pointer-events: none;
z-index: 6;
left: 0;
top: 0;
.list-container {
font-size: 1.3rem;
overflow: auto;
width: 100%;
padding-right: 0.5em;
@include scrollbars(4px);
transition-delay: 0;
opacity: 0;
transition: all 0.2s;
.list-item {
display: flex;
flex-direction: column;
margin-bottom: 0.2em;
cursor: pointer;
transition: all 0.2s;
padding: 0.8em 0.8em;
border-radius: 0.3em;
position: relative;
&:hover {
background-color: var(--hover-bg);
}
&.active {
background-color: var(--active-bg);
@keyframes loading-list {
0% {
background-position: 0 0;
}
100% {
background-position: 4em 0;
}
}
.loading {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-image: repeating-linear-gradient(
-70deg,
var(--audio-bar-loading-bg) 0% 30%,
rgba(243, 156, 18, 0) 30% 68%,
var(--audio-bar-loading-bg) 68% 100%
);
background-size: 4em 4em;
z-index: 0;
animation: loading-list 3s linear infinite;
pointer-events: none;
}
}
> div {
z-index: 1;
}
.meta {
display: flex;
justify-content: space-between;
font-size: 0.8em;
}
}
}
}
.player-container {
height: inherit;
width: inherit;
border-radius: inherit;
display: flex;
flex-direction: column;
color: var(--text-color);
align-items: center;
font-size: 2rem;
padding: 2.5em 0.5em 2em 0.5em;
.title {
font-size: 1em;
font-weight: bold;
white-space: nowrap;
text-transform: capitalize;
}
.author {
font-size: 0.5em;
text-align: center;
text-transform: capitalize;
}
.cover-wrapper {
position: relative;
height: 8em;
width: 8em;
margin: 1.5em 0;
.prev-next {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 50%;
z-index: 5;
display: flex;
justify-content: space-around;
align-items: center;
&:hover {
background-color: rgba(white, 0.1);
~ .cover img {
filter: sepia(0.5) saturate(2) blur(5px);
}
div {
opacity: 1;
&.disabled {
opacity: 0.2;
cursor: default;
}
}
}
div {
border-radius: 50%;
height: 20%;
width: 20%;
background-color: transp;
display: flex;
justify-content: center;
align-items: center;
padding: 1em;
color: var(--text-color);
cursor: pointer;
transition: all 0.2s;
font-size: 1.5em;
opacity: 0;
&:hover:not(.disabled) {
background-color: var(--hover-bg);
}
}
}
#spectrum {
height: 120%;
width: 120%;
border-radius: 50%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
polygon {
stroke: var(--spectrum-color);
stroke-width: 0.1em;
fill: transparent;
}
}
.cover {
overflow: hidden;
height: 100%;
width: 100%;
border-radius: 50%;
flex-shrink: 0;
img {
max-width: 100%;
filter: sepia(0.5) saturate(2);
transition: all 0.2s;
}
}
}
.chapter {
margin-bottom: 2em;
font-size: 0.7em;
}
.audio-bar-wrapper {
display: flex;
flex-direction: column;
width: 100%;
margin-bottom: 1em;
.audio-bar-container {
position: relative;
padding: 0.3rem 0;
&:hover .handle {
transform: translate(-50%, -50%) scale(1);
}
.bar {
width: 100%;
height: 0.1em;
background-color: var(--audio-bar-bg);
border-radius: 0.3em;
position: relative;
@keyframes loading {
0% {
background-position: 0 0;
}
100% {
background-position: 0.6em 0;
}
}
.loading {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-image: repeating-linear-gradient(
-55deg,
var(--audio-bar-loading-bg) 0% 30%,
rgba(243, 156, 18, 0) 30% 68%,
var(--audio-bar-loading-bg) 68% 100%
);
background-size: 0.6em 0.4em;
z-index: 5;
animation: loading 1s linear infinite;
}
.played {
position: absolute;
z-index: 3;
background-color: var(--audio-bar-played-bg);
height: 100%;
left: 0;
}
.buffered {
background-color: var(--audio-bar-buffered-bg);
display: inline-block;
height: 100%;
position: absolute;
z-index: 2;
}
}
.handle {
height: 0.6em;
width: 0.6em;
border-radius: 50%;
cursor: pointer;
background-color: var(--audio-handle-bg);
position: absolute;
transform: translate(-50%, -50%) scale(0);
top: 50%;
// box-shadow: 0 0 0rem 0.2rem rgba(255, 255, 255, 0.2);
z-index: 4;
transition: transform 0.3s;
}
}
.time-container {
display: flex;
justify-content: space-between;
font-size: 0.5em;
margin-top: 0.7em;
}
}
.options {
display: flex;
font-size: 0.5em;
justify-content: space-between;
width: 90%;
align-items: center;
margin-bottom: 1em;
div {
cursor: pointer;
transition: all 0.2s;
border-radius: 50%;
height: 3em;
width: 3em;
display: flex;
justify-content: center;
align-items: center;
&.repeat i {
font-size: 1.5em;
}
&.speed {
font-size: 1.1em;
}
&.inactive {
opacity: 0.3;
cursor: default;
}
&.active {
color: var(--active-color);
}
&:hover:not(.inactive) {
background-color: var(--hover-bg);
}
}
}
.controls {
display: flex;
font-size: 0.5em;
justify-content: space-between;
width: 90%;
align-items: center;
.play-pause {
font-size: 2em;
height: 2em;
width: 2em;
display: flex;
justify-content: center;
align-items: center;
}
div {
cursor: pointer;
transition: all 0.2s;
border-radius: 50%;
height: 3em;
width: 3em;
display: flex;
justify-content: center;
align-items: center;
&.inactive {
opacity: 0.3;
cursor: default;
}
&:hover:not(.inactive) {
background-color: var(--hover-bg);
}
}
}
}
}
#error-box {
background-color: #f8d7da;
padding: 1rem 2rem;
border: 0.1rem solid #f5c6cb;
position: absolute;
bottom: 10%;
width: 90%;
left: 50%;
border-radius: 0.4rem;
transition: all 0.3s;
transform: translate(-50%, 50%) scale(0);
pointer-events: none;
color: #721c24;
font-weight: bold;
&.show {
transform: translate(-50%, 50%) scale(1);
}
}
const book = {
title: "Crime and Punishment",
author: "Fyodor DOSTOYEVSKY",
cover_art:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_1708.jpg",
info: [
'Crime and Punishment is the second of Fyodor Dostoyevsky\'s full-length novels following his return from 5 years of exile in Siberia, and is considered the first great novel of his "mature" period of writing.',
"The novel focuses on the mental anguish and moral dilemmas of Rodion Raskolnikov, an impoverished ex-student in St. Petersburg who formulates and executes a plan to kill an unscrupulous pawnbroker for her cash.",
"Raskolnikov, in an attempt to defend his actions, argues that with the pawnbroker's money he can perform good deeds to counterbalance the crime while ridding the world of a vermin, and to test a theory of his that some people are naturally superior and have the right to commit crimes if it is in pursuit of a higher purpose. ( Mark Nelson)"
],
chapters: [
{
name: "Preface",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_00_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:05:38"
},
{
name: "Part 1 Chapter 1",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_01_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:21:23"
},
{
name: "Part 1 Chapter 2",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_02_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:46:57"
},
{
name: "Part 1 Chapter 3",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_03_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:33:07"
},
{
name: "Part 1 Chapter 4",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_04_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:32:15"
},
{
name: "Part 1 Chapter 5",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_05_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:25:51"
},
{
name: "Part 1 Chapter 6",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_06_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:31:09"
},
{
name: "Part 1 Chapter 7",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_07_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:29:42"
},
{
name: "Part 2 Chapter 1",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_08_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:43:11"
},
{
name: "Part 2 Chapter 2",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_09_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:26:38"
},
{
name: "Part 2 Chapter 3",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_10_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:33:18"
},
{
name: "Part 2 Chapter 4",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_11_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:25:24"
},
{
name: "Part 2 Chapter 5",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_12_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:27:43"
},
{
name: "Part 2 Chapter 6",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_13_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:49:49"
},
{
name: "Part 2 Chapter 7",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_14_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:44:41"
},
{
name: "Part 3 Chapter 1",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_15_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:36:07"
},
{
name: "Part 3 Chapter 2",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_16_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:28:49"
},
{
name: "Part 3 Chapter 3",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_17_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:34:38"
},
{
name: "Part 3 Chapter 4",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_18_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:28:31"
},
{
name: "Part 3 Chapter 5",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_19_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:47:14"
},
{
name: "Part 3 Chapter 6",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_20_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:27:42"
},
{
name: "Part 4 Chapter 1",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_21_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:31:11"
},
{
name: "Part 4 Chapter 2",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_22_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:30:21"
},
{
name: "Part 4 Chapter 3",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_23_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:20:28"
},
{
name: "Part 4 Chapter 4",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_24_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:41:15"
},
{
name: "Part 4 Chapter 5",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_25_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:44:37"
},
{
name: "Part 4 Chapter 6",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_26_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:18:55"
},
{
name: "Part 5 Chapter 1",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_27_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:39:53"
},
{
name: "Part 5 Chapter 2",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_28_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:30:54"
},
{
name: "Part 5 Chapter 3",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_29_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:36:12"
},
{
name: "Part 5 Chapter 4",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_30_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:43:50"
},
{
name: "Part 5 Chapter 5",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_31_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:33:45"
},
{
name: "Part 6 Chapter 1",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_32_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:25:02"
},
{
name: "Part 6 Chapter 2",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_33_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:35:50"
},
{
name: "Part 6 Chapter 3",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_34_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:23:58"
},
{
name: "Part 6 Chapter 4",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_35_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:28:07"
},
{
name: "Part 6 Chapter 5",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_36_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:35:37"
},
{
name: "Part 6 Chapter 6",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_37_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:34:10"
},
{
name: "Part 6 Chapter 7",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_38_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:23:22"
},
{
name: "Part 6 Chapter 8",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_39_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:25:57"
},
{
name: "Epilogue",
link:
"https://ia800604.us.archive.org/20/items/crime_punishment_3_1708_librivox/crimepunishment_40_dostoyevsky_128kb.mp3",
reader: "Mark Nelson",
duration: "00:39:00"
}
]
};
Vue.component("spectrum", {
template: "#spectrum-template",
props: ["pins"],
data: function () {
return {
radius: 50,
adjust: 0,
avarage: 0,
cover_art: null
};
},
mounted: function () {
const width = this.$el.getBoundingClientRect().width;
const innerWidth = (width * 100) / 130;
this.adjust = (width - innerWidth) / 2;
this.radius = innerWidth / 2;
},
methods: {
valueToPoint: function (value, index) {
let angle = (360 * index) / this.total - 90;
// convert to radians
angle = (angle * Math.PI) / 180;
var cos =
Math.cos(angle) * (this.radius + value) + this.radius + this.adjust;
var sin =
Math.sin(angle) * (this.radius + value) + this.radius + this.adjust;
return `${cos},${sin}`;
}
},
computed: {
points: function () {
let avarage_count = 0;
const retn = this.pins
.map((p, index) => {
avarage_count += p;
return this.valueToPoint(p, index);
})
.join(" ");
this.$emit("avarage", avarage_count / this.total);
return retn;
},
total: function () {
return this.pins.length;
}
}
});
new Vue({
el: "#app",
data: {
handle_clicked: false,
handle_position: 0,
bar: null,
is_playing: false,
is_loading: true,
is_error: false,
error_timeout: null,
error_msg: "",
audio_obj: null,
audio_index: 0,
duration: 0,
current_time: 0,
audio_pins: [],
analyser: null,
data_array: [],
buffered: [],
speed: 1,
repeat: false,
repeat_count: 0,
list_play: false,
show_list: false,
book: book,
show_info: false,
cover_art_avarage: 0
},
mounted: function () {
this.bar = this.$refs.bar.getBoundingClientRect();
let handle = this.$refs.handle;
document.addEventListener("mousedown", this.mouseDown);
document.addEventListener("mouseup", (e) => (this.handle_click = false));
document.addEventListener("mousemove", this.moveHandler);
window.addEventListener("resize", this.resizeHandler);
// initiate audio obj
this.audio_obj = new Audio(this.book.chapters[this.audio_index].link);
this.audio_obj.crossOrigin = "anonymous";
this.audio_obj.src = this.book.chapters[this.audio_index].link;
this.audio_obj.load();
this.audio_obj.addEventListener("loadeddata", () => {
this.duration = this.audio_obj.duration;
});
this.audio_obj.addEventListener("ended", this.onEnded);
this.audio_obj.addEventListener("progress", this.onProgress);
this.audio_obj.addEventListener("loadedmetadata", this.onProgress);
this.audio_obj.addEventListener("playing", (e) => (this.is_playing = true));
this.audio_obj.addEventListener("pause", (e) => (this.is_playing = false));
this.audio_obj.addEventListener(
"canplay",
(e) => (this.is_loading = false)
);
this.audio_obj.addEventListener("seeking", (e) => (this.is_loading = true));
this.audio_obj.onerror = this.onError;
},
methods: {
onError: function () {
let msg = this.audio_obj.error.code + `: ` + this.audio_obj.error.message;
console.error("ERROR", msg);
this.is_error = true;
this.error_msg = msg;
this.is_playing = false;
this.is_loading = false;
clearTimeout(this.error_timeout);
this.error_timeout = setTimeout(() => {
this.is_error = false;
this.error_msg = "";
}, 3500);
},
onEnded: function (event) {
this.audio_obj.currentTime = 0;
if (this.repeat && this.repeat_count < 1) {
this.audio_obj.play();
this.repeat_count = this.repeat_count + 1;
return;
}
if (this.repeat_count == 1) {
this.repeat_count = 0;
}
if (this.list_play) {
const newIndex = this.audio_index + 1;
if (newIndex < this.book.chapters.length) this.audio_index = newIndex;
return;
}
this.is_playing = false;
this.repeat = false;
},
onProgress: function (e) {
const oneSecond = 100 / this.duration;
const ranges = [];
for (var i = 0; i < this.audio_obj.buffered.length; i++) {
const start = this.audio_obj.buffered.start(i);
const end = this.audio_obj.buffered.end(i);
const position = {};
position.left = oneSecond * start + "%";
position.width = oneSecond * (end - start) + "%";
ranges.push(position);
}
this.buffered = ranges;
},
updateAvarage: function (event) {
this.cover_art_avarage = event;
},
timeUpdated: function () {
this.current_time = this.audio_obj.currentTime;
this.analyser.getByteTimeDomainData(this.data_array);
this.audio_pins = Array.from(this.data_array);
requestAnimationFrame(this.timeUpdated);
},
playNext: function () {
const newIndex = this.audio_index + 1;
if (newIndex >= this.book.chapters.length) return;
this.audio_index = newIndex;
},
playPrev: function () {
const newIndex = this.audio_index - 1;
if (newIndex < 0) return;
this.audio_index = newIndex;
},
initAnalyser: function () {
const ctx = new AudioContext();
this.analyser = ctx.createAnalyser();
const audioSrc = ctx.createMediaElementSource(this.audio_obj);
// we could configure the analyser: e.g. analyser.fftSize (for further infos read the spec)
// 256
this.analyser.minDecibels = -90;
this.analyser.maxDecibels = -10;
this.analyser.smoothingTimeConstant = 0.75;
this.analyser.fftSize = 128;
// we have to connect the MediaElementSource with the analyser
audioSrc.connect(this.analyser);
this.analyser.connect(ctx.destination);
const bufferLength = this.analyser.frequencyBinCount;
this.data_array = new Uint8Array(bufferLength);
},
playAudio: function () {
if (this.is_playing) this.audio_obj.pause();
else this.audio_obj.play();
if (this.analyser == null) {
this.initAnalyser();
requestAnimationFrame(this.timeUpdated);
}
},
toggleSpeed: function () {
const speedArray = [
"0.5",
"0.7",
"1",
"1.1",
"1.2",
"1.3",
"1.4",
"1.5",
"1.6",
"1.7",
"1.8",
"1.9",
"2"
];
const curerntIndex = speedArray.indexOf(this.speed.toString());
let newIndex = curerntIndex + 1;
if (newIndex > speedArray.length - 1) newIndex = 0;
this.speed = parseFloat(speedArray[newIndex]);
this.audio_obj.playbackRate = this.speed;
},
barClick: function (e) {
const clickPos = e.clientX - this.bar.x;
const time = (clickPos * this.duration) / this.bar.width;
this.audio_obj.currentTime = time;
this.handle_click = true;
},
mouseDown: function (e) {
if (e.target.id == "handle") this.handle_click = true;
},
resizeHandler: function () {
this.bar = this.$refs.bar.getBoundingClientRect();
},
formatSeconds: function (secs) {
var hr = Math.floor(secs / 3600);
var min = Math.floor((secs - hr * 3600) / 60);
var sec = Math.floor(secs - hr * 3600 - min * 60);
if (min < 10) {
min = "0" + min;
}
if (sec < 10) {
sec = "0" + sec;
}
return min + ":" + sec;
},
moveHandler: function (e) {
let barWidth = this.bar.width;
let barLeft = this.bar.x;
let barRight = this.bar.right;
if (this.handle_click) {
let left = e.clientX - barLeft;
if (left < 0) left = 0;
if (left > barWidth) left = barWidth;
this.current_time = (left * this.duration) / barWidth;
this.audio_obj.currentTime = this.current_time;
}
},
moveAudio: function (direction, amount) {
let newTime = this.current_time;
amount = parseInt(amount);
switch (direction) {
case "increase":
newTime = newTime + amount;
break;
case "decrease":
newTime = newTime - amount;
break;
}
if (newTime > this.duration || newTime < 0) newTime = this.current_time;
this.audio_obj.currentTime = newTime;
},
updateAudio: function (index) {}
},
computed: {
endTime: function () {
return this.formatSeconds(this.duration);
},
currentTime: function () {
return this.formatSeconds(this.current_time);
},
handlePosition: function () {
return (this.current_time * 100) / this.duration + "%";
},
leftTime: function () {
return this.duration - this.current_time;
},
maxAudioPin: function () {
return this.audio_pins
.slice()
.sort((a, b) => b - a)
.slice(0, 1);
},
normlizeAudioPins: function () {
// 20 is the max length
return this.audio_pins.map((p) => {
return (p * 20) / this.maxAudioPin;
});
},
info: function () {
return `<p>${this.book.info.join("</p><p>")}</p>`;
},
coverArtTransition: function () {
let scale = (this.cover_art_avarage * 100) / 20 / 100;
if (scale < 0.98) scale = 0.98;
return {
transform: `scale(${scale})`
};
},
currentLink: function () {
this.audio_obj.src = this.book.chapters[this.audio_index].link;
}
},
watch: {
audio_index: function (newIndex, oldVal) {
this.audio_obj.src = this.book.chapters[newIndex].link;
this.audio_obj.play();
this.is_loading = true;
}
}
});
Also see: Tab Triggers