goomx

package module
v0.0.0-...-c0c45f6 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: MIT Imports: 19 Imported by: 0

README

omxplayer

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/sonnt85/goomx

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

import (
	"github.com/sonnt85/goomx"
)

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.

goomx.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 {
	goomx.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 := goomx.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:

goomx.SetUser("root", "/root")
player, err := goomx.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

Index

Constants

View Source
const (
	ACTION_DECREASE_SPEED          = 1
	ACTION_INCREASE_SPEED          = 2
	ACTION_REWIND                  = 3
	ACTION_FAST_FORWARD            = 4
	ACTION_SHOW_INFO               = 5
	ACTION_PREVIOUS_AUDIO          = 6
	ACTION_NEXT_AUDIO              = 7
	ACTION_PREVIOUS_CHAPTER        = 8
	ACTION_NEXT_CHAPTER            = 9
	ACTION_PREVIOUS_SUBTITLE       = 10
	ACTION_NEXT_SUBTITLE           = 11
	ACTION_TOGGLE_SUBTITLE         = 12
	ACTION_DECREASE_SUBTITLE_DELAY = 13
	ACTION_INCREASE_SUBTITLE_DELAY = 14
	ACTION_EXIT                    = 15
	ACTION_PLAYPAUSE               = 16
	ACTION_DECREASE_VOLUME         = 17
	ACTION_INCREASE_VOLUME         = 18
	ACTION_SEEK_BACK_SMALL         = 19
	ACTION_SEEK_FORWARD_SMALL      = 20
	ACTION_SEEK_BACK_LARGE         = 21
	ACTION_SEEK_FORWARD_LARGE      = 22
	ACTION_SEEK_RELATIVE           = 25
	ACTION_SEEK_ABSOLUTE           = 26
	ACTION_STEP                    = 23
	ACTION_BLANK                   = 24
	ACTION_MOVE_VIDEO              = 27
	ACTION_HIDE_VIDEO              = 28
	ACTION_UNHIDE_VIDEO            = 29
	ACTION_HIDE_SUBTITLES          = 30
	ACTION_SHOW_SUBTITLES          = 31
	ACTION_SET_ALPHA               = 32
	ACTION_SET_ASPECT_MODE         = 33
	ACTION_CROP_VIDEO              = 34
	ACTION_PAUSE                   = 35
	ACTION_PLAY                    = 36
	ACTION_CHANGE_FILE             = 37
	ACTION_SET_LAYER               = 38
)

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 CommonOmx

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

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

type FilePlay

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

type Player

type Player struct {
	*goring.EventLinkedList[string]
	CommandKeysBuffer *bytes.Buffer

	SeekStep *gosyncutils.EventOpject[int]

	CancelFunc context.CancelFunc
	// contains filtered or unexported fields
}
var Gplayer *Player

func NewPlayer

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

func (*Player) ActiveViewDefaultPictures

func (p *Player) ActiveViewDefaultPictures(picspath string)

func (*Player) AddVideoToPlaylist

func (p *Player) AddVideoToPlaylist(finename string, index int) bool

func (*Player) CmdAction

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

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

func (*Player) CmdAspect

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

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

func (*Player) CmdCanControl

func (p *Player) CmdCanControl() (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) CmdCanGoNext

func (p *Player) CmdCanGoNext() (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) CmdCanGoPrevious

func (p *Player) CmdCanGoPrevious() (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) CmdCanPause

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

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

func (*Player) CmdCanPlay

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

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

func (*Player) CmdCanQuit

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

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

func (*Player) CmdCanRaise

func (p *Player) CmdCanRaise() (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) CmdCanSeek

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

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

func (*Player) CmdCanSetFullscreen

func (p *Player) CmdCanSetFullscreen() (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) CmdDuration

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

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

func (*Player) CmdFullscreen

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

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

func (*Player) CmdGetSource

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

func (*Player) CmdHasTrackList

func (p *Player) CmdHasTrackList() (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) CmdHideSubtitles

func (p *Player) CmdHideSubtitles() error

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

func (*Player) CmdHideVideo

func (p *Player) CmdHideVideo() error

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

func (*Player) CmdIdentity

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

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

func (*Player) CmdListVideo

func (p *Player) CmdListVideo() ([]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) CmdMaximumRate

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

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

func (*Player) CmdMinimumRate

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

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

func (*Player) CmdMute

func (p *Player) CmdMute() error

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

func (*Player) CmdNextTrack

func (p *Player) CmdNextTrack() error

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

func (*Player) CmdOpenUri

func (p *Player) CmdOpenUri(uripath string) error

func (*Player) CmdPause

func (p *Player) CmdPause() 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) CmdPlay

