Class: GstPlayer
Instance Attribute Summary collapse
-
#audio_params ⇒ Object
Returns the value of attribute audio_params.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#paused ⇒ Object
readonly
Returns the value of attribute paused.
Instance Method Summary collapse
- #close ⇒ Object
- #gstPlayUrl(url) ⇒ Object
-
#initialize(params = {}) ⇒ GstPlayer
constructor
A new instance of GstPlayer.
-
#logscale(val, inverse = false) ⇒ Object
approximation to a logarithmic scale.
- #mute ⇒ Object
- #muted? ⇒ Boolean
- #pause ⇒ Object
- #play(track) ⇒ Object
- #playing? ⇒ Boolean
- #stop ⇒ Object
- #version ⇒ Object
- #volume ⇒ Object
- #volume=(val) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ GstPlayer
Returns a new instance of GstPlayer.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/gstplayer.rb', line 20 def initialize params = {} @curvature = 4 params.each { |key, value| send "#{key}=", value } unless defined? Gst puts "Gstream backend requires gstream gem" exit false end @logger.info version @inqueue = [] begin @pipeline = Gst::ElementFactory.make("playbin", "cloudruby_pipeline") if @pipeline.nil? puts "Cannot initialize playing pipeline. Is gstreamer installed?" exit false end @pipeline.set_property "buffer-size", 16 * 1024 * 1024 if @audio_params @audio_params.each do |key, value| case key when :"audio-sink" sink = Gst::ElementFactory.make(value, "#{value}") @pipeline.set_property "audio-sink", sink unless sink.nil? when :"buffer-duration", :"buffer-size", :"mute", :"volume" @pipeline.set_property key, value when :volume @pipeline.set_property key, logscale(value) when :"volume-curvature" @curvature = value.to_f end end end changed notify_observers :state => :inited runMainLoop rescue => err @error = err changed notify_observers :state => :error, :error => err end end |
Instance Attribute Details
#audio_params ⇒ Object
Returns the value of attribute audio_params.
9 10 11 |
# File 'lib/gstplayer.rb', line 9 def audio_params @audio_params end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
8 9 10 |
# File 'lib/gstplayer.rb', line 8 def error @error end |
#logger ⇒ Object
Returns the value of attribute logger.
9 10 11 |
# File 'lib/gstplayer.rb', line 9 def logger @logger end |
#paused ⇒ Object (readonly)
Returns the value of attribute paused.
8 9 10 |
# File 'lib/gstplayer.rb', line 8 def paused @paused end |
Instance Method Details
#close ⇒ Object
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/gstplayer.rb', line 143 def close() @pipeline.stop @mainloop.quit changed notify_observers :state => :closed rescue => err @error = err changed notify_observers :state => :error, :error => err end |
#gstPlayUrl(url) ⇒ Object
154 155 156 157 158 |
# File 'lib/gstplayer.rb', line 154 def gstPlayUrl(url) @pipeline.stop @pipeline.uri = url @pipeline.play end |
#logscale(val, inverse = false) ⇒ Object
approximation to a logarithmic scale
102 103 104 105 106 107 108 109 |
# File 'lib/gstplayer.rb', line 102 def logscale val, inverse = false val = val.to_f if inverse 100 * (val ** (1.0/@curvature)) else (val/100)**@curvature end end |
#mute ⇒ Object
129 130 131 132 133 134 135 136 137 |
# File 'lib/gstplayer.rb', line 129 def mute @pipeline.set_property "mute", !@pipeline.get_property("mute") changed notify_observers :state => :status, :type => "Volume", :value => "#{muted? ? 0 : volume}%" rescue => err @error = err changed notify_observers :state => :error, :error => err end |
#muted? ⇒ Boolean
139 140 141 |
# File 'lib/gstplayer.rb', line 139 def muted? @pipeline.get_property "mute" end |
#pause ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/gstplayer.rb', line 80 def pause() @paused = !@paused if @paused @pipeline.pause else @pipeline.play end rescue => err @error = err changed notify_observers :state => :error, :error => err end |
#play(track) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/gstplayer.rb', line 63 def play(track) @last_track = track unless track.nil? || track.is_a?(Hash) && track[:error] && !Gst.valid_uri?(track["mpg123url"]) gstPlayUrl track["mpg123url"] end changed notify_observers :state => :load, :track => track rescue => err @error = err changed notify_observers :state => :error, :error => err end |
#playing? ⇒ Boolean
76 77 78 |
# File 'lib/gstplayer.rb', line 76 def @pipeline. end |
#stop ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/gstplayer.rb', line 93 def stop() @playbin.stop rescue => err @error = err changed notify_observers :state => :error, :error => err end |
#version ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/gstplayer.rb', line 11 def version as = nil unless @pipeline.nil? as = @pipeline.get_property "audio-sink" as = ", Sink: #{as.name}" end return "Audio backend: Gstreamer #{Gst.version.join('.')}#{as}" end |
#volume ⇒ Object
124 125 126 127 |
# File 'lib/gstplayer.rb', line 124 def volume logval = @pipeline.get_property("volume").to_f logscale logval, true end |
#volume=(val) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/gstplayer.rb', line 111 def volume= (val) vol = volume vol += val vol = [0, [vol, 100].min].max @pipeline.volume = logscale(vol) changed notify_observers :state => :status, :type => "Volume", :value => "#{vol.to_i}%" rescue => err @error = err changed notify_observers :state => :error, :error => err end |