Class: Rockbox::Api::Playback
- Inherits:
-
Object
- Object
- Rockbox::Api::Playback
- Defined in:
- lib/rockbox/api/playback.rb
Constant Summary collapse
- TRACK_FIELDS =
<<~GQL fragment TrackFields on Track { id title artist album genre disc trackString yearString composer comment albumArtist grouping discnum tracknum layer year bitrate frequency filesize length elapsed path albumId artistId genreId albumArt } GQL
Instance Method Summary collapse
- #current_track ⇒ Rockbox::Track?
- #file_position ⇒ Integer
- #flush_and_reload ⇒ Object
-
#initialize(http) ⇒ Playback
constructor
A new instance of Playback.
- #next! ⇒ Object
- #next_track ⇒ Rockbox::Track?
- #pause ⇒ Object
-
#play(elapsed: 0, offset: 0) ⇒ Object
——————————————————————— Transport controls ———————————————————————.
- #play_album(album_id, shuffle: nil, position: nil) ⇒ Object
- #play_all_tracks(shuffle: nil, position: nil) ⇒ Object
- #play_artist(artist_id, shuffle: nil, position: nil) ⇒ Object
- #play_directory(path, recurse: nil, shuffle: nil, position: nil) ⇒ Object
- #play_liked_tracks(shuffle: nil, position: nil) ⇒ Object
- #play_playlist(playlist_id, shuffle: nil, position: nil) ⇒ Object
-
#play_track(path) ⇒ Object
——————————————————————— Single-call play helpers ———————————————————————.
- #previous! ⇒ Object
- #resume ⇒ Object
- #seek(position_ms) ⇒ Object
-
#status ⇒ Integer
One of PlaybackStatus constants.
-
#status_name ⇒ Symbol
:stopped | :playing | :paused | :unknown.
- #stop ⇒ Object
Constructor Details
#initialize(http) ⇒ Playback
Returns a new instance of Playback.
18 19 20 |
# File 'lib/rockbox/api/playback.rb', line 18 def initialize(http) @http = http end |
Instance Method Details
#current_track ⇒ Rockbox::Track?
37 38 39 40 |
# File 'lib/rockbox/api/playback.rb', line 37 def current_track data = @http.execute("#{TRACK_FIELDS}\nquery CurrentTrack { currentTrack { ...TrackFields } }") Track.from_hash(data[:current_track]) end |
#file_position ⇒ Integer
49 50 51 |
# File 'lib/rockbox/api/playback.rb', line 49 def file_position @http.execute("query FilePosition { getFilePosition }")[:get_file_position] end |
#flush_and_reload ⇒ Object
70 |
# File 'lib/rockbox/api/playback.rb', line 70 def flush_and_reload; @http.execute("mutation FlushReload { flushAndReloadTracks }"); nil; end |
#next! ⇒ Object
67 |
# File 'lib/rockbox/api/playback.rb', line 67 def next!; @http.execute("mutation Next { next }"); nil; end |
#next_track ⇒ Rockbox::Track?
43 44 45 46 |
# File 'lib/rockbox/api/playback.rb', line 43 def next_track data = @http.execute("#{TRACK_FIELDS}\nquery NextTrack { nextTrack { ...TrackFields } }") Track.from_hash(data[:next_track]) end |
#pause ⇒ Object
65 |
# File 'lib/rockbox/api/playback.rb', line 65 def pause; @http.execute("mutation Pause { pause }"); nil; end |
#play(elapsed: 0, offset: 0) ⇒ Object
Transport controls
57 58 59 60 61 62 63 |
# File 'lib/rockbox/api/playback.rb', line 57 def play(elapsed: 0, offset: 0) @http.execute( "mutation Play($elapsed: Long!, $offset: Long!) { play(elapsed: $elapsed, offset: $offset) }", { elapsed: elapsed, offset: offset } ) nil end |
#play_album(album_id, shuffle: nil, position: nil) ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/rockbox/api/playback.rb', line 93 def play_album(album_id, shuffle: nil, position: nil) @http.execute( "mutation PlayAlbum($albumId: String!, $shuffle: Boolean, $position: Int) { " \ "playAlbum(albumId: $albumId, shuffle: $shuffle, position: $position) }", { album_id: album_id, shuffle: shuffle, position: position }.compact ) nil end |
#play_all_tracks(shuffle: nil, position: nil) ⇒ Object
138 139 140 141 142 143 144 145 |
# File 'lib/rockbox/api/playback.rb', line 138 def play_all_tracks(shuffle: nil, position: nil) @http.execute( "mutation PlayAllTracks($shuffle: Boolean, $position: Int) { " \ "playAllTracks(shuffle: $shuffle, position: $position) }", { shuffle: shuffle, position: position }.compact ) nil end |
#play_artist(artist_id, shuffle: nil, position: nil) ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/rockbox/api/playback.rb', line 102 def play_artist(artist_id, shuffle: nil, position: nil) @http.execute( "mutation PlayArtist($artistId: String!, $shuffle: Boolean, $position: Int) { " \ "playArtistTracks(artistId: $artistId, shuffle: $shuffle, position: $position) }", { artist_id: artist_id, shuffle: shuffle, position: position }.compact ) nil end |
#play_directory(path, recurse: nil, shuffle: nil, position: nil) ⇒ Object
120 121 122 123 124 125 126 127 |
# File 'lib/rockbox/api/playback.rb', line 120 def play_directory(path, recurse: nil, shuffle: nil, position: nil) @http.execute( "mutation PlayDirectory($path: String!, $recurse: Boolean, $shuffle: Boolean, $position: Int) { " \ "playDirectory(path: $path, recurse: $recurse, shuffle: $shuffle, position: $position) }", { path: path, recurse: recurse, shuffle: shuffle, position: position }.compact ) nil end |
#play_liked_tracks(shuffle: nil, position: nil) ⇒ Object
129 130 131 132 133 134 135 136 |
# File 'lib/rockbox/api/playback.rb', line 129 def play_liked_tracks(shuffle: nil, position: nil) @http.execute( "mutation PlayLikedTracks($shuffle: Boolean, $position: Int) { " \ "playLikedTracks(shuffle: $shuffle, position: $position) }", { shuffle: shuffle, position: position }.compact ) nil end |
#play_playlist(playlist_id, shuffle: nil, position: nil) ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'lib/rockbox/api/playback.rb', line 111 def play_playlist(playlist_id, shuffle: nil, position: nil) @http.execute( "mutation PlayPlaylist($playlistId: String!, $shuffle: Boolean, $position: Int) { " \ "playPlaylist(playlistId: $playlistId, shuffle: $shuffle, position: $position) }", { playlist_id: playlist_id, shuffle: shuffle, position: position }.compact ) nil end |
#play_track(path) ⇒ Object
Single-call play helpers
85 86 87 88 89 90 91 |
# File 'lib/rockbox/api/playback.rb', line 85 def play_track(path) @http.execute( "mutation PlayTrack($path: String!) { playTrack(path: $path) }", { path: path } ) nil end |
#previous! ⇒ Object
68 |
# File 'lib/rockbox/api/playback.rb', line 68 def previous!; @http.execute("mutation Previous { previous }"); nil; end |
#resume ⇒ Object
66 |
# File 'lib/rockbox/api/playback.rb', line 66 def resume; @http.execute("mutation Resume { resume }"); nil; end |
#seek(position_ms) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/rockbox/api/playback.rb', line 73 def seek(position_ms) @http.execute( "mutation Seek($newTime: Int!) { fastForwardRewind(newTime: $newTime) }", { new_time: position_ms } ) nil end |
#status ⇒ Integer
Returns one of PlaybackStatus constants.
27 28 29 |
# File 'lib/rockbox/api/playback.rb', line 27 def status @http.execute("query PlaybackStatus { status }")[:status] end |
#status_name ⇒ Symbol
Returns :stopped | :playing | :paused | :unknown.
32 33 34 |
# File 'lib/rockbox/api/playback.rb', line 32 def status_name PlaybackStatus.name(status) end |
#stop ⇒ Object
69 |
# File 'lib/rockbox/api/playback.rb', line 69 def stop; @http.execute("mutation Stop { hardStop }"); nil; end |