func (p *Player) CmdPlay() 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) CmdPlayPause

func (p *Player) CmdPlayPause() 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) CmdPlaybackStatus

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

func (*Player) CmdPreviousTrack

func (p *Player) CmdPreviousTrack() error

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

func (*Player) CmdQuit

func (p *Player) CmdQuit() error

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

func (*Player) CmdRaise

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

func (*Player) CmdResWidth

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

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

func (*Player) CmdSeek

func (p *Player) CmdSeek(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) CmdSelectAudio

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

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

func (*Player) CmdSelectSubtitle

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

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

func (*Player) CmdSetPosition

func (p *Player) CmdSetPosition(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) CmdShowSubtitles

func (p *Player) CmdShowSubtitles() error

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

func (*Player) CmdStop

func (p *Player) CmdStop() bool

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

func (*Player) CmdSupportedMimeTypes

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

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

func (*Player) CmdSupportedURISchemes

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

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

func (*Player) CmdUnHideVideo

func (p *Player) CmdUnHideVideo() error

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

func (*Player) CmdUnmute

func (p *Player) CmdUnmute() error

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

func (*Player) CmdVideoStreamCount

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

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

func (*Player) CmdVolume

func (p *Player) CmdVolume(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) CmdVolumePercent

func (p *Player) CmdVolumePercent(volume ...int) (volint int, err 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) ConfigureNewPlaylist

func (p *Player) ConfigureNewPlaylist(list []string) (chaged bool)

func (*Player) GetPlaying

func (p *Player) GetPlaying() (retfile string, ok bool)

func (*Player) GetPlaylist

func (p *Player) GetPlaylist() (retstrs []string)

func (*Player) GetPlaylistWithoutPath

func (p *Player) GetPlaylistWithoutPath() []string

func (*Player) GetSavedVolume

func (p *Player) GetSavedVolume() float64

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) Play

func (p *Player) Play() bool

func (*Player) PlayIsActive

func (p *Player) PlayIsActive() bool

func (*Player) PlayNextVideo

func (p *Player) PlayNextVideo() (retfile string, ok bool)

func (*Player) PlayPrevVideo

func (p *Player) PlayPrevVideo() (retfile string, ok bool)

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) Quit

func (p *Player) Quit()

func (*Player) RemoveVideoFromPlaylist

func (p *Player) RemoveVideoFromPlaylist(index int) bool

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) SeekVideos

func (p *Player) SeekVideos(n int) (retfile string, ok bool)

func (*Player) Stop

func (p *Player) Stop()

func (*Player) VideosDoesNotExist

func (p *Player) VideosDoesNotExist() (retstrs []string)

func (*Player) WaitFinishCurrentPlaying

func (p *Player) WaitFinishCurrentPlaying()

func (*Player) WaitForQuitTimeOut

func (p *Player) WaitForQuitTimeOut(timeout time.Duration) bool

func (*Player) WaitForReady

func (p *Player) WaitForReady()

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

func (*Player) WaitForReadyWithTimeOut

func (p *Player) WaitForReadyWithTimeOut(timeout time.Duration) bool

Jump to

Keyboard shortcuts

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