Example #1
0
func eventHandler(plyr *player.Player, bus chan *player.Event) {
	var event *player.Event
	for !plyr.Connected {
		fmt.Println("Waiting for player to connect")
	}
	for plyr.Connected {
		event = <-bus
		fmt.Println(event)
		plyr.Send("received event.")
	}
}
Example #2
0
func Run(p *player.Player) error {
	conn, err := dbus.SessionBus()
	if err != nil {
		return fmt.Errorf("Could not get session bus: %s", err)
	}

	reply, err := conn.RequestName(bus_name, dbus.NameFlagDoNotQueue)
	if err != nil {
		return fmt.Errorf("Could not request name: %s", err)
	}

	if reply != dbus.RequestNameReplyPrimaryOwner {
		return fmt.Errorf("Name already take")
	}

	bus_props_spec := map[string]map[string]*prop.Prop{
		bus_interface_player: {
			"PlaybackStatus": {
				p.Status.String(), false,
				prop.EmitTrue, nil,
			},

			"LoopStatus": {
				"none", true, prop.EmitTrue, SetLoopStatus,
			},

			"TrackMetadata": {
				map[string]string{}, false, prop.EmitTrue, nil,
			},

			"TrackPath": {
				"", false, prop.EmitTrue, nil,
			},

			"TrackLength": {
				float64(0), false, prop.EmitTrue, nil,
			},

			"TrackTitle": {
				"", false, prop.EmitTrue, nil,
			},

			"Tracks": {
				[]string{}, false, prop.EmitTrue, nil,
			},

			"Volume": {
				0.0, true, prop.EmitTrue, SetVolume,
			},
		},
	}

	bus = &Bus{
		player: p,
		props:  prop.New(conn, bus_path, bus_props_spec),
	}

	conn.Export(bus, bus_path, bus_interface_player)

	p.HandleStatusChange = HandleStatusChange
	p.HandleTrackChange = HandleTrackChange
	p.HandleTracksChange = HandleTracksChange
	p.HandleVolumeChange = HandleVolumeChange

	introspect := introspect.Introspectable(bus_introspection)
	conn.Export(introspect, bus_path, bus_interface_introspect)

	return nil
}