From 4f4936a55f1d257df958f5bc6723e37d49c3f004 Mon Sep 17 00:00:00 2001 From: Yutaka HARA Date: Thu, 30 May 2024 22:41:42 +0900 Subject: [PATCH] Add loop_ to Sound#Play --- lib/dxopal/sound.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/dxopal/sound.rb b/lib/dxopal/sound.rb index baeeca3..1102647 100644 --- a/lib/dxopal/sound.rb +++ b/lib/dxopal/sound.rb @@ -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); }