mpris

package module
v1.4.1-0...-cab9ae3 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: MIT Imports: 3 Imported by: 0

README

GO-MPRIS

A Go library for MPRIS.

Install

$ go get github.com/Pauloo27/go-mpris

the dependency github.com/godbus/dbus/v5 is going to be installed as well.

Example

Printing the current playback status and then changing it:

import (
	"log"

	"github.com/Pauloo27/go-mpris"
	"github.com/godbus/dbus/v5"
)

func main() {
	conn, err := dbus.SessionBus()
	if err != nil {
		panic(err)
	}
	names, err := mpris.List(conn)
	if err != nil {
		panic(err)
	}
	if len(names) == 0 {
		log.Fatal("No player found")
	}

	name := names[0]
	player := mpris.New(conn, name)

	status, err := player.GetPlaybackStatus()
	if err != nil {
		log.Fatal("Could not get current playback status")
	}

	log.Printf("The player was %s...", status)
	err = player.PlayPause()
	if err != nil {
		log.Fatal("Could not play/pause player")
	}
}

For more examples, see the examples folder.

Go Docs

Read the docs at https://pkg.go.dev/github.com/Pauloo27/go-mpris.

Credits

emersion for the original code.

Documentation

Index

Constants

View Source
const (
	BaseInterface      = "org.mpris.MediaPlayer2"
	PlayerInterface    = "org.mpris.MediaPlayer2.Player"
	TrackListInterface = "org.mpris.MediaPlayer2.TrackList"
	PlaylistsInterface = "org.mpris.MediaPlayer2.Playlists"
)

Variables

This section is empty.

Functions

func List

func List(conn *dbus.Conn) ([]string, error)

List lists the available players.

Types

type LoopStatus

type LoopStatus string

LoopStatus the status of the player loop. It can be "None", "Track" or "Playlist".

const (
	LoopNone     LoopStatus = "None"
	LoopTrack    LoopStatus = "Track"
	LoopPlaylist LoopStatus = "Playlist"
)

type PlaybackStatus

type PlaybackStatus string

PlaybackStatus the status of the playback. It can be "Playing", "Paused" or "Stopped".

const (
	PlaybackPlaying PlaybackStatus = "Playing"
	PlaybackPaused  PlaybackStatus = "Paused"
	PlaybackStopped PlaybackStatus = "Stopped"
)

type Player

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

Player represents a mpris player.

func New

func New(conn *dbus.Conn, name string) *Player

New connects the the player with the name in the connection conn.

func (*Player) GetIdentity

func (i *Player) GetIdentity() (string, error)

GetIdentity returns the player identity.

func (*Player) GetLength

func (i *Player) GetLength() (float64, error)

GetLength returns the current track length in seconds.

func (*Player) GetLoopStatus

func (i *Player) GetLoopStatus() (LoopStatus, error)

GetLoopStatus returns the loop status.

func (*Player) GetMetadata

func (i *Player) GetMetadata() (map[string]dbus.Variant, error)

GetMetadata returns the metadata.

func (*Player) GetName

func (i *Player) GetName() string

GetName gets the player full name.

func (*Player) GetPlaybackStatus

func (i *Player) GetPlaybackStatus() (PlaybackStatus, error)

GetPlaybackStatus gets the playback status.

func (*Player) GetPlayerProperty

func (i *Player) GetPlayerProperty(properityName string) (dbus.Variant, error)

GetPlayerProperty returns the properityName from the player interface.

func (*Player) GetPosition

func (i *Player) GetPosition() (float64, error)

GetPosition returns the position in seconds of the current track.

func (*Player) GetProperty

func (i *Player) GetProperty(targetInterface, properityName string) (dbus.Variant, error)

GetProperty returns the properityName in the targetInterface.

func (*Player) GetRate

func (i *Player) GetRate() (float64, error)

Returns the current playback rate.

func (*Player) GetShuffle

func (i *Player) GetShuffle() (bool, error)

GetShuffle returns false if the player is going linearly through a playlist and false if it's in some other order.

func (*Player) GetVolume

func (i *Player) GetVolume() (float64, error)

GetVolume returns the volume.

func (*Player) Next

func (i *Player) Next() error

Next skips to the next track in the tracklist.

func (*Player) OnSignal

func (i *Player) OnSignal(ch chan<- *dbus.Signal) (err error)

OnSignal adds a handler to the player's properties change signal.

func (*Player) OpenUri

func (i *Player) OpenUri(uri string) error

OpenUri opens and plays the uri if supported.

func (*Player) Pause

func (i *Player) Pause() error

Pause pauses the current track.

func (*Player) Play

func (i *Player) Play() error

Play starts or resumes the current track.

func (*Player) PlayPause

func (i *Player) PlayPause() error

PlayPause resumes the current track if it's paused and pauses it if it's playing.

func (*Player) Previous

func (i *Player) Previous() error

Previous skips to the previous track in the tracklist.

func (*Player) Quit

func (i *Player) Quit() error

Quit closes the player.

func (*Player) Raise

func (i *Player) Raise() error

Raise raises player priority.

func (*Player) Seek

func (i *Player) Seek(offset float64) error

Seek seeks the current track position by the offset. The offset should be in seconds. If the offset is negative it's seeked back.

func (*Player) SetLoopStatus

func (i *Player) SetLoopStatus(loopStatus LoopStatus) error

SetLoopStatus sets the loop status to loopStatus.

func (*Player) SetPlayerProperty

func (i *Player) SetPlayerProperty(propertyName string, value interface{}) error

SetPlayerProperty sets the propertyName from the player interface.

func (*Player) SetPosition

func (i *Player) SetPosition(position float64) error

SetPosition sets the position of the current track. The position should be in seconds.

func (*Player) SetProperty

func (i *Player) SetProperty(targetInterface, propertyName string, value interface{}) error

SetProperty sets the value of a propertyName in the targetInterface.

func (*Player) SetShuffle

func (i *Player) SetShuffle(value bool) error

SetShuffle sets the shuffle playlist mode.

func (*Player) SetTrackPosition

func (i *Player) SetTrackPosition(trackId *dbus.ObjectPath, position float64) error

SetTrackPosition sets the position of a track. The position should be in seconds.

func (*Player) SetVolume

func (i *Player) SetVolume(volume float64) error

SetVolume sets the volume.

func (*Player) Stop

func (i *Player) Stop() error

Stop stops the current track.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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