1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-09-15 18:57:04 +00:00

feat: Media player: Conrol playback speed

fix  #1845
This commit is contained in:
Romain de Laage 2024-03-16 14:20:02 +01:00 committed by Frédéric Guillot
parent b68ada396a
commit 00dabc1d3c
31 changed files with 188 additions and 74 deletions

View file

@ -33,6 +33,7 @@ type SettingsForm struct {
DefaultHomePage string
CategoriesSortingOrder string
MarkReadOnView bool
MediaPlaybackRate float64
}
// Merge updates the fields of the given user.
@ -55,6 +56,7 @@ func (s *SettingsForm) Merge(user *model.User) *model.User {
user.DefaultHomePage = s.DefaultHomePage
user.CategoriesSortingOrder = s.CategoriesSortingOrder
user.MarkReadOnView = s.MarkReadOnView
user.MediaPlaybackRate = s.MediaPlaybackRate
if s.Password != "" {
user.Password = s.Password
@ -84,6 +86,10 @@ func (s *SettingsForm) Validate() *locale.LocalizedError {
}
}
if s.MediaPlaybackRate < 0.25 || s.MediaPlaybackRate > 4 {
return locale.NewLocalizedError("error.settings_media_playback_rate_range")
}
return nil
}
@ -101,6 +107,10 @@ func NewSettingsForm(r *http.Request) *SettingsForm {
if err != nil {
cjkReadingSpeed = 0
}
mediaPlaybackRate, err := strconv.ParseFloat(r.FormValue("media_playback_rate"), 64)
if err != nil {
mediaPlaybackRate = 1
}
return &SettingsForm{
Username: r.FormValue("username"),
Password: r.FormValue("password"),
@ -122,5 +132,6 @@ func NewSettingsForm(r *http.Request) *SettingsForm {
DefaultHomePage: r.FormValue("default_home_page"),
CategoriesSortingOrder: r.FormValue("categories_sorting_order"),
MarkReadOnView: r.FormValue("mark_read_on_view") == "1",
MediaPlaybackRate: mediaPlaybackRate,
}
}

View file

@ -22,6 +22,7 @@ func TestValid(t *testing.T) {
DefaultReadingSpeed: 35,
CJKReadingSpeed: 25,
DefaultHomePage: "unread",
MediaPlaybackRate: 1.25,
}
err := settings.Validate()
@ -45,6 +46,7 @@ func TestConfirmationEmpty(t *testing.T) {
DefaultReadingSpeed: 35,
CJKReadingSpeed: 25,
DefaultHomePage: "unread",
MediaPlaybackRate: 1.25,
}
err := settings.Validate()
@ -72,6 +74,7 @@ func TestConfirmationIncorrect(t *testing.T) {
DefaultReadingSpeed: 35,
CJKReadingSpeed: 25,
DefaultHomePage: "unread",
MediaPlaybackRate: 1.25,
}
err := settings.Validate()