omxplayer

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2019 License: MIT Imports: 9 Imported by: 0

README

omxplayer

Build Status GoDoc

omxplayer is a simple library for controlling omxplayer on your Raspberry Pi from a Go application.

Table of Contents

Requirements

  • The omxplayer library requires a build of the omxplayer application later than the 1d20cdc1be commit.

Getting Started

The omxplayer library follows the standard Go package format, allowing you to start using it with a single command:

go get github.com/jleight/omxplayer

Once the library has been downloaded to your Go path, you can import it in your project to start using it:

import (
	"github.com/jleight/omxplayer"
)

Note on Design Choices

The omxplayer application and D-Bus were designed such that:

  1. The omxplayer application provides multi-user support by appending the name of the user that is running the process to the file containing the D-Bus connection information.
  2. D-Bus requires authentication in which the user's name and home directory need to be provided.

The normal way of getting the current user's username and home directory would be to use the os/user package. However, as of the time of writing this, the os/user package does not work on the Raspberry Pi.

For this reason, we have opted to use os.Getenv to get the USER and HOME environment variables in order to connect to omxplayer via D-Bus.

If, for any reason, either the USER or HOME environment variables are not available, you must specify the user and the user's home directory before attempting to start a new omxplayer instance. This can be done with the SetUser method.

omxplayer.SetUser("someuser", "/home/someuser")

If you are using this library to build an executable to run as a service, you could choose to pass in the user and home directory as command line arguments:

if len(os.Args) == 3 {
	omxplayer.SetUser(os.Args[1], os.Args[2])
}

Usage

Now that you've downloaded and imported the omxplayer library in your application, you can use it to start up a new instance of omxplayer, providing a path to the file you would like to play:

player, err := omxplayer.New("/path/to/video.mp4", "--no-osd")

This will start a new omxplayer process that will play the specified video file. The original purpose of this library required that the omxplayer instance have time to buffer the video before playing it, so this library starts the omxplayer instance and immediately pauses it.

Sometimes it takes a while (a few hundred milliseconds) for omxplayer to write its D-Bus information to a file. As a precaution, this library includes both an IsReady and WaitForReady method. These can be used to check if the Player instance is ready to start accepting D-Bus commands, or to wait until the Player is ready, respectively. It is recommended that you either make sure that the Player instance IsReady before issuing any other commands, or that you WaitForReady if you cannot do anything else.

Now that you have a Player instance, you can control it through any of the D-Bus methods described in the D-Bus Control section of the omxplayer application's README.

Example

Here's an example to bring it all together:

omxplayer.SetUser("root", "/root")
player, err := omxplayer.New("/root/testvideo.mp4", "--no-osd")

player.WaitForReady()
err = player.PlayPause()

time.Sleep(5 * time.Second)
err = player.ShowSubtitles()

time.Sleep(5 * time.Second)
err = player.Quit()

Of course, all of the D-Bus methods return errors, so you should make sure handle them appropriately.

License

The omxplayer library is available under the MIT license. See the LICENSE file for the full license text.

Documentation

Overview

Package omxplayer is a simple library for controlling the omxplayer application on your Raspberry Pi from Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetUser

func SetUser(u, h string)

SetUser sets the username (u) and home directory (h) of the user that new omxplayer processes will be running as. This does not change which user the processes will be spawned as, it is just used to find the correct D-Bus configuration file after a new process has been started.

Types

type Player

type Player struct {
	// contains filtered or unexported fields
}

The Player struct provides access to all of omxplayer's D-Bus methods.

func New

func New(url string, args ...string) (player *Player, err error)

New returns a new Player instance that can be used to control an OMXPlayer instance that is playing the video located at the specified URL.

func (*Player) Action

func (p *Player) Action(action int32) error

Action allows for executing keyboard commands. See https://github.com/popcornmix/omxplayer#action for more details.

func (*Player) Aspect

func (p *Player) Aspect() (float64, error)

Aspect returns the aspect ratio. See https://github.com/popcornmix/omxplayer/blob/master/OMXControl.cpp#L362.

func (*Player) CanControl

func (p *Player) CanControl() (bool, error)

CanControl returns true if the player can be controlled, false otherwise. See https://github.com/popcornmix/omxplayer#cancontrol for more details.

func (*Player) CanGoNext

func (p *Player) CanGoNext() (bool, error)

CanGoNext returns true if the player can skip to the next track, false otherwise. See https://github.com/popcornmix/omxplayer#cangonext for more details.

func (*Player) CanGoPrevious

func (p *Player) CanGoPrevious() (bool, error)

