2020-02-26 05:26:43 +00:00
|
|
|
// Code generated by "inline -o templates.go -p cdr mixtape.tmpl templates/parts.tmpl" -- DO NOT EDIT --
|
2020-02-26 05:13:51 +00:00
|
|
|
|
|
|
|
package cdr
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ReadAsset(file string, useLocal bool) ([]byte, error) {
|
|
|
|
if useLocal {
|
|
|
|
return ioutil.ReadFile(file)
|
|
|
|
}
|
|
|
|
if f, ok := files[file]; ok {
|
|
|
|
return []byte(f), nil
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("file doesn't exist.")
|
|
|
|
}
|
|
|
|
|
|
|
|
var files = map[string]string{
|
2020-02-26 05:26:43 +00:00
|
|
|
"mixtape.tmpl": `{{define "mixtape"}}
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Mixtape</title>
|
2020-02-29 16:42:00 +00:00
|
|
|
<meta charset="UTF-8" />
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
2020-02-26 05:26:43 +00:00
|
|
|
<style type="text/css">
|
|
|
|
body {
|
|
|
|
font-size: 1.2em;
|
|
|
|
margin: 1em;
|
|
|
|
}
|
|
|
|
#playlist {
|
2020-02-29 15:50:22 +00:00
|
|
|
list-style: decimal-leading-zero;
|
2020-02-26 05:26:43 +00:00
|
|
|
margin: 1em 0;
|
|
|
|
}
|
|
|
|
#playlist li {
|
|
|
|
margin: 0.5em 0;
|
|
|
|
}
|
2020-02-29 16:25:46 +00:00
|
|
|
li p {
|
|
|
|
display: none;
|
|
|
|
font-style: italic;
|
|
|
|
}
|
2020-02-29 15:50:22 +00:00
|
|
|
li.active a {
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
2020-02-29 16:25:46 +00:00
|
|
|
li.active p {
|
|
|
|
display: block;
|
|
|
|
}
|
2020-02-26 05:26:43 +00:00
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
{{template "full-player" .Tracks}}
|
|
|
|
</body>
|
|
|
|
</html>
|
2020-02-29 16:25:46 +00:00
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{define "track-info"}}
|
|
|
|
{{if eq .Num 1}}
|
|
|
|
<p>[Here I might introduce this mix.]</p>
|
|
|
|
<p>[Some notes about track 1.]</p>
|
|
|
|
{{else if eq .Num 2}}
|
|
|
|
<p>[Some notes about track 2.]</p>
|
|
|
|
{{else if eq .Num 5}}
|
|
|
|
<p>[Some notes about track 5.]</p>
|
|
|
|
{{end}}
|
2020-02-26 05:26:43 +00:00
|
|
|
{{end}}`,
|
2020-02-26 05:13:51 +00:00
|
|
|
"templates/parts.tmpl": `{{define "player"}}
|
|
|
|
{{with $x := index . 0}}
|
|
|
|
<audio id="player" preload="auto" tabindex="0" controls>
|
|
|
|
<source src="{{$x.Filename}}">
|
|
|
|
</audio>
|
|
|
|
{{end}}
|
2020-02-29 16:18:38 +00:00
|
|
|
{{end}}
|
|
|
|
{{define "playlist"}}
|
2020-02-26 05:13:51 +00:00
|
|
|
<ol id="playlist">
|
|
|
|
{{range $i, $el := .}}
|
|
|
|
<li{{if eq $i 0}} class="active"{{end}}>
|
|
|
|
<a href="{{$el.Filename}}">{{$el.Artist}} - {{$el.Title}}</a>
|
2020-02-29 16:25:46 +00:00
|
|
|
{{template "track-info" $el}}
|
2020-02-26 05:13:51 +00:00
|
|
|
</li>
|
|
|
|
{{end}}
|
|
|
|
</ol>
|
|
|
|
{{end}}
|
|
|
|
|
2020-02-29 16:25:46 +00:00
|
|
|
{{define "track-info"}}{{end}}
|
|
|
|
|
2020-02-26 05:13:51 +00:00
|
|
|
{{define "full-player"}}
|
|
|
|
{{template "player" .}}
|
2020-02-29 16:18:38 +00:00
|
|
|
{{template "playlist" .}}
|
2020-02-26 05:13:51 +00:00
|
|
|
{{template "playlist-js"}}
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{define "playlist-js"}}
|
|
|
|
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
$(document).ready(function() {
|
2020-02-29 16:19:41 +00:00
|
|
|
var current = 0;
|
|
|
|
var $audio = $('#player');
|
|
|
|
var $playlist = $('#playlist');
|
|
|
|
var $tracks = $playlist.find('li a');
|
|
|
|
var len = $tracks.length;
|
2020-02-26 05:13:51 +00:00
|
|
|
|
2020-02-29 16:19:41 +00:00
|
|
|
$playlist.on('click', 'a', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
link = $(this);
|
|
|
|
current = link.parent().index();
|
|
|
|
console.log(current);
|
|
|
|
play(link, $audio[0]);
|
|
|
|
});
|
|
|
|
$audio[0].addEventListener('ended', function (e) {
|
|
|
|
playNext();
|
|
|
|
});
|
|
|
|
$('a#next').on('click', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
playNext();
|
|
|
|
});
|
|
|
|
$('a#prev').on('click', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
playPrev();
|
|
|
|
});
|
|
|
|
|
|
|
|
function playPrev() {
|
|
|
|
current--;
|
|
|
|
if (current <= 0) {
|
|
|
|
current = len;
|
|
|
|
link = $playlist.find('a')[0];
|
|
|
|
} else {
|
|
|
|
link = $playlist.find('a')[current];
|
|
|
|
}
|
|
|
|
play($(link), $audio[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function playNext() {
|
|
|
|
current++;
|
|
|
|
if (current == len) {
|
|
|
|
current = 0;
|
|
|
|
link = $playlist.find('a')[0];
|
|
|
|
} else {
|
|
|
|
link = $playlist.find('a')[current];
|
|
|
|
}
|
|
|
|
play($(link), $audio[0]);
|
2020-02-26 05:13:51 +00:00
|
|
|
}
|
|
|
|
|
2020-02-29 16:19:41 +00:00
|
|
|
function play($link, $player) {
|
2020-02-26 05:13:51 +00:00
|
|
|
$player.src = $link.attr('href');
|
|
|
|
par = $link.parent();
|
|
|
|
par.addClass('active').siblings().removeClass('active');
|
|
|
|
$player.load();
|
|
|
|
$player.play();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
{{end}}`,
|
2020-02-29 16:19:41 +00:00
|
|
|
}
|