mirror of
https://github.com/AynaLivePlayer/AynaLivePlayer.git
synced 2025-12-15 22:48:16 +08:00
add plugin play duration control
This commit is contained in:
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