Skip to content

Commit

Permalink
初步完善歌词
Browse files Browse the repository at this point in the history
  • Loading branch information
lyswhut committed Mar 2, 2021
1 parent 9f72831 commit 040fcfb
Show file tree
Hide file tree
Showing 12 changed files with 779 additions and 120 deletions.
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"plugins": [
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-transform-modules-umd",
"@babel/plugin-transform-runtime"
"@babel/plugin-transform-runtime",
"@babel/plugin-proposal-class-properties"
]
}
150 changes: 57 additions & 93 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
"homepage": "https://github.com/lyswhut/lx-music-desktop#readme",
"devDependencies": {
"@babel/core": "^7.13.1",
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-transform-modules-umd": "^7.13.0",
"@babel/plugin-transform-runtime": "^7.13.4",
Expand Down
18 changes: 15 additions & 3 deletions src/renderer/components/core/Player.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ div(:class="$style.player")
</template>

<script>
import Lyric from 'lrc-file-parser'
import Lyric from '@renderer/utils/lyric-font-player'
import { rendererSend, rendererOn, NAMES } from '../../../common/ipc'
import { formatPlayTime2, getRandom, checkPath, setTitle, clipboardWriteText, debounce, throttle, assertApiSupport } from '../../utils'
import { mapGetters, mapActions, mapMutations } from 'vuex'
Expand Down Expand Up @@ -452,6 +452,9 @@ export default {
})
window.lrc = new Lyric({
className: 'lrc-content',
shadowContent: false,
activeLineClassName: 'active',
onPlay: (line, text) => {
this.lyric.text = text
this.lyric.line = line
Expand All @@ -463,7 +466,7 @@ export default {
this.lyric.lines = lines
this.lyric.line = 0
},
offset: 80,
// offset: 80,
})
this.handleRegisterEvent('on')
Expand Down Expand Up @@ -641,6 +644,7 @@ export default {
this.getLrc(targetSong).then(() => {
this.musicInfo.lrc = targetSong.lrc
this.musicInfo.tlrc = targetSong.tlrc
this.musicInfo.lxlrc = targetSong.lxlrc
}).catch(() => {
this.status = this.statusText = this.$t('core.player.lyric_error')
}).finally(() => {
Expand All @@ -658,6 +662,7 @@ export default {
this.musicInfo.songmid = null
this.musicInfo.lrc = null
this.musicInfo.tlrc = null
this.musicInfo.lxlrc = null
this.musicInfo.url = null
this.nowPlayTime = 0
this.maxPlayTime = 0
Expand Down Expand Up @@ -848,7 +853,14 @@ export default {
})
},
setLyric() {
window.lrc.setLyric((this.setting.player.isShowLyricTransition && this.musicInfo.tlrc ? (this.musicInfo.tlrc + '\n') : '') + (this.musicInfo.lrc || ''))
window.lrc.setLyric(
this.musicInfo.lxlrc ? this.musicInfo.lxlrc : this.musicInfo.lrc,
// (
// this.setting.player.isShowLyricTransition && this.musicInfo.tlrc
// ? (this.musicInfo.tlrc + '\n')
// : ''
// ) + (this.musicInfo.lrc || ''),
)
if (this.isPlay && (this.musicInfo.url || this.listId == 'download')) {
window.lrc.play(audio.currentTime * 1000)
this.handleUpdateWinLyricInfo('play', audio.currentTime * 1000)
Expand Down
73 changes: 61 additions & 12 deletions src/renderer/components/core/PlayerDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
div(:class="$style.right")
div(:class="[$style.lyric, lyricEvent.isMsDown ? $style.draging : null]" @wheel="handleWheel" @mousedown="handleLyricMouseDown" ref="dom_lyric")
div(:class="$style.lyricSpace")
p(v-for="(info, index) in lyricLines" :key="index" :class="lyric.line == index ? $style.lrcActive : null") {{info.text}}
div(:class="[$style.lyricText]" ref="dom_lyric_text")
//- p(v-for="(info, index) in lyricLines" :key="index" :class="lyric.line == index ? $style.lrcActive : null") {{info.text}}
div(:class="$style.lyricSpace")

material-music-comment(:class="$style.comment" :titleFormat="this.setting.download.fileName" :musicInfo="musicInfo" v-model="isShowComment")
Expand Down Expand Up @@ -158,11 +159,14 @@ export default {
handler(n, o) {
this.isSetedLines = true
if (o) {
this.$refs.dom_lyric_text.textContent = ''
this.setLyric(n)
this._lyricLines = n
if (n.length) {
this.lyricLines = n
this.$nextTick(() => {
this.dom_lines = this.$refs.dom_lyric.querySelectorAll('p')
this.dom_lines = this.$refs.dom_lyric.querySelectorAll('.lrc-content')
this.handleScrollLrc()
})
} else {
Expand All @@ -174,15 +178,15 @@ export default {
if (this.lyricLines === this._lyricLines && this._lyricLines.length) return
this.lyricLines = this._lyricLines
this.$nextTick(() => {
this.dom_lines = this.$refs.dom_lyric.querySelectorAll('p')
this.dom_lines = this.$refs.dom_lyric.querySelectorAll('.lrc-content')
this.handleScrollLrc()
})
}, 50)
}
} else {
this.lyricLines = n
this.$nextTick(() => {
this.dom_lines = this.$refs.dom_lyric.querySelectorAll('p')
this.dom_lines = this.$refs.dom_lyric.querySelectorAll('.lrc-content')
this.handleScrollLrc()
})
}
Expand Down Expand Up @@ -235,6 +239,8 @@ export default {
document.addEventListener('mousemove', this.handleMouseMsMove)
document.addEventListener('mouseup', this.handleMouseMsUp)
window.addEventListener('resize', this.handleResize)
console.log('object', this.$refs.dom_lyric_text)
this.setLyric(this.lyricLines)
},
beforeDestroy() {
this.clearLyricScrollTimeout()
Expand All @@ -250,6 +256,13 @@ export default {
...mapMutations('player', [
'visiblePlayerDetail',
]),
setLyric(lines) {
const dom_lines = document.createDocumentFragment()
for (const line of lines) {
dom_lines.appendChild(line.dom_line)
}
this.$refs.dom_lyric_text.appendChild(dom_lines)
},
handleResize() {
this.setProgressWidth()
},
Expand Down Expand Up @@ -540,6 +553,7 @@ export default {
&:before {
position: absolute;
z-index: 1;
top: 0;
left: 0;
content: ' ';
Expand Down Expand Up @@ -568,13 +582,39 @@ export default {
&.draging {
cursor: grabbing;
}
p {
padding: 8px 0;
line-height: 1.2;
overflow-wrap: break-word;
transition: @transition-theme !important;
transition-property: color, font-size;
:global {
.lrc-content {
line-height: 1.2;
padding: 8px 0;
overflow-wrap: break-word;
&.active {
span {
// color: @color-theme;
font-size: 1.2em;
}
}
span {
transition: @transition-theme !important;
transition-property: font-size;
font-size: 1em;
background-repeat: no-repeat;
background-color: rgba(77, 77, 77, 0.9);
background-image: -webkit-linear-gradient(top, @color-theme, @color-theme);
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
background-size: 0 100%;
}
}
}
// p {
// padding: 8px 0;
// line-height: 1.2;
// overflow-wrap: break-word;
// transition: @transition-theme !important;
// transition-property: color, font-size;
// }
}
.lyric-space {
height: 70%;
Expand Down Expand Up @@ -736,6 +776,7 @@ each(@themes, {
.container {
border-left-color: ~'@{color-@{value}-theme}';
background-color: ~'@{color-@{value}-theme_2-background_1}';
// color: ~'@{color-@{value}-theme_2-font}';
}
.right {
&:before {
Expand Down Expand Up @@ -769,9 +810,17 @@ each(@themes, {
box-shadow: 0 0 4px ~'@{color-@{value}-theme-hover}';
// border-color: ~'@{color-@{value}-theme-hover}';
}
.lrc-active {
color: ~'@{color-@{value}-theme}';
:global {
.lrc-content {
span {
// background-color: ~'@{color-@{value}-theme_2-font}';
background-image: -webkit-linear-gradient(top, ~'@{color-@{value}-theme}', ~'@{color-@{value}-theme}');
}
}
}
// .lrc-active {
// color: ~'@{color-@{value}-theme}';
// }
.footerLeftControlBtns {
color: ~'@{color-@{value}-theme_2-font}';
}
Expand Down
16 changes: 11 additions & 5 deletions src/renderer/store/modules/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,21 @@ const actions = {
if (musicInfo.lrc && musicInfo.tlrc != null) {
if (musicInfo.lrc.startsWith('\ufeff[id:$00000000]')) {
let str = musicInfo.lrc.replace('\ufeff[id:$00000000]\n', '')
commit('setLrc', { musicInfo, lyric: str, tlyric: musicInfo.tlrc })
commit('setLrc', { musicInfo, lyric: str, tlyric: musicInfo.tlrc, lxlyric: musicInfo.tlrc })
} else if (musicInfo.lrc.startsWith('[id:$00000000]')) {
let str = musicInfo.lrc.replace('[id:$00000000]\n', '')
commit('setLrc', { musicInfo, lyric: str, tlyric: musicInfo.tlrc, lxlyric: musicInfo.tlrc })
}
return Promise.resolve()
}

if ((musicInfo.lxlrc == null && musicInfo.source != 'kg') || musicInfo.lxlrc != null) {
return Promise.resolve()
}
}

// lrcRequest = music[musicInfo.source].getLyric(musicInfo)
return getLyric.call(this, musicInfo).then(({ lyric, tlyric }) => {
return getLyric.call(this, musicInfo).then(({ lyric, tlyric, lxlyric }) => {
// lrcRequest = null
commit('setLrc', { musicInfo, lyric, tlyric })
commit('setLrc', { musicInfo, lyric, tlyric, lxlyric })
}).catch(err => {
// lrcRequest = null
return Promise.reject(err)
Expand Down Expand Up @@ -332,6 +337,7 @@ const mutations = {
setLrc(state, datas) {
datas.musicInfo.lrc = datas.lyric
datas.musicInfo.tlrc = datas.tlyric
datas.musicInfo.lxlrc = datas.lxlyric
},
setList(state, { list, index }) {
state.playMusicInfo = {
Expand Down
Loading

0 comments on commit 040fcfb

Please sign in to comment.