Fix #59: Use color-thief for setting player colors based on track cover
This commit is contained in:
parent
e67e290325
commit
a910929132
|
@ -87,9 +87,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="ui inverted segment player-wrapper">
|
|
||||||
<player></player>
|
<player></player>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -150,6 +148,7 @@ export default {
|
||||||
$sidebar-color: #1B1C1D;
|
$sidebar-color: #1B1C1D;
|
||||||
|
|
||||||
.sidebar {
|
.sidebar {
|
||||||
|
background: $sidebar-color;
|
||||||
@include media(">tablet") {
|
@include media(">tablet") {
|
||||||
display:flex;
|
display:flex;
|
||||||
flex-direction:column;
|
flex-direction:column;
|
||||||
|
@ -211,11 +210,6 @@ $sidebar-color: #1B1C1D;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.player-wrapper {
|
|
||||||
border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
|
|
||||||
background-color: rgb(46, 46, 46) !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.logo {
|
.logo {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
|
<div class="ui inverted segment player-wrapper" :style="style">
|
||||||
<div class="player">
|
<div class="player">
|
||||||
<audio-track
|
<audio-track
|
||||||
ref="currentAudio"
|
ref="currentAudio"
|
||||||
|
@ -13,7 +14,7 @@
|
||||||
<div v-if="currentTrack" class="track-area ui unstackable items">
|
<div v-if="currentTrack" class="track-area ui unstackable items">
|
||||||
<div class="ui inverted item">
|
<div class="ui inverted item">
|
||||||
<div class="ui tiny image">
|
<div class="ui tiny image">
|
||||||
<img v-if="currentTrack.album.cover" :src="Track.getCover(currentTrack)">
|
<img ref="cover" @load="updateBackground" v-if="currentTrack.album.cover" :src="Track.getCover(currentTrack)">
|
||||||
<img v-else src="../../assets/audio/default-cover.png">
|
<img v-else src="../../assets/audio/default-cover.png">
|
||||||
</div>
|
</div>
|
||||||
<div class="middle aligned content">
|
<div class="middle aligned content">
|
||||||
|
@ -133,13 +134,14 @@
|
||||||
@keydown.l.prevent.exact="$store.commit('player/toggleLooping')"
|
@keydown.l.prevent.exact="$store.commit('player/toggleLooping')"
|
||||||
@keydown.s.prevent.exact="shuffle"
|
@keydown.s.prevent.exact="shuffle"
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import {mapState, mapGetters, mapActions} from 'vuex'
|
import {mapState, mapGetters, mapActions} from 'vuex'
|
||||||
import GlobalEvents from '@/components/utils/global-events'
|
import GlobalEvents from '@/components/utils/global-events'
|
||||||
|
import ColorThief from '@/vendor/color-thief'
|
||||||
|
|
||||||
import Track from '@/audio/track'
|
import Track from '@/audio/track'
|
||||||
import AudioTrack from '@/components/audio/Track'
|
import AudioTrack from '@/components/audio/Track'
|
||||||
|
@ -153,9 +155,12 @@ export default {
|
||||||
AudioTrack
|
AudioTrack
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
|
let defaultAmbiantColors = [[46, 46, 46], [46, 46, 46], [46, 46, 46], [46, 46, 46]]
|
||||||
return {
|
return {
|
||||||
sliderVolume: this.volume,
|
sliderVolume: this.volume,
|
||||||
Track: Track
|
Track: Track,
|
||||||
|
defaultAmbiantColors: defaultAmbiantColors,
|
||||||
|
ambiantColors: defaultAmbiantColors
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
|
@ -177,6 +182,14 @@ export default {
|
||||||
let target = this.$refs.progress
|
let target = this.$refs.progress
|
||||||
time = e.layerX / target.offsetWidth * this.duration
|
time = e.layerX / target.offsetWidth * this.duration
|
||||||
this.$refs.currentAudio.setCurrentTime(time)
|
this.$refs.currentAudio.setCurrentTime(time)
|
||||||
|
},
|
||||||
|
updateBackground () {
|
||||||
|
if (!this.currentTrack.album.cover) {
|
||||||
|
this.ambiantColors = this.defaultAmbiantColors
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let image = this.$refs.cover
|
||||||
|
this.ambiantColors = ColorThief.prototype.getPalette(image, 4).slice(0, 4)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -195,9 +208,34 @@ export default {
|
||||||
durationFormatted: 'player/durationFormatted',
|
durationFormatted: 'player/durationFormatted',
|
||||||
currentTimeFormatted: 'player/currentTimeFormatted',
|
currentTimeFormatted: 'player/currentTimeFormatted',
|
||||||
progress: 'player/progress'
|
progress: 'player/progress'
|
||||||
})
|
}),
|
||||||
|
style: function () {
|
||||||
|
let style = {
|
||||||
|
'background': this.ambiantGradiant
|
||||||
|
}
|
||||||
|
return style
|
||||||
|
},
|
||||||
|
ambiantGradiant: function () {
|
||||||
|
let indexConf = [
|
||||||
|
{orientation: 330, percent: 100, opacity: 0.7},
|
||||||
|
{orientation: 240, percent: 90, opacity: 0.7},
|
||||||
|
{orientation: 150, percent: 80, opacity: 0.7},
|
||||||
|
{orientation: 60, percent: 70, opacity: 0.7}
|
||||||
|
]
|
||||||
|
let gradients = this.ambiantColors.map((e, i) => {
|
||||||
|
let [r, g, b] = e
|
||||||
|
let conf = indexConf[i]
|
||||||
|
return `linear-gradient(${conf.orientation}deg, rgba(${r}, ${g}, ${b}, ${conf.opacity}) 10%, rgba(255, 255, 255, 0) ${conf.percent}%)`
|
||||||
|
}).join(', ')
|
||||||
|
return gradients
|
||||||
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
currentTrack (newValue) {
|
||||||
|
if (!newValue) {
|
||||||
|
this.ambiantColors = this.defaultAmbiantColors
|
||||||
|
}
|
||||||
|
},
|
||||||
volume (newValue) {
|
volume (newValue) {
|
||||||
this.sliderVolume = newValue
|
this.sliderVolume = newValue
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue