Skip to content

Commit

Permalink
Merge pull request #51 from yhara/sound-looping
Browse files Browse the repository at this point in the history
Add loop_ to Sound#Play
  • Loading branch information
yhara authored May 30, 2024
2 parents c7c8193 + 4f4936a commit ec29ee8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/dxopal/sound.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ def initialize(path_or_url)
end
attr_accessor :decoded

# Play this sound once
def play
# Play this sound
def play(loop_ = false)
raise "Sound #{path_or_url} is not loaded yet" unless @decoded
source = nil
%x{
var context = #{Sound.audio_context};
source = context.createBufferSource();
source.buffer = #{@decoded};
if (#{loop_}) {
source.loop = true;
}
source.connect(context.destination);
source.start(0);
}
Expand Down

0 comments on commit ec29ee8

Please sign in to comment.