Wednesday, December 22, 2010

Play MP3 audio files in rails


If  you want to play mp3 files from your web application then you can do it by using SoundManager2plugin.
There are few steps that you need to follow.
Step 1: Install the soundmanger2 plugin.
Step 2:  Generate the soundmanager2 in your app. This will store the necessary files in your app.
1
ruby script/generate sound_manager2
Above command give following result.
1
2
3
4
5
6
public/soundmanager2.swf
public/javascripts/soundmanager2.js
public/javascripts/soundmanager2-jsmin.js
public/javascripts/soundmanager2-rails.js
public/images/SoundManager2/pause-control.gif
public/images/SoundManager2/play-control.gif
Step 3: Add below code in your view file.
1
2
3
4
5
6
7
<%=javascript_include_tag :defaults%>
<%=sounds=[[sound1,""][sound2,""]]%>
 
<%=initialize_sounds(sounds) %>
 
Play sound 1: <%= toggle_sound "sound1" %>
Play sound 2: <%= toggle_sound "sound2" %>
Now run view file and you will get Start and stop button to play mp3 file.

No comments:

Post a Comment