Class: Rubio::Radio
Instance Attribute Summary collapse
-
#player ⇒ Object
readonly
Returns the value of attribute player.
-
#stations ⇒ Object
readonly
Returns the value of attribute stations.
Instance Method Summary collapse
-
#initialize(backend, debug: false) ⇒ Radio
constructor
A new instance of Radio.
- #launch ⇒ Object
- #monitor_thread(debug) ⇒ Object
- #play_uuid(station_uuid) ⇒ Object
- #selected_station_at(idx) ⇒ Object
- #stop_uuid(station_uuid) ⇒ Object
Constructor Details
#initialize(backend, debug: false) ⇒ Radio
Returns a new instance of Radio.
11 12 13 14 15 16 17 18 |
# File 'lib/rubio/radio.rb', line 11 def initialize(backend, debug: false) @stations_all, @table = RadioBrowser.topvote(1000) @stations = @stations_all.dup @station_uuid = nil @player = Player.new(backend) monitor_thread(debug) end |
Instance Attribute Details
#player ⇒ Object (readonly)
Returns the value of attribute player.
9 10 11 |
# File 'lib/rubio/radio.rb', line 9 def player @player end |
#stations ⇒ Object (readonly)
Returns the value of attribute stations.
9 10 11 |
# File 'lib/rubio/radio.rb', line 9 def stations @stations end |
Instance Method Details
#launch ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rubio/radio.rb', line 64 def launch window('Rubio', 400, 200) do vertical_box do horizontal_box do stretchy false search_entry do |se| on_changed do filter_value = se.text if filter_value.empty? @stations.replace @stations_all.dup else @stations.replace(@stations_all.filter do |row_data| row_data.name.downcase.include?(filter_value.downcase) end) end end end end horizontal_box do table do ('Play') do on_clicked do |row| selected_station_at(row) end end text_column('name') text_column('language') cell_rows <= [self, :stations] end end end on_closing do @player.stop_all end end.show end |
#monitor_thread(debug) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rubio/radio.rb', line 20 def monitor_thread(debug) Glimmer::LibUI.timer(1) do p @player.history if debug next if @station_uuid.nil? || @player.alive? ("player '#{@player.backend}' stopped!", @player.thr.to_s) stop_uuid(@station_uuid) @station_uuid = nil true end end |
#play_uuid(station_uuid) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rubio/radio.rb', line 45 def play_uuid(station_uuid) station = uuid_to_station(station_uuid) begin @player.play(station.url) rescue StandardError => e (e.) raise e end station. = true end |
#selected_station_at(idx) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rubio/radio.rb', line 32 def selected_station_at(idx) raise unless idx.is_a?(Integer) station_uuid = stations[idx].stationuuid stop_uuid(@station_uuid) if @station_uuid == station_uuid @station_uuid = nil else play_uuid(station_uuid) @station_uuid = station_uuid end end |
#stop_uuid(station_uuid) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/rubio/radio.rb', line 56 def stop_uuid(station_uuid) return if station_uuid.nil? station = uuid_to_station(station_uuid) @player.stop station. = false end |