Skip to content

pauloo27/go-mpris

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

45 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

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.

About

๐Ÿ“š A Go library for MPRIS

Topics

Resources

License

Stars

Watchers

Forks

Languages

  • Go 100.0%