Documentation ¶
Index ¶
- Variables
- func Draw(viewport *ebiten.Image, frame *ebiten.Image)
- type Player
- func (self *Player) CurrentFrame() *ebiten.Image
- func (self *Player) Duration() time.Duration
- func (self *Player) FrameRate() float64
- func (self *Player) HasAudio() bool
- func (self *Player) IsPlaying() bool
- func (self *Player) MPEG() (*mpeg.MPEG, *sync.Mutex)
- func (self *Player) Pause()
- func (self *Player) Play()
- func (self *Player) Position() time.Duration
- func (self *Player) Resolution() (int, int)
- func (self *Player) Rewind()
- func (self *Player) SeekFast(position time.Duration)
- func (self *Player) SeekPrecise(position time.Duration)
- func (self *Player) SetVolume(volume float64)
- func (self *Player) Volume() float64
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoVideo = errors.New("mpeg doesn't include any video stream") ErrMissingHeaders = errors.New("one or more mpeg streams are missing headers") ErrNilAudioContext = errors.New("mpeg has audio stream but audio.Context is not initialized") ErrBadSampleRate = errors.New("mpeg audio stream and audio context sample rates don't match") ErrTooManyChannels = errors.New("mpeg audio streams with more than 2 channels are not supported") )
A collection of initialization errors defined by this package for NewPlayer(). Other mpeg-specific errors are also possible.
Functions ¶
func Draw ¶
func Draw(viewport *ebiten.Image, frame *ebiten.Image)
A utility function to draw a frame into the given viewport, scaling as required with ebiten.FilterLinear to take as much space as possible while preserving the aspect ratio.
If there's extra space in the viewport, the frame will be drawn centered, but black bars won't be explicitly drawn, so whatever was on the background of the viewport will remain visible.
Common usage:
mpegg.Draw(screen, mpegPlayer.CurrentFrame())
Types ¶
type Player ¶
type Player struct {
// contains filtered or unexported fields
}
A Player represents an mpeg video player, typically also including audio.
The player is a simple abstraction layer or wrapper around the lower level gen2brain/mpeg types, which implement the underlying decoders used to make playing video possible on Ebitengine.
Usage is quite similar to Ebitengine audio players:
- Create a NewPlayer().
- Call [Player.Play()] to start the video.
- Audio will play automatically. Frames are obtained with Player.CurrentFrame().
- Use Player.Pause() or Player.SeekFast() to control the video.
More methods are available, but that's the main idea.
func NewPlayer ¶
func NewPlayer(mpegVideoReader io.ReadSeeker) (*Player, error)
Creates a new mpeg video Player. The read-seeker source is usually a file opened with os.Open().
func (*Player) CurrentFrame ¶
func (self *Player) CurrentFrame() *ebiten.Image
Returns the image corresponding to the underlying mpeg's video frame at the current Player.Position(). This means that as long as the mpeg is playing, calling this method at different times will return different frames.
The returned image is reused, so calling this method again is likely to overwrite its contents. This means you can use the image between calls, but you should not store it for later use expecting the image to remain the same.
func (*Player) FrameRate ¶
Returns the video's framerate (how many video frames are used per second).
func (*Player) IsPlaying ¶
Returns whether the player's clock and audio are running or not. Notice that even when playing, video frames need to be retrieved manually through Player.CurrentFrame().
func (*Player) MPEG ¶
Returns the player's underlying mpeg and its associated mutex. The mutex is particularly critical when the mpeg also contains audio, as the Ebitengine audio process may be periodically reading from the mpeg, making concurrent access dangerous.
Here's a list of common useful methods on the underlying mpeg:
- SetAudioStream(int) to select the audio stream [0 - 4].
- SetLoop(bool) to set mpeg looping mode.
- Loop() bool to determine if the mpeg is in looping mode.
func (*Player) Pause ¶
func (self *Player) Pause()
Pauses the player's playback clock. If the player is already paused, it just stays paused and nothing new happens.
If the underlying mpeg contains any audio, the audio will also be paused.
func (*Player) Play ¶
func (self *Player) Play()
Play() activates the player's playback clock. If the player is already playing, it just keeps playing and nothing new happens.
If the underlying mpeg contains any audio, the audio will also start or resume. Video frames need to be retrieved manually through Player.CurrentFrame() instead.
func (*Player) Resolution ¶
Returns the width and height of the video.
func (*Player) Rewind ¶
func (self *Player) Rewind()
Rewinds the mpeg streams to the beginning. Behavior may differ from [Player.Seek](0) (TODO: figure out the differences in more detail).
func (*Player) SeekFast ¶
Moves the player's playback position to the first intra-frame that can be found before the given target position.
Player.SeekPrecise() is more precise but can also be significantly slower.
TODO: better document the potential precision loss, common values in practical scenarios, or advice on format settings in order to make results more or less precise (if intra-frames can be easily configured). Also quantify how much slower "slower" means.
func (*Player) SeekPrecise ¶
Moves the player's playback position to the given one, relative to the start of the video.
This method is more precise than Player.SeekFast(), but it can also be significantly slower: a precise seek has to do an initial fast seek to the first intra-frame that can be found before the target position, but then it also has to keep decoding frames progressively until the actual target position is reached.