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) FramesRendered() uint64
- func (p *Player) GetPropertyString(name string) (string, error)
- 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) 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) 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) SetSubtitleVisible(visible bool) error
- func (p *Player) SetUserAgent(ua string) 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 zero-copy GPU texture inside MyGo's native UI scene graph.
The returned ui.Element can be styled and laid out like any ui.Image (Fill, Width, Height, Fit, 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 Retina and multi-monitor setups.
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" // HWDecVideoToolbox explicitly requests Apple VideoToolbox zero-copy decoding. HWDecVideoToolbox HWDecMode = "videotoolbox" // HWDecVideoToolboxCopy requests VideoToolbox decoding with copy-back. HWDecVideoToolboxCopy HWDecMode = "videotoolbox-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.
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 and StartMuted is false.
Volume float64
// StartMuted mutes audio on creation.
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).
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.
// Runs on the player's background event goroutine; calls to Player methods are safe.
OnStateChange func()
// OnEndFile is invoked when playback of a file ends (EOF, stop, or error).
// Runs on the player's background event goroutine.
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 with zero-copy GPU rendering into a MyGo native.Texture. 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.
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) FramesRendered ¶
FramesRendered returns the total number of GPU frames presented since creation.
func (*Player) GetPropertyString ¶
GetPropertyString is an escape hatch for querying an arbitrary libmpv property.
func (*Player) Open ¶
func (p *Player) Open(target string, opts ...OpenOptions) error
Open opens a local file path or network URL for playback.
func (*Player) Play ¶
Play starts or resumes playback. If playback reached EOF, it seeks back to 0 first.
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) 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, HWDecVideoToolbox, HWDecNone).
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 zero-copy GPU rendering. Pass (0, 0) to revert to the video's native resolution.
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) Snapshot ¶
Snapshot returns a consistent copy of the player's current playback state and tracks.
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 suitable for ui.Image(c, p.Texture()).
func (*Player) TogglePause ¶
TogglePause switches between playing and paused states.
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
}
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.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
player
command
Example player demonstrates github.com/arixbit/mygo-player in a MyGo native UI window on macOS with zero-copy GPU rendering (IOSurface -> Metal), MKV playback, multi-audio track switching, embedded & external subtitles, hardware decoding (VideoToolbox), and custom HTTP headers.
|
Example player demonstrates github.com/arixbit/mygo-player in a MyGo native UI window on macOS with zero-copy GPU rendering (IOSurface -> Metal), MKV playback, multi-audio track switching, embedded & external subtitles, hardware decoding (VideoToolbox), 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. |