Last active
April 6, 2023 08:56
-
-
Save DucNg/4b60437832f2d007324eba200599b212 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"github.com/godbus/dbus/v5" | |
"github.com/godbus/dbus/v5/prop" | |
) | |
type Instancee struct { | |
props *prop.Properties | |
conn *dbus.Conn | |
} | |
var player = map[string]*prop.Prop{ | |
"PlaybackStatus": newProp("Playing", nil), | |
"Rate": newProp(1.0, nil), | |
"Metadata": newProp(map[string]interface{}{}, nil), | |
"Volume": newProp(float64(100), nil), | |
"Position": newProp(int64(0), nil), | |
"MinimumRate": newProp(1.0, nil), | |
"MaximumRate": newProp(1.0, nil), | |
"CanGoNext": newProp(false, nil), | |
"CanGoPrevious": newProp(false, nil), | |
"CanPlay": newProp(true, nil), | |
"CanPause": newProp(true, nil), | |
"CanSeek": newProp(false, nil), | |
"CanControl": newProp(false, nil), | |
} | |
var mediaPlayer2 = map[string]*prop.Prop{ | |
"CanQuit": newProp(false, nil), | |
"CanRaise": newProp(false, nil), | |
"HasTrackList": newProp(false, nil), | |
"Identity": newProp("myPlayer", nil), | |
"SupportedUriSchemes": newProp([]string{}, nil), | |
"SupportedMimeTypes": newProp([]string{}, nil), | |
} | |
func main() { | |
conn, err := dbus.ConnectSessionBus() | |
if err != nil { | |
log.Fatalln(err) | |
} | |
ins := &Instancee{ | |
conn: conn, | |
} | |
ins.props, err = prop.Export( | |
conn, | |
"/org/mpris/MediaPlayer2", | |
map[string]map[string]*prop.Prop{ | |
"org.mpris.MediaPlayer2": mediaPlayer2, | |
"org.mpris.MediaPlayer2.Player": player, | |
}, | |
) | |
if err != nil { | |
log.Fatalln(err) | |
} | |
reply, err := conn.RequestName("org.mpris.MediaPlayer2.myPlayer", dbus.NameFlagReplaceExisting) | |
if err != nil { | |
log.Fatalln(err) | |
} | |
if reply != dbus.RequestNameReplyPrimaryOwner { | |
log.Fatalln("Name already taken") | |
} | |
select {} | |
} | |
func newProp(value interface{}, cb func(*prop.Change) *dbus.Error) *prop.Prop { | |
return &prop.Prop{ | |
Value: value, | |
Writable: true, | |
Emit: prop.EmitTrue, | |
Callback: cb, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment