2020-06-29 18:23:56 +00:00
|
|
|
<template>
|
2020-07-16 20:49:08 +00:00
|
|
|
<audio id="preview-track" @canplay="onCanPlay" @timeupdate="onTimeUpdate" ref="preview">
|
2020-06-29 18:23:56 +00:00
|
|
|
<source id="preview-track_source" src="" type="audio/mpeg" />
|
|
|
|
</audio>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import $ from 'jquery'
|
2020-07-16 22:11:28 +00:00
|
|
|
import EventBus from '@/utils/EventBus'
|
2020-06-29 18:23:56 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
data: () => ({
|
|
|
|
previewStopped: false
|
|
|
|
}),
|
2020-07-16 20:49:08 +00:00
|
|
|
mounted() {
|
|
|
|
this.$refs.preview.volume = 1
|
|
|
|
|
|
|
|
EventBus.$on('trackPreview:playPausePreview', this.playPausePreview)
|
|
|
|
EventBus.$on('trackPreview:stopStackedTabsPreview', this.stopStackedTabsPreview)
|
|
|
|
EventBus.$on('trackPreview:previewMouseEnter', this.previewMouseEnter)
|
|
|
|
EventBus.$on('trackPreview:previewMouseLeave', this.previewMouseLeave)
|
|
|
|
},
|
2020-06-29 18:23:56 +00:00
|
|
|
methods: {
|
|
|
|
async onCanPlay() {
|
2020-07-16 20:49:08 +00:00
|
|
|
await this.$refs.preview.play()
|
2020-06-29 18:23:56 +00:00
|
|
|
|
|
|
|
this.previewStopped = false
|
2020-07-16 20:49:08 +00:00
|
|
|
$(this.$refs.preview).animate({ volume: vol.preview_max_volume / 100 }, 500)
|
2020-06-29 18:23:56 +00:00
|
|
|
},
|
|
|
|
onTimeUpdate() {
|
|
|
|
// Prevents first time entering in this function
|
2020-07-16 20:49:08 +00:00
|
|
|
if (isNaN(this.$refs.preview.duration)) return
|
|
|
|
if (this.$refs.preview.currentTime <= this.$refs.preview.duration - 1) return
|
2020-06-29 18:23:56 +00:00
|
|
|
|
2020-07-16 20:49:08 +00:00
|
|
|
$(this.$refs.preview).animate({ volume: 0 }, 800)
|
2020-06-29 18:23:56 +00:00
|
|
|
|
|
|
|
this.previewStopped = true
|
|
|
|
|
|
|
|
$('a[playing] > .preview_controls').css({ opacity: 0 })
|
|
|
|
$('*').removeAttr('playing')
|
|
|
|
$('.preview_controls').text('play_arrow')
|
|
|
|
$('.preview_playlist_controls').text('play_arrow')
|
2020-07-16 20:49:08 +00:00
|
|
|
},
|
|
|
|
playPausePreview(e) {
|
|
|
|
e.preventDefault()
|
|
|
|
|
|
|
|
const { currentTarget: obj } = event
|
|
|
|
|
|
|
|
var $icon = obj.tagName == 'I' ? $(obj) : $(obj).children('i')
|
|
|
|
|
|
|
|
if ($(obj).attr('playing')) {
|
|
|
|
if (this.$refs.preview.paused) {
|
|
|
|
this.$refs.preview.play()
|
|
|
|
this.previewStopped = false
|
|
|
|
|
|
|
|
$icon.text('pause')
|
|
|
|
|
|
|
|
$(this.$refs.preview).animate({ volume: vol.preview_max_volume / 100 }, 500)
|
|
|
|
} else {
|
|
|
|
this.previewStopped = true
|
|
|
|
|
|
|
|
$icon.text('play_arrow')
|
|
|
|
|
|
|
|
$(this.$refs.preview).animate({ volume: 0 }, 250, 'swing', () => {
|
|
|
|
this.$refs.preview.pause()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$('*').removeAttr('playing')
|
|
|
|
$(obj).attr('playing', true)
|
|
|
|
|
|
|
|
$('.preview_controls').text('play_arrow')
|
|
|
|
$('.preview_playlist_controls').text('play_arrow')
|
|
|
|
$('.preview_controls').css({ opacity: 0 })
|
|
|
|
|
|
|
|
$icon.text('pause')
|
|
|
|
$icon.css({ opacity: 1 })
|
|
|
|
|
|
|
|
this.previewStopped = false
|
|
|
|
|
|
|
|
$(this.$refs.preview).animate({ volume: 0 }, 250, 'swing', () => {
|
|
|
|
this.$refs.preview.pause()
|
|
|
|
$('#preview-track_source').prop('src', $(obj).data('preview'))
|
|
|
|
this.$refs.preview.load()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
stopStackedTabsPreview() {
|
|
|
|
if (
|
|
|
|
$('.preview_playlist_controls').filter(function() {
|
|
|
|
return $(this).attr('playing')
|
|
|
|
}).length > 0
|
|
|
|
) {
|
|
|
|
$(this.$refs.preview).animate({ volume: 0 }, 800)
|
|
|
|
this.previewStopped = true
|
|
|
|
$('.preview_playlist_controls').removeAttr('playing')
|
|
|
|
$('.preview_playlist_controls').text('play_arrow')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
previewMouseEnter(e) {
|
|
|
|
$(e.currentTarget).css({ opacity: 1 })
|
|
|
|
},
|
|
|
|
previewMouseLeave(event) {
|
|
|
|
const { currentTarget: obj } = event
|
|
|
|
|
|
|
|
if (
|
|
|
|
($(obj)
|
|
|
|
.parent()
|
|
|
|
.attr('playing') &&
|
|
|
|
this.previewStopped) ||
|
|
|
|
!$(obj)
|
|
|
|
.parent()
|
|
|
|
.attr('playing')
|
|
|
|
) {
|
|
|
|
$(obj).css({ opacity: 0 }, 200)
|
|
|
|
}
|
2020-06-29 18:23:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
</style>
|