Documentation
¶
Overview ¶
Package video provides Experimental, window-independent media playback.
Index ¶
- Variables
- type Diagnostics
- type Event
- type EventKind
- type HDR
- type HardwareDecoding
- type OpenOptions
- type Options
- type Phase
- type Player
- func (p *Player) AddSubtitle(path string, selectTrack bool) error
- func (p *Player) Close() error
- func (p *Player) Diagnostics() Diagnostics
- func (p *Player) Open(source string, opts OpenOptions) error
- func (p *Player) Pause() error
- func (p *Player) Play() error
- func (p *Player) Screenshot(path string) error
- func (p *Player) Seek(position time.Duration, mode SeekMode) error
- func (p *Player) SelectTrack(kind TrackKind, id int64) error
- func (p *Player) SetHardwareDecoding(mode HardwareDecoding) error
- func (p *Player) SetLoop(loop bool) error
- func (p *Player) SetMuted(muted bool) error
- func (p *Player) SetSpeed(rate float64) error
- func (p *Player) SetSubtitleOffset(offset time.Duration) error
- func (p *Player) SetSubtitleStyle(style SubtitleStyle) error
- func (p *Player) SetVolume(percent float64) error
- func (p *Player) State() State
- func (p *Player) Tracks() ([]Track, error)
- func (p *Player) VideoError() error
- type SeekMode
- type State
- type SubtitleStyle
- type Track
- type TrackKind
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("video: player closed")
ErrClosed is returned by operations on a closed player.
Functions ¶
This section is empty.
Types ¶
type Diagnostics ¶
type Diagnostics struct {
Submitted, Evicted, Skipped uint64
MPVDropped, MPVDelayed uint64
AVSync time.Duration
Path string
Err error
}
Diagnostics reports cumulative renderer counts and the current libmpv playback counters when enabled by Options.Diagnostics. AVSync is the signed current audio/video difference. Path identifies the selected output.
type Event ¶
Event carries the playback snapshot at the time of dispatch scheduling. Err is set for Error events. Consecutive Changed events and ordinary Progress events may be coalesced while the app's main thread is busy.
type EventKind ¶
type EventKind uint8
EventKind identifies a playback notification.
const ( // Changed reports changes such as pause, source, duration, dimensions, // HDR metadata, or track selection. Progress has its own event. Changed EventKind = iota Loaded Finished Error // Progress reports position, buffering state, or buffer percentage. // A snapshot also accompanies Loaded, Finished, and a completed seek. Progress )
type HDR ¶
type HDR struct {
Active bool
Transfer, Primaries string
MinLuminance, MaxLuminance float64
MaxContentLight, MaxFrameAverageLight float64
}
HDR describes the source's reported color metadata. Luminance and light levels are in cd/m². Zero represents unavailable metadata.
type HardwareDecoding ¶
type HardwareDecoding uint8
HardwareDecoding selects the decode policy.
const ( HardwareAuto HardwareDecoding = iota HardwareOn HardwareOff )
type OpenOptions ¶
type OpenOptions struct {
Headers http.Header
Start time.Duration
Subtitles []string
// contains filtered or unexported fields
}
OpenOptions applies to one source. Headers can include User-Agent and Referer, which are applied as their dedicated mpv options.
type Options ¶
type Options struct {
// LibraryPath overrides the platform libmpv search. On macOS the default
// looks in the app's Frameworks directory, then the Homebrew locations.
LibraryPath string
// OnEvent receives playback events on the app's main thread.
OnEvent func(Event)
// ProgressInterval is the minimum interval between ordinary Progress
// events. Zero uses 250 ms and a negative duration disables throttling.
// Load, end of playback, and completed seek snapshots bypass the interval.
ProgressInterval time.Duration
// Video enables frame output for ui.Video. The default is headless.
Video bool
// SoftwareVideo selects software rendering and BGRA upload on Windows.
SoftwareVideo bool
// Diagnostics enables renderer counters for Diagnostics.
Diagnostics bool
// contains filtered or unexported fields
}
Options configures a Player.
type Player ¶
type Player struct {
// contains filtered or unexported fields
}
Player owns a playback instance. Its methods are safe to call concurrently. Call Close to release the instance, for example when the app quits.
func New ¶
New creates a player that dispatches events through app.Post. On macOS it and Linux or Windows it needs libmpv 0.37 or newer (client API version 2.2). Enable Options.Video to attach a frame output.
func (*Player) AddSubtitle ¶
AddSubtitle loads an external subtitle file and optionally selects it.
func (*Player) Close ¶
Close releases the player's native resources. It is safe to call repeatedly or from an event callback.
func (*Player) Diagnostics ¶
func (p *Player) Diagnostics() Diagnostics
Diagnostics reads the current counters. A zero value is returned when diagnostics were disabled. Reading mpv properties is charged to the caller.
func (*Player) Open ¶
func (p *Player) Open(source string, opts OpenOptions) error
Open replaces the current source with a local path or a URL. It returns after mpv accepts the request. Loaded and Error report the eventual result.
func (*Player) Screenshot ¶
Screenshot writes the current video frame as a PNG, overwriting an existing file at path. The path must have a .png extension.
func (*Player) SelectTrack ¶
SelectTrack selects an audio or subtitle track by ID. Zero disables that track kind, and -1 restores mpv's automatic selection.
func (*Player) SetHardwareDecoding ¶
func (p *Player) SetHardwareDecoding(mode HardwareDecoding) error
SetHardwareDecoding changes the decode policy. HardwareAuto selects among safe hardware decoders. HardwareOn tries all available hardware decoders. mpv may fall back to software for unsupported sources.
func (*Player) SetSubtitleOffset ¶
SetSubtitleOffset applies a timing offset. A positive offset delays subtitles.
func (*Player) SetSubtitleStyle ¶
func (p *Player) SetSubtitleStyle(style SubtitleStyle) error
SetSubtitleStyle applies subtitle styling to the player.
func (*Player) VideoError ¶
VideoError returns an output initialization or rendering error, when one has occurred. OnEvent reports initialization failures as well.
type State ¶
type State struct {
Source string
Phase Phase
Position, Duration time.Duration
BufferPercent float64
Paused, Buffering bool
Width, Height int
HDR HDR
}
State is a snapshot of playback. Position and Duration are zero when unavailable. BufferPercent is mpv's cache fill percentage before resuming playback, from 0 to 100, or zero when unavailable.
type SubtitleStyle ¶
type SubtitleStyle struct {
Font string
Size float64
Foreground, Outline *color.NRGBA
OutlineWidth *float64
OverrideASS bool
// contains filtered or unexported fields
}
SubtitleStyle configures text subtitles. Unset fields leave their current value in place. OverrideASS also applies styling to authored ASS subtitles.