New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add reversed mode & improvements to lyrics animation #1226
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c706eaf
feat(reversed-mode): add reversed mode & improvements to lyrics anima…
GalvinGao a1002fb
feat(lyrics-animation): improve `:active` style
GalvinGao 5924e3c
fix: extra white space after artist in lyrics view
GalvinGao fa0c75e
refactor: remove unused function
GalvinGao 82aae94
feat: slightly add duration of transition to improve replication from…
GalvinGao File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ export default class { | |
this._enabled = false; // 是否启用Player | ||
this._repeatMode = 'off'; // off | on | one | ||
this._shuffle = false; // true | false | ||
this._reversed = false; | ||
this._volume = 1; // 0 to 1 | ||
this._volumeBeforeMuted = 1; // 用于保存静音前的音量 | ||
|
||
|
@@ -84,6 +85,18 @@ export default class { | |
this._shuffleTheList(); | ||
} | ||
} | ||
get reversed() { | ||
return this._reversed; | ||
} | ||
set reversed(reversed) { | ||
if (this._isPersonalFM) return; | ||
if (reversed !== true && reversed !== false) { | ||
console.warn('reversed: invalid args, must be Boolean'); | ||
return; | ||
} | ||
console.log('changing reversed to:', reversed); | ||
this._reversed = reversed; | ||
} | ||
get volume() { | ||
return this._volume; | ||
} | ||
|
@@ -180,27 +193,43 @@ export default class { | |
}, 1000); | ||
} | ||
_getNextTrack() { | ||
const next = this._reversed ? this.current - 1 : this.current + 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
個人拙見。 |
||
|
||
if (this._playNextList.length > 0) { | ||
let trackID = this._playNextList.shift(); | ||
return [trackID, this.current]; | ||
} | ||
|
||
// 当歌曲是列表最后一首 && 循环模式开启 | ||
if (this.list.length === this.current + 1 && this.repeatMode === 'on') { | ||
return [this.list[0], 0]; | ||
// 循环模式开启,则重新播放当前模式下的相对的下一首 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 能有 Unit Test 更好。 |
||
if (this.repeatMode === 'on') { | ||
if (this._reversed && this.current === 0) { | ||
// 倒序模式,当前歌曲是第一首,则重新播放列表最后一首 | ||
return [this.list[this.list.length - 1], this.list.length - 1]; | ||
} else if (this.list.length === this.current + 1) { | ||
// 正序模式,当前歌曲是最后一首,则重新播放第一首 | ||
return [this.list[0], 0]; | ||
} | ||
} | ||
|
||
// 返回 [trackID, index] | ||
return [this.list[this.current + 1], this.current + 1]; | ||
return [this.list[next], next]; | ||
} | ||
_getPrevTrack() { | ||
// 当歌曲是列表第一首 && 循环模式开启 | ||
if (this.current === 0 && this.repeatMode === 'on') { | ||
return [this.list[this.list.length - 1], this.list.length - 1]; | ||
const next = this._reversed ? this.current + 1 : this.current - 1; | ||
|
||
// 循环模式开启,则重新播放当前模式下的相对的下一首 | ||
if (this.repeatMode === 'on') { | ||
if (this._reversed && this.current === 0) { | ||
// 倒序模式,当前歌曲是最后一首,则重新播放列表第一首 | ||
return [this.list[0], 0]; | ||
} else if (this.list.length === this.current + 1) { | ||
// 正序模式,当前歌曲是第一首,则重新播放列表最后一首 | ||
return [this.list[this.list.length - 1], this.list.length - 1]; | ||
} | ||
} | ||
|
||
// 返回 [trackID, index] | ||
return [this.list[this.current - 1], this.current - 1]; | ||
return [this.list[next], next]; | ||
} | ||
async _shuffleTheList(firstTrackID = this._currentTrack.id) { | ||
let list = this._list.filter(tid => tid !== firstTrackID); | ||
|
@@ -659,6 +688,9 @@ export default class { | |
switchShuffle() { | ||
this.shuffle = !this.shuffle; | ||
} | ||
switchReversed() { | ||
this.reversed = !this.reversed; | ||
} | ||
|
||
clearPlayNextList() { | ||
this._playNextList = []; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
檢查類型建議用 typeof:
typeof reversed !== 'boolean'