| Module | SoundManager2::Helper |
| In: |
lib/sound_manager2.rb
|
Defines helper methods that are automatically mixed-in to ActionView::Base by the Rails plugin, allowing all view files access to them.
Generates HTML that includes the required SoundManager2 Javascsript files, initializes the SoundManager2 API, and optionally allows the developer to specify initialization actions (like SoundManager#create_sound) via a passed in block.
# File lib/sound_manager2.rb, line 37
37: def initialize_sound_manager(debug=false, swf_url="/soundmanager2.swf")
38: soundman = SoundManager.new
39: yield soundman if block_given?
40:
41: output = javascript_include_tag("soundmanager2-jsmin") + "\n"
42: output += javascript_include_tag("soundmanager2-rails") + "\n"
43: output += javascript_tag(%Q{
44: soundManager.url = '#{swf_url}';
45: soundManager.debugMode = #{debug};
46: soundManager.consoleOnly = #{debug};
47: })
48:
49: output += javascript_tag(soundman.onload_function) if soundman.onload_function?
50: output
51: end
A convenience method to initialize the SoundManager2 and setup a list of sounds to play later. The required sound_array variable should be an array of arrays of the following format: [["sound_1_id", "sound_1_url"], ["sound_2_id", "sound_2_url"]]. Passing debug true will create a SoundManager2 console on your page and visibly log all SoundManager2 events. (There are plenty!)
# File lib/sound_manager2.rb, line 25
25: def initialize_sounds(sound_array, debug=false)
26: initialize_sound_manager(debug) do |soundman|
27: sound_array.each do |id, url|
28: soundman.create_sound(id, url)
29: end
30: end
31: end
Generates a "play" button that will toggle to a "pause" button when pressed, and vice versa. Pressing "play" starts playing the MP3 associated to _sound_id via the SoundManager2 API. (This method actually generates HTML and Javascript that should be included in your HTML ERB templates.)
The sound_id parameter here must correspond to a value specified by initialize_sounds (or indirectly via initialize_sound_manager) or else no sound will play.
# File lib/sound_manager2.rb, line 16
16: def toggle_sound(sound_id)
17: link_to_function image_tag("SoundManager2/play-control.gif", :border => 0), "toggle_sound('#{sound_id}')", :id => "#{sound_id}"
18: end