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.
- #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.
17 18 19 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 |
# File 'lib/gstplayer.rb', line 17 def initialize params = {} params.each { |key, value| send "#{key}=", value } @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 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.
6 7 8 |
# File 'lib/gstplayer.rb', line 6 def audio_params @audio_params end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
5 6 7 |
# File 'lib/gstplayer.rb', line 5 def error @error end |
#logger ⇒ Object
Returns the value of attribute logger.
6 7 8 |
# File 'lib/gstplayer.rb', line 6 def logger @logger end |
#paused ⇒ Object (readonly)
Returns the value of attribute paused.
5 6 7 |
# File 'lib/gstplayer.rb', line 5 def paused @paused end |
Instance Method Details
#close ⇒ Object
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/gstplayer.rb', line 121 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
132 133 134 135 136 |
# File 'lib/gstplayer.rb', line 132 def gstPlayUrl(url) @pipeline.stop @pipeline.uri = url @pipeline.play end |
#mute ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/gstplayer.rb', line 107 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
117 118 119 |
# File 'lib/gstplayer.rb', line 117 def muted? @pipeline.get_property "mute" end |
#pause ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/gstplayer.rb', line 68 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
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/gstplayer.rb', line 51 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
64 65 66 |
# File 'lib/gstplayer.rb', line 64 def @pipeline. end |
#stop ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/gstplayer.rb', line 81 def stop() @playbin.stop rescue => err @error = err changed notify_observers :state => :error, :error => err end |
#version ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/gstplayer.rb', line 8 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
103 104 105 |
# File 'lib/gstplayer.rb', line 103 def volume (@pipeline.get_property("volume") * 100).to_int end |
#volume=(val) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/gstplayer.rb', line 89 def volume= (val) @volume = volume @volume += val @volume = [@volume, 100].min @volume = [@volume, 0].max @pipeline.volume = @volume/100.0 changed notify_observers :state => :status, :type => "Volume", :value => "#{@volume}%" rescue => err @error = err changed notify_observers :state => :error, :error => err end |