Skip to content

Commit

Permalink
feat: save volume to local
Browse files Browse the repository at this point in the history
  • Loading branch information
IronKinoko committed Nov 8, 2021
1 parent a5ae313 commit e817f17
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "agefans",
"version": "1.12.2",
"version": "1.13.0",
"description": "增强agefans播放功能,实现自动换集、无缝换集、画中画、历史记录、断点续播、显示视频源、获取当前页面全部视频等功能",
"main": "index.user.js",
"scripts": {
Expand Down
47 changes: 26 additions & 21 deletions src/player/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ class KPlayer {
const $header = $('<div id="k-player-header"/>')
$wrapper.append($video)

this.localConfigKey = 'kplayer'
this.statusSessionKey = 'k-player-status'

/**
* @type {{speed:number,continuePlay:boolean,autoNext:boolean,showProgress:boolean,volume:number}}
*/
this.localConfig = {
speed: 1,
continuePlay: true,
autoNext: true,
showProgress: true,
volume: 1,
}
try {
this.localConfig = Object.assign(
this.localConfig,
JSON.parse(window.localStorage.getItem(this.localConfigKey))
)
} catch (error) {
/** empty */
}

this.plyr = new Plyr('#k-player', {
autoplay: true,
keyboard: { global: true },
Expand All @@ -57,6 +79,7 @@ class KPlayer {
],
storage: false,
seekTime: 5,
volume: this.localConfig.volume,
speed: { options: speedList },
i18n: {
restart: '重播',
Expand Down Expand Up @@ -110,27 +133,6 @@ class KPlayer {
...opts,
})

this.localConfigKey = 'kplayer'
this.statusSessionKey = 'k-player-status'

/**
* @type {{speed:number,continuePlay:boolean,autoNext:boolean,showProgress:boolean}}
*/
this.localConfig = {
speed: 1,
continuePlay: true,
autoNext: true,
showProgress: true,
}
try {
this.localConfig = Object.assign(
this.localConfig,
JSON.parse(window.localStorage.getItem(this.localConfigKey))
)
} catch (error) {
/** empty */
}

this.$wrapper = $wrapper
this.$loading = $loading
this.$error = $error
Expand Down Expand Up @@ -242,6 +244,9 @@ class KPlayer {
this.on('exitfullscreen', () => {
this.$videoWrapper.removeClass('k-player-fullscreen')
})
this.on('volumechange', () => {
this.configSaveToLocal('volume', this.plyr.volume)
})
this.on('timeupdate', () => {
this.$progress
.find('.k-player-progress-current')
Expand Down

0 comments on commit e817f17

Please sign in to comment.