CanGoPrevious returns true if the player can skip to previous track, false otherwise. See https://github.com/popcornmix/omxplayer#cangoprevious for more details.

func (*Player) CanPause

func (p *Player) CanPause() (bool, error)

CanPause returns true if the player can pause, false otherwise. See https://github.com/popcornmix/omxplayer#canpause for more details.

func (*Player) CanPlay

func (p *Player) CanPlay() (bool, error)

CanPlay returns true if the player can play, false otherwise. See https://github.com/popcornmix/omxplayer#canplay for more details.

func (*Player) CanQuit

func (p *Player) CanQuit() (bool, error)

CanQuit returns true if the player can quit, false otherwise. See https://github.com/popcornmix/omxplayer#canquit for more details.

func (*Player) CanRaise

func (p *Player) CanRaise() (bool, error)

CanRaise returns true if the player can be brought to the front, false otherwise. See https://github.com/popcornmix/omxplayer#canraise for more details.

func (*Player) CanSeek

func (p *Player) CanSeek() (bool, error)

CanSeek returns true if the player can seek, false otherwise. See https://github.com/popcornmix/omxplayer#canseek for more details.

func (*Player) CanSetFullscreen

func (p *Player) CanSetFullscreen() (bool, error)

CanSetFullscreen returns true if the player can be set to fullscreen, false otherwise. See https://github.com/popcornmix/omxplayer#cansetfullscreen for more details.

func (*Player) Duration

func (p *Player) Duration() (int64, error)

Duration returns the total length of the video in milliseconds. See https://github.com/popcornmix/omxplayer#duration for more details.

func (*Player) Fullscreen

func (p *Player) Fullscreen() (bool, error)

Fullscreen returns true if the player is fullscreen, false otherwise. See https://github.com/popcornmix/omxplayer#fullscreen for more details.

func (*Player) HasTrackList

func (p *Player) HasTrackList() (bool, error)

HasTrackList returns true if the player has a track list, false otherwise. See https://github.com/popcornmix/omxplayer#hastracklist for more details.

func (*Player) HideSubtitles

func (p *Player) HideSubtitles() error

HideSubtitles stops displaying subtitles. See https://github.com/popcornmix/omxplayer#hidesubtitles for more details.

func (*Player) HideVideo

func (p *Player) HideVideo() error

HideVideo is an undocumented D-Bus method. See https://github.com/popcornmix/omxplayer/blob/master/OMXControl.cpp#L457.

func (*Player) Identity

func (p *Player) Identity() (string, error)

Identity returns the name of the player instance. See https://github.com/popcornmix/omxplayer#identity for more details.

func (*Player) IsReady

func (p *Player) IsReady() bool

IsReady checks to see if the Player instance is ready to accept D-Bus commands. If the player is ready and can accept commands, the function returns true, otherwise it returns false.

func (*Player) IsRunning

func (p *Player) IsRunning() bool

IsRunning checks to see if the OMXPlayer process is running. If it is, the function returns true, otherwise it returns false.

func (*Player) ListAudio

func (p *Player) ListAudio() ([]string, error)

ListAudio returns a list of the audio tracks available in the video file. See https://github.com/popcornmix/omxplayer#listaudio for more details.

func (*Player) ListSubtitles

func (p *Player) ListSubtitles() ([]string, error)

ListSubtitles returns a list of the subtitles available in the video file. See https://github.com/popcornmix/omxplayer#listsubtitles for more details.

func (*Player) ListVideo

func (p *Player) ListVideo() ([]string, error)

ListVideo returns a list of the video tracks available in the video file. See https://github.com/popcornmix/omxplayer#listvideo for more details.

func (*Player) MaximumRate

func (p *Player) MaximumRate() (float64, error)

MaximumRate returns the maximum playback rate. See https://github.com/popcornmix/omxplayer#maximumrate for more details.

func (*Player) MinimumRate

func (p *Player) MinimumRate() (float64, error)

MinimumRate returns the minimum playback rate. See https://github.com/popcornmix/omxplayer#minimumrate for more details.

func (*Player) Mute

func (p *Player) Mute() error

Mute mutes the video's audio stream. See https://github.com/popcornmix/omxplayer#mute for more details.

func (*Player) Next

func (p *Player) Next() error

Next tells the player to skip to the next chapter. See https://github.com/popcornmix/omxplayer#next for more details.

func (*Player) Pause

func (p *Player) Pause() error

Pause pauses the player if it is playing. Otherwise, it resumes playback. See https://github.com/popcornmix/omxplayer#pause for more details.

