rui_orig/videoPlayer.go

142 lines
3.5 KiB
Go
Raw Normal View History

2021-09-07 17:36:50 +03:00
package rui
import (
"strings"
)
const (
// VideoWidth is the constant for the "video-width" property tag of VideoPlayer.
// The "video-width" float property defines the width of the video's display area in pixels.
VideoWidth = "video-width"
// VideoHeight is the constant for the "video-height" property tag of VideoPlayer.
// The "video-height" float property defines the height of the video's display area in pixels.
VideoHeight = "video-height"
// Poster is the constant for the "poster" property tag of VideoPlayer.
// The "poster" property defines an URL for an image to be shown while the video is downloading.
// If this attribute isn't specified, nothing is displayed until the first frame is available,
// then the first frame is shown as the poster frame.
Poster = "poster"
)
type VideoPlayer interface {
MediaPlayer
}
type videoPlayerData struct {
mediaPlayerData
}
// NewVideoPlayer create new MediaPlayer object and return it
2021-11-04 21:21:42 +03:00
func NewVideoPlayer(session Session, params Params) VideoPlayer {
2021-09-07 17:36:50 +03:00
view := new(videoPlayerData)
view.init(session)
2021-09-07 17:36:50 +03:00
view.tag = "VideoPlayer"
setInitParams(view, params)
return view
}
func newVideoPlayer(session Session) View {
return NewVideoPlayer(session, nil)
}
func (player *videoPlayerData) init(session Session) {
player.mediaPlayerData.init(session)
2021-09-07 17:36:50 +03:00
player.tag = "VideoPlayer"
}
2022-05-22 12:54:02 +03:00
func (player *videoPlayerData) String() string {
return getViewString(player)
}
2021-09-07 17:36:50 +03:00
func (player *videoPlayerData) htmlTag() string {
return "video"
}
func (player *videoPlayerData) Remove(tag string) {
player.remove(strings.ToLower(tag))
}
func (player *videoPlayerData) remove(tag string) {
switch tag {
case VideoWidth:
delete(player.properties, tag)
2022-10-30 17:22:33 +03:00
player.session.removeProperty(player.htmlID(), "width")
2021-09-07 17:36:50 +03:00
case VideoHeight:
delete(player.properties, tag)
2022-10-30 17:22:33 +03:00
player.session.removeProperty(player.htmlID(), "height")
2021-09-07 17:36:50 +03:00
case Poster:
delete(player.properties, tag)
2022-10-30 17:22:33 +03:00
player.session.removeProperty(player.htmlID(), Poster)
2021-09-07 17:36:50 +03:00
default:
player.mediaPlayerData.remove(tag)
}
}
2022-07-26 18:36:00 +03:00
func (player *videoPlayerData) Set(tag string, value any) bool {
2021-09-07 17:36:50 +03:00
return player.set(strings.ToLower(tag), value)
}
2022-07-26 18:36:00 +03:00
func (player *videoPlayerData) set(tag string, value any) bool {
2021-09-07 17:36:50 +03:00
if value == nil {
player.remove(tag)
return true
}
if player.mediaPlayerData.set(tag, value) {
session := player.Session()
updateSize := func(cssTag string) {
2022-08-18 18:18:36 +03:00
if size, ok := floatTextProperty(player, tag, session, 0); ok {
if size != "0" {
2022-10-30 17:22:33 +03:00
session.updateProperty(player.htmlID(), cssTag, size)
2021-09-07 17:36:50 +03:00
} else {
2022-10-30 17:22:33 +03:00
session.removeProperty(player.htmlID(), cssTag)
2021-09-07 17:36:50 +03:00
}
}
}
switch tag {
case VideoWidth:
updateSize("width")
case VideoHeight:
updateSize("height")
case Poster:
if url, ok := stringProperty(player, Poster, session); ok {
2022-10-30 17:22:33 +03:00
session.updateProperty(player.htmlID(), Poster, url)
2021-09-07 17:36:50 +03:00
}
}
return true
}
return false
}
func (player *videoPlayerData) htmlProperties(self View, buffer *strings.Builder) {
player.mediaPlayerData.htmlProperties(self, buffer)
session := player.Session()
2022-08-18 18:18:36 +03:00
if size, ok := floatTextProperty(player, VideoWidth, session, 0); ok && size != "0" {
buffer.WriteString(` width="`)
buffer.WriteString(size)
buffer.WriteString(`"`)
2021-09-07 17:36:50 +03:00
}
2022-08-18 18:18:36 +03:00
if size, ok := floatTextProperty(player, VideoHeight, session, 0); ok && size != "0" {
buffer.WriteString(` height="`)
buffer.WriteString(size)
buffer.WriteString(`"`)
2021-09-07 17:36:50 +03:00
}
if url, ok := stringProperty(player, Poster, session); ok && url != "" {
buffer.WriteString(` poster="`)
buffer.WriteString(url)
buffer.WriteString(`"`)
}
}