Skip to content

Commit

Permalink
Add loop_ to Sound#Play
Browse files Browse the repository at this point in the history
  • Loading branch information
yhara committed May 30, 2024
1 parent c7c8193 commit 4f4936a
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 4f4936a

Please sign in to comment.