Class: Audio

Inherits:
Object
  • Object
show all
Defined in:
lib/kita/audio.rb

Overview

Initialise Gstreamer for sounds

Instance Method Summary collapse

Constructor Details

#initializeAudio

Returns a new instance of Audio.



7
8
9
# File 'lib/kita/audio.rb', line 7

def initialize
  setup_gst
end

Instance Method Details

#play(uri) ⇒ Object



23
24
25
26
27
# File 'lib/kita/audio.rb', line 23

def play(uri)
  @playbin.stop
  @playbin.uri = Gst.filename_to_uri("#{RootPath}/sounds/#{uri}.ogg")
  @playbin.play
end

#repeatObject



29
30
31
32
# File 'lib/kita/audio.rb', line 29

def repeat
  @playbin.stop
  @playbin.play
end

#setup_gstObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/kita/audio.rb', line 11

def setup_gst
  Gst.init
  @playbin = Gst::ElementFactory.make('playbin3')

  @playbin.bus.add_watch do |_bus, message|
    case message.type
    when Gst::MessageType::EOS
      @playbin.stop
    end
  end
end