Documentation
¶
Index ¶
- Variables
- func ClientAPIVersion() (major, minor uint32, err error)
- func LibraryPath() (string, error)
- func Load() error
- func SetLibraryPath(path string)
- func View(c *ui.Context, p *Player) ui.Element
- type HWDecMode
- type OpenOptions
- type Options
- type Player
- func (p *Player) AddSubtitleFile(path string, flags ...SubtitleFlag) error
- func (p *Player) AudioTracks() []Track
- func (p *Player) Close() error
- func (p *Player) CurrentHWDec() string
- func (p *Player) DisableAudioTrack() error
- func (p *Player) DisableSubtitleTrack() error
- func (p *Player) FrameBackStep() error
- func (p *Player) FrameSize() (width, height int)
- func (p *Player) FrameStep() error
- func (p *Player) FramesRendered() uint64
- func (p *Player) GetPropertyString(name string) (string, error)
- func (p *Player) ImageSource() ui.ImageSource
- func (p *Player) Open(target string, opts ...OpenOptions) error
- func (p *Player) Pause() error
- func (p *Player) Play() error
- func (p *Player) Seek(pos time.Duration) error
- func (p *Player) SeekRelative(delta time.Duration) error
- func (p *Player) SelectAudioTrack(id int64) error
- func (p *Player) SelectSubtitleTrack(id int64) error
- func (p *Player) SetAudioDelay(d time.Duration) error
- func (p *Player) SetHTTPHeaders(headers map[string]string) error
- func (p *Player) SetHWDec(mode HWDecMode) error
- func (p *Player) SetLoop(loop bool) error
- func (p *Player) SetMuted(muted bool) error
- func (p *Player) SetPanscan(v float64) error
- func (p *Player) SetPropertyString(name, value string) error
- func (p *Player) SetReferrer(ref string) error
- func (p *Player) SetRenderSize(width, height int)
- func (p *Player) SetSpeed(rate float64) error
- func (p *Player) SetSubtitleDelay(d time.Duration) error
- func (p *Player) SetSubtitlePos(pos int) error
- func (p *Player) SetSubtitleScale(scale float64) error
- func (p *Player) SetSubtitleVisible(visible bool) error
- func (p *Player) SetUserAgent(ua string) error
- func (p *Player) SetVideoRotate(deg int) error
- func (p *Player) SetVolume(v float64) error
- func (p *Player) Snapshot() Snapshot
- func (p *Player) Stop() error
- func (p *Player) SubtitleTracks() []Track
- func (p *Player) Texture() *native.Texture
- func (p *Player) TogglePause() error
- func (p *Player) Tracks() []Track
- func (p *Player) VideoTracks() []Track
- type Snapshot
- type State
- type SubtitleFlag
- type Track
- type TrackType
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("player: closed")
ErrClosed is returned when operations are invoked on a closed Player.
Functions ¶
func ClientAPIVersion ¶
ClientAPIVersion returns the loaded libmpv client API major and minor version.
func LibraryPath ¶
LibraryPath returns the resolved path of the libmpv dynamic library.
func Load ¶
func Load() error
Load loads libmpv and binds all symbols once. New calls Load automatically; call Load earlier to verify libmpv availability at startup.
func SetLibraryPath ¶
func SetLibraryPath(path string)
SetLibraryPath overrides the libmpv shared library path before Load or New is called. Most applications should rely on mygo-plugin.json or MYGO_NATIVE_MPV instead.
func View ¶
View renders p's video frame inside MyGo's native UI scene graph (zero-copy Metal *native.Texture on macOS; double-buffered *ui.Bitmap on Windows and Linux). Because frames are composited directly in MyGo rather than a native child window, overlays such as danmaku, HUD controls, rounded corners, and popovers always render cleanly on top.
The returned ui.Element can be styled and laid out like any ui.Image (Fill, Width, Height, Radius, Opacity, etc.). View automatically binds the window's Invalidate hook to the player and reads the window's live display scale via ui.Painter.Scale() so both video and libass subtitles stay sharp across HiDPI/Retina and multi-monitor setups.
Aspect ratio and filling: View asks libmpv to render at the element's full physical size, and libmpv itself letterboxes the picture inside that frame (black bars) while drawing subtitles at full viewport resolution. The element's Fit(ui.Contain) therefore only matters before the first sized frame; overriding it with Fit(ui.Cover) does NOT remove libmpv's black bars (the frame already matches the element's size, bars included). To fill the viewport (crop-to-fill), keep the View full-size and call p.SetPanscan(1.0) (any value in 0..1 trades bars for cropping); SetVideoRotate rotates within the same frame.
Types ¶
type HWDecMode ¶
type HWDecMode string
HWDecMode controls hardware video decoding in libmpv.
const ( // HWDecAutoSafe enables safe zero-copy hardware decoding (VideoToolbox on // macOS) and falls back to software decoding for unsupported streams. HWDecAutoSafe HWDecMode = "auto-safe" // HWDecAutoCopy enables safe copy-back hardware decoding (such as D3D11VA on // Windows, VA-API/NVDEC on Linux, or VideoToolbox copy-back on macOS) and // falls back to software decoding for unsupported streams. Default on Windows // and Linux. HWDecAutoCopy HWDecMode = "auto-copy" // HWDecVideoToolbox explicitly requests Apple VideoToolbox zero-copy decoding. HWDecVideoToolbox HWDecMode = "videotoolbox" // HWDecVideoToolboxCopy requests VideoToolbox decoding with copy-back. HWDecVideoToolboxCopy HWDecMode = "videotoolbox-copy" // HWDecD3D11VACopy explicitly requests Windows D3D11VA hardware decoding with copy-back. HWDecD3D11VACopy HWDecMode = "d3d11va-copy" // HWDecVAAPICopy explicitly requests Linux VA-API hardware decoding with copy-back. HWDecVAAPICopy HWDecMode = "vaapi-copy" // HWDecNone disables hardware decoding (software decoding only). HWDecNone HWDecMode = "no" )
type OpenOptions ¶
type OpenOptions struct {
// Headers overrides or supplements HTTP headers for this media source.
// Per-open headers are automatically reset on subsequent Open calls.
Headers map[string]string
// UserAgent overrides the HTTP User-Agent for this media source.
UserAgent string
// Referrer overrides the HTTP Referer for this media source.
Referrer string
// StartTime seeks to the given position when opening the media.
StartTime time.Duration
// Paused opens the media paused on its first frame.
Paused bool
// Subtitles specifies external subtitle files to attach automatically.
Subtitles []string
}
OpenOptions configures per-file playback parameters passed to Player.Open.
type Options ¶
type Options struct {
// HWDec configures hardware decoding. Defaults to HWDecAutoSafe on macOS
// and HWDecAutoCopy on Windows and Linux.
HWDec HWDecMode
// KeepOpen keeps the last frame visible when playback reaches EOF.
// Defaults to true when KeepOpen is nil.
KeepOpen *bool
// Volume sets initial volume in [0, 100] (or higher for software boost).
// Defaults to 100 when <= 0 (also with StartMuted, so unmuting is audible).
Volume float64
// StartMuted mutes audio on creation without changing Volume.
StartMuted bool
// Loop loops the current file indefinitely when true.
Loop bool
// HTTPHeaders sets default HTTP headers sent for network streams.
HTTPHeaders map[string]string
// UserAgent sets the default HTTP User-Agent for network streams.
UserAgent string
// Referrer sets the default HTTP Referer header for network streams.
Referrer string
// AudioOutput overrides mpv's "ao" option (e.g. "null" for headless tests).
// Defaults to "wasapi" on Windows and mpv's native default on macOS
// (CoreAudio) and Linux (PipeWire/PulseAudio/ALSA).
AudioOutput string
// LogLevel enables libmpv log callbacks ("fatal", "error", "warn", "info", "v", "debug").
// Empty disables log message delivery.
LogLevel string
// ExtraOptions sets arbitrary libmpv options before mpv_initialize.
ExtraOptions map[string]string
// OnLog receives libmpv log lines when LogLevel is set.
// Runs on the player's background event goroutine.
OnLog func(level, prefix, text string)
// OnStateChange is invoked when playback state, tracks, or metadata change.
// Position-only updates are throttled to about one call per 100ms (the
// Snapshot itself keeps full precision); state changes and seeks notify
// immediately. Usually runs on the player's background event goroutine
// (or the goroutine calling Open/Stop/track methods, after internal locks
// are released). Calling any Player method, including Close, is safe.
OnStateChange func()
// OnEndFile is invoked when playback of a file ends (EOF, stop, or error).
// With KeepOpen (default) the file stays loaded at EOF, so OnEndFile(nil)
// is delivered once when EOF is first reached; replaying (Play/seek back)
// or opening media re-arms it, and a later Stop/Open of the same ended
// file does not report it again. Errors carry a readable libmpv message.
// Runs on the player's background event goroutine; calling Close is safe.
OnEndFile func(err error)
}
Options configures a new Player created by New.
type Player ¶
type Player struct {
// contains filtered or unexported fields
}
Player manages a libmpv playback instance rendered into MyGo's native UI scene graph (zero-copy native.Texture on macOS; double-buffered ui.Bitmap on Windows). Its methods are safe to call from any goroutine.
func (*Player) AddSubtitleFile ¶
func (p *Player) AddSubtitleFile(path string, flags ...SubtitleFlag) error
AddSubtitleFile attaches an external subtitle file (SRT, ASS/SSA, WebVTT, SUP, etc.). By default flag is SubtitleSelect so the added subtitle is immediately active.
func (*Player) AudioTracks ¶
AudioTracks returns all audio tracks in the current media.
func (*Player) Close ¶
Close shuts down the render context, event loop, and libmpv instance cleanly.
Close is idempotent and safe to call from any goroutine, including from inside OnStateChange / OnEndFile / OnLog callbacks running on the player's event goroutine. In that case Close returns immediately after stopping the renderer; the libmpv handle is destroyed as soon as the callback returns and the event loop unwinds, so no libmpv call ever touches a freed handle.
func (*Player) CurrentHWDec ¶
CurrentHWDec returns the active hardware decoder reported by libmpv (for example "videotoolbox", or "" / "no" when software decoding is active).
func (*Player) DisableAudioTrack ¶
DisableAudioTrack disables audio playback ("aid=no").
func (*Player) DisableSubtitleTrack ¶
DisableSubtitleTrack turns off subtitle track selection ("sid=no").
func (*Player) FrameBackStep ¶ added in v0.4.0
FrameBackStep pauses playback and steps back exactly one video frame (requires a seekable source; it is slower than FrameStep).
func (*Player) FrameSize ¶ added in v0.2.0
FrameSize returns the pixel dimensions of the most recently rendered video frame on any supported platform.
func (*Player) FrameStep ¶ added in v0.4.0
FrameStep pauses playback and advances exactly one video frame.
func (*Player) FramesRendered ¶
FramesRendered returns the total number of video frames rendered since creation.
func (*Player) GetPropertyString ¶
GetPropertyString is an escape hatch for querying an arbitrary libmpv property.
func (*Player) ImageSource ¶ added in v0.2.0
func (p *Player) ImageSource() ui.ImageSource
ImageSource returns the ui.ImageSource for the current video frame (*native.Texture on macOS, *ui.Bitmap on Windows). Call it on the UI thread (typically via View(c, p)).
func (*Player) Open ¶
func (p *Player) Open(target string, opts ...OpenOptions) error
Open opens a local file path or network URL for playback.
Open resets every per-file Snapshot field left over from the previous media (position, duration, EOF, buffering, title, video size, track IDs, tracks, error) and synchronizes Snapshot().Paused with opt.Paused immediately.
func (*Player) Play ¶
Play starts or resumes playback. If playback reached EOF it restarts from the beginning: with KeepOpen (default) it seeks back to 0; with KeepOpen=false (file already unloaded) it reloads the last opened target.
func (*Player) SeekRelative ¶
SeekRelative seeks forward (positive) or backward (negative) by delta.
func (*Player) SelectAudioTrack ¶
SelectAudioTrack switches to the audio track with the given mpv track ID.
func (*Player) SelectSubtitleTrack ¶
SelectSubtitleTrack switches to the embedded or external subtitle track with the given mpv track ID and ensures subtitle visibility is enabled.
func (*Player) SetAudioDelay ¶ added in v0.4.0
SetAudioDelay shifts audio relative to video by d (positive delays audio). Mirrored in Snapshot().AudioDelay.
func (*Player) SetHTTPHeaders ¶
SetHTTPHeaders sets default HTTP headers applied to subsequent network streams. Special headers "User-Agent" and "Referer"/"Referrer" are automatically mapped to libmpv's dedicated user-agent and referrer properties.
func (*Player) SetHWDec ¶
SetHWDec dynamically updates the hardware decoding mode (e.g. HWDecAutoSafe, HWDecAutoCopy, HWDecVideoToolbox, HWDecD3D11VACopy, HWDecNone).
func (*Player) SetPanscan ¶ added in v0.4.0
SetPanscan crops the video to fill the View's aspect ratio: 0 (default) letterboxes the whole picture, 1 fills the viewport completely (cropping edges). Values must be within [0, 1]. Because View renders at the full viewport size, subtitles stay sharp and inside the visible area. Mirrored in Snapshot().Panscan.
func (*Player) SetPropertyString ¶
SetPropertyString is an escape hatch for setting an arbitrary libmpv property.
func (*Player) SetReferrer ¶
SetReferrer sets the default HTTP Referer header applied to network streams.
func (*Player) SetRenderSize ¶
SetRenderSize sets the target physical pixel dimensions for video rendering. Pass (0, 0) to revert to the video's native resolution.
func (*Player) SetSubtitleDelay ¶ added in v0.4.0
SetSubtitleDelay shifts subtitle timing by d (positive shows subtitles later). Mirrored in Snapshot().SubDelay.
func (*Player) SetSubtitlePos ¶ added in v0.4.0
SetSubtitlePos sets the vertical subtitle position in percent of the screen height (0 = top, 100 = bottom (default), up to 150 to push below the picture). Mirrored in Snapshot().SubPos.
func (*Player) SetSubtitleScale ¶ added in v0.4.0
SetSubtitleScale sets the subtitle font scale factor (must be > 0 and <= 100; default 1.0). Mirrored in Snapshot().SubScale.
func (*Player) SetSubtitleVisible ¶
SetSubtitleVisible toggles subtitle rendering without changing the selected track.
func (*Player) SetUserAgent ¶
SetUserAgent sets the default HTTP User-Agent applied to network streams.
func (*Player) SetVideoRotate ¶ added in v0.4.0
SetVideoRotate rotates the video clockwise by deg, which must be 0, 90, 180 or 270. Mirrored in Snapshot().VideoRotate. Arbitrary angles are not supported by this API; use SetPropertyString("video-rotate", ...) instead.
func (*Player) Snapshot ¶
Snapshot returns a consistent copy of the player's current playback state and tracks.
func (*Player) Stop ¶
Stop stops playback and returns the player to idle, clearing every per-file Snapshot field (EOF, position, duration, buffering, title, video size, track IDs, tracks and error).
func (*Player) SubtitleTracks ¶
SubtitleTracks returns all embedded and external subtitle tracks in the current media.
func (*Player) Texture ¶
Texture returns the zero-copy GPU native.Texture on macOS, or nil on platforms that present frames through ui.Bitmap (such as Windows). Prefer View(c, p) or ImageSource() for cross-platform UI rendering.
func (*Player) TogglePause ¶
TogglePause switches between playing and paused states. When playback is paused or has reached EOF it calls Play (which restarts ended media).
func (*Player) VideoTracks ¶
VideoTracks returns all video tracks in the current media.
type Snapshot ¶
type Snapshot struct {
State State
Position time.Duration
Duration time.Duration
Volume float64
Muted bool
Speed float64
Paused bool
Buffering bool
EOF bool
VideoWidth int
VideoHeight int
CurrentHWDec string
MediaTitle string
AudioTrackID int64
SubTrackID int64
SubVisible bool
Tracks []Track
Err error
// SubDelay is the subtitle delay (see SetSubtitleDelay).
SubDelay time.Duration
// AudioDelay is the audio delay (see SetAudioDelay).
AudioDelay time.Duration
// SubScale is the subtitle scale factor (default 1.0).
SubScale float64
// SubPos is the vertical subtitle position in percent (default 100).
SubPos int
// VideoRotate is the clockwise video rotation in degrees.
VideoRotate int
// Panscan is the crop-to-fill amount in [0, 1] (see SetPanscan).
Panscan float64
}
Snapshot is an immutable point-in-time summary of player state suitable for reading in UI view functions without taking locks repeatedly.
type SubtitleFlag ¶
type SubtitleFlag string
SubtitleFlag controls how AddSubtitleFile treats a newly added subtitle track.
const ( // SubtitleSelect loads and immediately activates the subtitle track (default). SubtitleSelect SubtitleFlag = "select" // SubtitleAuto loads the subtitle track without overriding an active track. SubtitleAuto SubtitleFlag = "auto" // SubtitleCached loads the subtitle track without selecting it. SubtitleCached SubtitleFlag = "cached" )
type Track ¶
type Track struct {
ID int64
Type TrackType
SrcID int64
Title string
Lang string
Codec string
Selected bool
Default bool
Forced bool
External bool
ExternalFilename string
Width int
Height int
FPS float64
Channels int
SampleRate int
}
Track describes a video, audio, or subtitle stream reported by libmpv.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
player
command
Example player demonstrates github.com/arixbit/mygo-player in a MyGo native UI window on macOS (zero-copy IOSurface -> Metal), Windows and Linux (software render API -> ui.Bitmap): MKV playback, multi-audio track switching, embedded & external subtitles, hardware decoding (VideoToolbox, D3D11VA, VA-API), and custom HTTP headers.
|
Example player demonstrates github.com/arixbit/mygo-player in a MyGo native UI window on macOS (zero-copy IOSurface -> Metal), Windows and Linux (software render API -> ui.Bitmap): MKV playback, multi-audio track switching, embedded & external subtitles, hardware decoding (VideoToolbox, D3D11VA, VA-API), and custom HTTP headers. |
|
internal
|
|
|
scripts
|
|
|
update-manifest
command
Command update-manifest updates mygo-plugin.json with SHA-256 checksums and immutable release asset URLs for built libmpv dynamic libraries, matching MyGo's native library publishing convention.
|
Command update-manifest updates mygo-plugin.json with SHA-256 checksums and immutable release asset URLs for built libmpv dynamic libraries, matching MyGo's native library publishing convention. |