mirror of
https://github.com/AynaLivePlayer/AynaLivePlayer.git
synced 2026-05-19 09:15:47 +08:00
add plugin play duration control
This commit is contained in:
@@ -380,6 +380,30 @@
|
||||
"en": "User",
|
||||
"zh-CN": "普通用户"
|
||||
},
|
||||
"plugin.maxduration.description": {
|
||||
"en": "Set the maximum duration of a song",
|
||||
"zh-CN": "设置歌曲最长能播多久"
|
||||
},
|
||||
"plugin.maxduration.enable": {
|
||||
"en": "Enable",
|
||||
"zh-CN": "开启"
|
||||
},
|
||||
"plugin.maxduration.maxduration": {
|
||||
"en": "Max Duration (seconds)",
|
||||
"zh-CN": "最大时长 (秒)"
|
||||
},
|
||||
"plugin.maxduration.skiponplay": {
|
||||
"en": "Skip on play",
|
||||
"zh-CN": "播放时跳过"
|
||||
},
|
||||
"plugin.maxduration.skiponreach": {
|
||||
"en": "Skip when reach max duration",
|
||||
"zh-CN": "播放到最大时长时跳过"
|
||||
},
|
||||
"plugin.maxduration.title": {
|
||||
"en": "Audio Duration Control",
|
||||
"zh-CN": "歌曲时长控制"
|
||||
},
|
||||
"plugin.qiege.admin": {
|
||||
"en": "Admin",
|
||||
"zh-CN": "管理员"
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"AynaLivePlayer/internal/plugins"
|
||||
"AynaLivePlayer/internal/source"
|
||||
"AynaLivePlayer/plugin/diange"
|
||||
"AynaLivePlayer/plugin/durationmgmt"
|
||||
"AynaLivePlayer/plugin/qiege"
|
||||
"AynaLivePlayer/plugin/sourcelogin"
|
||||
"AynaLivePlayer/plugin/textinfo"
|
||||
@@ -23,6 +24,7 @@ func Initialize() {
|
||||
plugins.LoadPlugins(
|
||||
diange.NewDiange(), qiege.NewQiege(), sourcelogin.NewSourceLogin(),
|
||||
textinfo.NewTextInfo(),
|
||||
durationmgmt.NewMaxDuration(),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
const (
|
||||
ProgramName = "卡西米尔唱片机"
|
||||
Version uint32 = 0x010000
|
||||
Version uint32 = 0x010001
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
for build usage
|
||||
106
plugin/durationmgmt/durationmgmt.go
Normal file
106
plugin/durationmgmt/durationmgmt.go
Normal file
@@ -0,0 +1,106 @@
|
||||
package durationmgmt
|
||||
|
||||
import (
|
||||
"AynaLivePlayer/core/events"
|
||||
"AynaLivePlayer/global"
|
||||
"AynaLivePlayer/gui"
|
||||
"AynaLivePlayer/pkg/config"
|
||||
"AynaLivePlayer/pkg/event"
|
||||
"AynaLivePlayer/pkg/i18n"
|
||||
"AynaLivePlayer/pkg/logger"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/data/binding"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
type MaxDuration struct {
|
||||
config.BaseConfig
|
||||
MaxDuration int
|
||||
SkipOnPlay bool
|
||||
SkipOnReach bool
|
||||
skipped bool
|
||||
panel fyne.CanvasObject
|
||||
log logger.ILogger
|
||||
}
|
||||
|
||||
func NewMaxDuration() *MaxDuration {
|
||||
return &MaxDuration{
|
||||
MaxDuration: 60 * 10,
|
||||
SkipOnPlay: false,
|
||||
SkipOnReach: false,
|
||||
skipped: false,
|
||||
log: global.Logger.WithPrefix("plugin.maxduration"),
|
||||
}
|
||||
}
|
||||
|
||||
func (d *MaxDuration) Name() string {
|
||||
return "MaxDuration"
|
||||
}
|
||||
|
||||
func (d *MaxDuration) Enable() error {
|
||||
config.LoadConfig(d)
|
||||
gui.AddConfigLayout(d)
|
||||
global.EventManager.RegisterA(
|
||||
events.PlayerPropertyDurationUpdate,
|
||||
"plugin.maxduration.duration",
|
||||
func(event *event.Event) {
|
||||
data := event.Data.(events.PlayerPropertyDurationUpdateEvent)
|
||||
if int(data.Duration) > d.MaxDuration && d.SkipOnPlay {
|
||||
d.log.Infof("Skip on reach max duration %.2f/%d (on play)", data.Duration, d.MaxDuration)
|
||||
global.EventManager.CallA(
|
||||
events.PlayerPlayNextCmd, events.PlayerPlayNextCmdEvent{})
|
||||
}
|
||||
})
|
||||
global.EventManager.RegisterA(
|
||||
events.PlayerPropertyTimePosUpdate,
|
||||
"plugin.maxduration.timepos",
|
||||
func(event *event.Event) {
|
||||
data := event.Data.(events.PlayerPropertyTimePosUpdateEvent)
|
||||
if int(data.TimePos) > d.MaxDuration && d.SkipOnReach && !d.skipped {
|
||||
d.log.Infof("Skip on reach max duration %.2f/%d (on time pos reach)", data.TimePos, d.MaxDuration)
|
||||
d.skipped = true
|
||||
global.EventManager.CallA(
|
||||
events.PlayerPlayNextCmd, events.PlayerPlayNextCmdEvent{})
|
||||
}
|
||||
})
|
||||
global.EventManager.RegisterA(
|
||||
events.PlayerPlayingUpdate,
|
||||
"plugin.maxduration.play",
|
||||
func(event *event.Event) {
|
||||
d.skipped = false
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *MaxDuration) Disable() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *MaxDuration) Title() string {
|
||||
return i18n.T("plugin.maxduration.title")
|
||||
}
|
||||
|
||||
func (d *MaxDuration) Description() string {
|
||||
return i18n.T("plugin.maxduration.description")
|
||||
}
|
||||
|
||||
func (d *MaxDuration) CreatePanel() fyne.CanvasObject {
|
||||
if d.panel != nil {
|
||||
return d.panel
|
||||
}
|
||||
maxDurationInput := widget.NewEntryWithData(binding.IntToString(binding.BindInt(&d.MaxDuration)))
|
||||
skipOnPlayCheckbox := widget.NewCheckWithData(i18n.T("plugin.maxduration.enable"), binding.BindBool(&d.SkipOnPlay))
|
||||
skipOnReachCheckbox := widget.NewCheckWithData(i18n.T("plugin.maxduration.enable"), binding.BindBool(&d.SkipOnReach))
|
||||
d.panel = container.New(
|
||||
layout.NewFormLayout(),
|
||||
widget.NewLabel(i18n.T("plugin.maxduration.maxduration")),
|
||||
maxDurationInput,
|
||||
widget.NewLabel(i18n.T("plugin.maxduration.skiponplay")),
|
||||
skipOnPlayCheckbox,
|
||||
widget.NewLabel(i18n.T("plugin.maxduration.skiponreach")),
|
||||
skipOnReachCheckbox,
|
||||
)
|
||||
return d.panel
|
||||
}
|
||||
Reference in New Issue
Block a user