|
| 1 | +package mpris |
| 2 | + |
| 3 | +import ( |
| 4 | + librespot "github.com/devgianlu/go-librespot" |
| 5 | + "github.com/godbus/dbus/v5" |
| 6 | +) |
| 7 | + |
| 8 | +type PlaybackStatus string |
| 9 | + |
| 10 | +const ( |
| 11 | + Playing PlaybackStatus = "Playing" |
| 12 | + Paused PlaybackStatus = "Paused" |
| 13 | + Stopped PlaybackStatus = "Stopped" |
| 14 | +) |
| 15 | + |
| 16 | +type LoopStatus string |
| 17 | + |
| 18 | +const ( |
| 19 | + None LoopStatus = "None" |
| 20 | + Track LoopStatus = "Track" |
| 21 | + Playlist LoopStatus = "Playlist" |
| 22 | +) |
| 23 | + |
| 24 | +type MediaPlayer2PlayerCommandType int32 |
| 25 | + |
| 26 | +const ( |
| 27 | + MediaPlayer2PlayerCommandTypeNext MediaPlayer2PlayerCommandType = iota |
| 28 | + MediaPlayer2PlayerCommandTypePrevious |
| 29 | + MediaPlayer2PlayerCommandTypePause |
| 30 | + MediaPlayer2PlayerCommandTypePlayPause |
| 31 | + MediaPlayer2PlayerCommandTypeStop |
| 32 | + MediaPlayer2PlayerCommandTypePlay |
| 33 | + MediaPlayer2PlayerCommandTypeSeek |
| 34 | + MediaPlayer2PlayerCommandTypeSetPosition |
| 35 | + MediaPlayer2PlayerCommandTypeOpenUri |
| 36 | + MediaPlayer2PlayerCommandLoopStatusChanged |
| 37 | + MediaPlayer2PlayerCommandRateChanged |
| 38 | + MediaPlayer2PlayerCommandShuffleChanged |
| 39 | + MediaPlayer2PlayerCommandVolumeChanged |
| 40 | +) |
| 41 | + |
| 42 | +type MediaPlayer2PlayerCommand struct { |
| 43 | + Type MediaPlayer2PlayerCommandType |
| 44 | + Argument any |
| 45 | + |
| 46 | + response chan MediaPlayer2PlayerCommandResponse |
| 47 | +} |
| 48 | + |
| 49 | +func (m *MediaPlayer2PlayerCommand) Reply(resp MediaPlayer2PlayerCommandResponse) { |
| 50 | + m.response <- resp |
| 51 | +} |
| 52 | + |
| 53 | +type MediaPlayer2PlayerCommandResponse struct { |
| 54 | + Err *dbus.Error |
| 55 | +} |
| 56 | + |
| 57 | +type MediaState struct { |
| 58 | + PlaybackStatus PlaybackStatus |
| 59 | + LoopStatus LoopStatus |
| 60 | + Shuffle bool |
| 61 | + Volume float64 |
| 62 | + PositionMs int64 |
| 63 | + Uri *string // nilable |
| 64 | + Media *librespot.Media // nilable |
| 65 | +} |
| 66 | + |
| 67 | +type SeekState struct { |
| 68 | + PositionMs int64 |
| 69 | +} |
| 70 | + |
| 71 | +type Server interface { |
| 72 | + EmitStateUpdate(state MediaState) |
| 73 | + EmitSeekUpdate(state SeekState) |
| 74 | + Receive() <-chan MediaPlayer2PlayerCommand |
| 75 | + |
| 76 | + Close() error |
| 77 | +} |
| 78 | + |
| 79 | +func GetLoopStatus(repeatingContext bool, repeatingTrack bool) LoopStatus { |
| 80 | + if repeatingTrack { |
| 81 | + return Track |
| 82 | + } |
| 83 | + if repeatingContext { |
| 84 | + return Playlist |
| 85 | + } |
| 86 | + return None |
| 87 | +} |
| 88 | + |
| 89 | +type MediaPlayer2CommandSetPositionPayload struct { |
| 90 | + ObjectPath dbus.ObjectPath |
| 91 | + PositionUs int64 |
| 92 | +} |
| 93 | + |
| 94 | +type DummyServer struct { |
| 95 | +} |
| 96 | + |
| 97 | +func (d DummyServer) EmitStateUpdate(_ MediaState) { |
| 98 | +} |
| 99 | + |
| 100 | +func (d DummyServer) EmitSeekUpdate(_ SeekState) { |
| 101 | +} |
| 102 | + |
| 103 | +func (d DummyServer) Receive() <-chan MediaPlayer2PlayerCommand { |
| 104 | + return make(<-chan MediaPlayer2PlayerCommand) |
| 105 | +} |
| 106 | + |
| 107 | +func (d DummyServer) Close() error { return nil } |
0 commit comments