add blurhash image preview

This commit is contained in:
Jonas Heinrich 2020-10-23 22:18:05 +02:00
parent 6f433a6f1a
commit 26d494a696
7 changed files with 51 additions and 28 deletions

5
package-lock.json generated
View File

@ -11267,6 +11267,11 @@
"resolved": "https://registry.npmjs.org/vue/-/vue-2.6.12.tgz", "resolved": "https://registry.npmjs.org/vue/-/vue-2.6.12.tgz",
"integrity": "sha512-uhmLFETqPPNyuLLbsKz6ioJ4q7AZHzD8ZVFNATNyICSZouqP2Sz0rotWQC8UNBF6VGSCs5abnKJoStA6JbCbfg==" "integrity": "sha512-uhmLFETqPPNyuLLbsKz6ioJ4q7AZHzD8ZVFNATNyICSZouqP2Sz0rotWQC8UNBF6VGSCs5abnKJoStA6JbCbfg=="
}, },
"vue-blurhash": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/vue-blurhash/-/vue-blurhash-0.1.2.tgz",
"integrity": "sha512-VfIiQW2+F1HsJktumGsEwCsp0CYLdnmTcCA3nMvZ8Bze8bkpp9tonIygzBnjUKN0WZyOxb22i9QQ+lqgngjedA=="
},
"vue-color": { "vue-color": {
"version": "2.7.1", "version": "2.7.1",
"resolved": "https://registry.npmjs.org/vue-color/-/vue-color-2.7.1.tgz", "resolved": "https://registry.npmjs.org/vue-color/-/vue-color-2.7.1.tgz",

View File

@ -39,6 +39,7 @@
"jquery": "^3.5.1", "jquery": "^3.5.1",
"music-metadata": "^7.4.1", "music-metadata": "^7.4.1",
"vue": "^2.6.12", "vue": "^2.6.12",
"vue-blurhash": "^0.1.2",
"vue-router": "^3.4.7", "vue-router": "^3.4.7",
"vuex": "^3.5.1" "vuex": "^3.5.1"
}, },

View File

@ -33,7 +33,6 @@ import { Howl } from 'howler'
import { generateUrl } from '@nextcloud/router' import { generateUrl } from '@nextcloud/router'
import { showError } from '@nextcloud/dialogs' import { showError } from '@nextcloud/dialogs'
import axios from '@nextcloud/axios' import axios from '@nextcloud/axios'
import store from '../store'
let audioPlayer = null let audioPlayer = null
@ -109,8 +108,6 @@ export default {
* @param {Object} station Station object * @param {Object} station Station object
*/ */
doPlay(station) { doPlay(station) {
this.player.isPlaying = true
if (audioPlayer !== null) { if (audioPlayer !== null) {
audioPlayer.fade(1, 0, 500) // FIXME persistent volume state audioPlayer.fade(1, 0, 500) // FIXME persistent volume state
// FIXME fade out // FIXME fade out
@ -119,6 +116,7 @@ export default {
{ {
'User-Agent': 'Nextcloud Radio/1.0.0', // FIXME global version, doesnt seem to work 'User-Agent': 'Nextcloud Radio/1.0.0', // FIXME global version, doesnt seem to work
}) })
const vm = this
audioPlayer = new Howl({ audioPlayer = new Howl({
src: [station.url_resolved], src: [station.url_resolved],
volume: 0, volume: 0,
@ -128,15 +126,16 @@ export default {
} }
}, },
onplay() { onplay() {
store.player.isPlaying = true vm.$store.dispatch('isPlaying', true)
store.player.isBuffering = false vm.$store.dispatch('isBuffering', false)
}, },
onpause() { onpause() {
store.player.isPlaying = false vm.$store.dispatch('isPlaying', false)
store.player.isBuffering = false vm.$store.dispatch('isBuffering', false)
}, },
onload() { onload() {
store.player.isBuffering = true vm.$store.dispatch('isPlaying', true)
vm.$store.dispatch('isBuffering', true)
}, },
}) })
audioPlayer.play() audioPlayer.play()

View File

@ -19,7 +19,6 @@
value="this.volume" value="this.volume"
@input="changeVolume"> @input="changeVolume">
<span class="stationMetadata" /> <span class="stationMetadata" />
{{ player.isPlaying }}
</div> </div>
</template> </template>
@ -28,7 +27,11 @@ export default {
data: () => ({ data: () => ({
sliderVal: 0, sliderVal: 0,
}), }),
inject: ['player'], computed: {
player() {
return this.$store.state.player
},
},
methods: { methods: {
changeVolume() { changeVolume() {
this.$emit('changeVolume', this.sliderVal) this.$emit('changeVolume', this.sliderVal)

View File

@ -15,10 +15,14 @@
:key="idx" :key="idx"
:class="{ selected: idx === activeItem}"> :class="{ selected: idx === activeItem}">
<td @click="doPlay(idx, station)"> <td @click="doPlay(idx, station)">
<div class="stationIcon" <blur-hash-image
:style="{ backgroundImage: `url('${ station.favicon }')` }"> class="stationIcon"
width="32"
height="32"
hash="LdHfL}oJR$WBKnfi%3ofT0kCM{ay"
:src="station.favicon">
<span :class="{ 'icon-starred': stationsFavored.includes(idx) }" /> <span :class="{ 'icon-starred': stationsFavored.includes(idx) }" />
</div> </blur-hash-image>
</td> </td>
<td class="nameColumn" @click="doPlay(idx, station)"> <td class="nameColumn" @click="doPlay(idx, station)">
<span class="innernametext"> <span class="innernametext">
@ -153,11 +157,6 @@ table {
} }
.stationIcon { .stationIcon {
width: 32px;
height: 32px;
background-repeat: no-repeat;
background-size: contain;
background-position: center;
cursor: pointer; cursor: pointer;
} }

View File

@ -28,11 +28,16 @@ import { translate, translatePlural } from '@nextcloud/l10n'
import App from './App' import App from './App'
import jquery from 'jquery' import jquery from 'jquery'
import VueBlurHash from 'vue-blurhash'
import 'vue-blurhash/dist/vue-blurhash.css'
Vue.prototype.t = translate Vue.prototype.t = translate
Vue.prototype.n = translatePlural Vue.prototype.n = translatePlural
Vue.prototype.$jquery = jquery Vue.prototype.$jquery = jquery
Vue.use(VueBlurHash)
export default new Vue({ export default new Vue({
el: '#content', el: '#content',
store, store,

View File

@ -3,16 +3,27 @@ import Vuex from 'vuex'
Vue.use(Vuex) Vue.use(Vuex)
export default new Vuex.Store({ export default new Vuex.Store({
player: { state: {
isPlaying: false, player: {
isBuffering: false, isPlaying: false,
volume: 0, isBuffering: false,
count: 0, volume: 0,
}, },
mutations: { },
increment(player) { mutations: {
player.count++ isPlaying(state, playerState) {
state.player.isPlaying = playerState
},
isBuffering(state, bufferingState) {
state.player.isBuffering = bufferingState
},
},
actions: {
isPlaying(context, playerState) {
context.commit('isPlaying', playerState)
},
isBuffering(context, bufferingState) {
context.commit('isBuffering', bufferingState)
}, },
}, },
strict: true,
}) })