AudioPlayer, VideoPlayer, MediaPlayer

AudioPlayer and VideoPlayer are elements for audio and video playback.Both elements implement the MediaPlayer interface. Most of the properties and all eventsof AudioPlayer and VideoPlayer are implemented through the MediaPlayer.

"src" property

The "src" property (Source constant) specifies one or more media sources. The "src" property can take on the following types:

  • string,
  • MediaSource,
  • []MediaSource.

The MediaSource structure is declared as

type MediaSource struct {
	Url      string
	MimeType string

where Url is a required parameter, MimeType is an optional mime file type

Since different browsers support different file formats and codecs, it is recommendedto specify multiple sources in different formats. The player chooses the most suitableone from the list of sources. Setting mime types makes this process easier for the browser

"controls" property

The "controls" bool property (Controls constant) specifies whether UI elements should bedisplayed to control playback of the media resource. The default is false.

If the "controls" property is false for the AudioPlayer, then it will be invisible and will not take up screen space.

"loop" property

The "loop" bool property (Loop constant). If it set to true, then the media file will start over when it reaches the end. The default is false.

"muted" property

The "muted" bool property (constant Muted) enables (true) / disables (false) silent mode. The default is false.

"preload" property

The "preload" int property (constant Preload) defines what data should be preloaded.Valid values:

Value Constant Name Description
0 PreloadNone "none" Media file must not be pre-loaded
1 PreloadMetadata "metadata" Only metadata is preloaded
2 PreloadAuto "auto" The entire media file can be downloaded even if the user doesn't have to use it.

The default value is PreloadAuto (2)

"poster" property

The "poster" string property (Poster constant) is used only for VideoPlayer.It sets the url of the image that will be shown until the video is loaded.If this property is not set, then a black screen will be shown first, and then the first frame (as soon as it is loaded).

"video-width" and "video-height" properties

The "video-width" (VideoWidth constant) and "video-height" (VideoHeight constant) float64 properties are used only for VideoPlayer.It defines the width and height of the rendered video in pixels.

If "video-width" and "video-height" are not specified, then the actual dimensions of the video are used,while the dimensions of the container in which the video is placed are ignored and the video may overlapother interface elements. Therefore, it is recommended to set these values, for example, like this

rui.Set(view, "videoPlayerContainer", rui.ResizeEvent, func(frame rui.Frame) {
	rui.Set(view, "videoPlayer", rui.VideoWidth, frame.Width)
	rui.Set(view, "videoPlayer", rui.VideoHeight, frame.Height)

If only one of the "video-width" or "video-height" properties is set, then the second is calculated based on the aspect ratio of the video