mplayer

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2019 License: ISC Imports: 6 Imported by: 0

README

go-mplayer - Go interface with the MPlayer slave-mode

Short module allowing the user to control a fork'd MPlayer process in slave-mode.

You can read all about the MPlayer slave protocol at mplayerhq.hu

Requirements

MPlayer should be installed and available in the current PATH

Example

This example launches MPlayer in the background, requests it to play a file, wait for 5 seconds then stop playback:

import (
	"time"
	"github.com/tamentis/go-mplayer"
)

mplayer.StartSlave()

mplayer.SendCommand("loadfile /tmp/myfile.mp3")
time.Sleep(5 * time.Seconds)
mplayer.SendCommand("stop")

This example uses the blocking command PlayAndWait(), it allows you to use the module in a similar fashion to os/exec except that you can pre-load the process to get a better response time (e.g. on slow hardware):

import (
	"github.com/tamentis/go-mplayer"
)

mplayer.StartSlave()

mplayer.PlayAndWait("/tmp/myfile.mp3")

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Input is used to feed the slave subprocess commands.
	Input = make(chan string)
)

Functions

func PlayAndWait

func PlayAndWait(path string, volume uint)

PlayAndWait loads the given file and block until the file is done playing.

func PlayAndWaitWithDuration

func PlayAndWaitWithDuration(path string, volume uint, duration time.Duration)

PlayAndWaitWithDuration loads the given file and block until the file is done playing. This function will also stop playing after the given duration.

func SendCommand

func SendCommand(msg string)

SendCommand feeds the MPlayer slave with input commands.

func Skip

func Skip()

Skip attempts to cancel an existing PlayAndWait.

func StartSlave

func StartSlave(errorHandler ErrorHandler)

StartSlave keeps an mplayer process in slave mode open for the rest of time, consuming input from the mplayerInput channel and feeding it to the stdin of the process. If the process dies it is restarted automatically.

You are required to define an error handler function that will be called with all the errors that could have occured managing the slave.

Types

type ErrorHandler

type ErrorHandler func(error)

Jump to

Keyboard shortcuts

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