func (*Player) Play

func (p *Player) Play() error

Play play the video. If the video is playing, it has no effect, if it is paused it will play from current position. See https://github.com/popcornmix/omxplayer#play for more details.

func (*Player) PlayPause

func (p *Player) PlayPause() error

PlayPause pauses the player if it is playing. Otherwise, it resumes playback. See https://github.com/popcornmix/omxplayer#playpause for more details.

func (*Player) PlaybackStatus

func (p *Player) PlaybackStatus() (string, error)

PlaybackStatus returns the current state of the player. See https://github.com/popcornmix/omxplayer#playbackstatus for more details.

func (*Player) Position

func (p *Player) Position() (int64, error)

Position returns the current position in the video in milliseconds. See https://github.com/popcornmix/omxplayer#position for more details.

func (*Player) Previous

func (p *Player) Previous() error

Previous tells the player to skip to the previous chapter. See https://github.com/popcornmix/omxplayer#previous for more details.

func (*Player) Quit

func (p *Player) Quit() error

Quit stops the currently playing video and terminates the omxplayer process. See https://github.com/popcornmix/omxplayer#quit for more details.

func (*Player) ResHeight

func (p *Player) ResHeight() (int64, error)

ResHeight returns the height of the video. See https://github.com/popcornmix/omxplayer/blob/master/OMXControl.cpp#L383.

func (*Player) ResWidth

func (p *Player) ResWidth() (int64, error)

ResWidth returns the width of the video. See https://github.com/popcornmix/omxplayer/blob/master/OMXControl.cpp#L376.

func (*Player) Seek

func (p *Player) Seek(amount int64) (int64, error)

Seek performs a relative seek from the current video position. See https://github.com/popcornmix/omxplayer#seek for more details.

func (*Player) SelectAudio

func (p *Player) SelectAudio(index int32) (bool, error)

SelectAudio specifies which audio track should be used. See https://github.com/popcornmix/omxplayer#selectaudio for more details.

func (*Player) SelectSubtitle

func (p *Player) SelectSubtitle(index int32) (bool, error)

SelectSubtitle specifies which subtitle track should be used. See https://github.com/popcornmix/omxplayer#selectsubtitle for more details.

func (*Player) SetPosition

func (p *Player) SetPosition(path string, position int64) (int64, error)

SetPosition performs an absolute seek to the specified video position. See https://github.com/popcornmix/omxplayer#setposition for more details.

func (*Player) ShowSubtitles

func (p *Player) ShowSubtitles() error

ShowSubtitles starts displaying subtitles. See https://github.com/popcornmix/omxplayer#showsubtitles for more details.

func (*Player) Stop

func (p *Player) Stop() error

Stop tells the player to stop playing the video. See https://github.com/popcornmix/omxplayer#stop for more details.

func (*Player) SupportedMimeTypes

func (p *Player) SupportedMimeTypes() ([]string, error)

SupportedMimeTypes returns a list of supported MIME types. See https://github.com/popcornmix/omxplayer#supportedmimetypes for more details.

func (*Player) SupportedURISchemes

func (p *Player) SupportedURISchemes() ([]string, error)

SupportedURISchemes returns a list of playable URI formats. See https://github.com/popcornmix/omxplayer#supportedurischemes for more details.

func (*Player) UnHideVideo

func (p *Player) UnHideVideo() error

UnHideVideo is an undocumented D-Bus method. See https://github.com/popcornmix/omxplayer/blob/master/OMXControl.cpp#L462.

func (*Player) Unmute

func (p *Player) Unmute() error

Unmute unmutes the video's audio stream. See https://github.com/popcornmix/omxplayer#unmute for more details.

func (*Player) VideoStreamCount

func (p *Player) VideoStreamCount() (int64, error)

VideoStreamCount returns the number of available video streams. See https://github.com/popcornmix/omxplayer/blob/master/OMXControl.cpp#L369.

func (*Player) Volume

func (p *Player) Volume(volume ...float64) (float64, error)

Volume returns the current volume. Sets a new volume when an argument is specified. See https://github.com/popcornmix/omxplayer#volume for more details.

func (*Player) Wait

func (p *Player) Wait(status chan error)

Wait blocks till the running omxplayer instance ends and sends a signal through the supplied channel. This is just so we know exactly when omxplayer exits, mostly so we can tell when the video it was playing ended without having to Poll IsRunning().

func (*Player) WaitForReady

func (p *Player) WaitForReady()

WaitForReady waits until the Player instance is ready to accept D-Bus commands and then returns.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL