468,490 Members | 2,598 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,490 developers. It's quick & easy.

play sound files from the play list one by one

I created a jsp page having 1 textbox and play button...I hv sound files(.wav) of each english alphabet..I want to play the files sequentially acc. to the alphabets written in the textbox on button click...

Example::: if i write "abc" in the textbox..Then it will play a den b den c.....
May 2 '13 #1
6 4723
Dormilich
8,651 Expert Mod 8TB
what have you tried so far?
May 2 '13 #2
Expand|Select|Wrap|Line Numbers
  1. <%--
  2.     Document   : english_alp
  3.     Created on : Apr 28, 2013, 7:48:03 AM
  4.     Author     : Administrator
  5. --%>
  6.  
  7. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  8. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  9.    "http://www.w3.org/TR/html4/loose.dtd">
  10.  
  11. <html>
  12.     <head>
  13.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  14.         <style type="text/css" >
  15.             .try
  16.             {
  17.                 font-family: Arial;
  18.                 font-size:19px;
  19.                 font-weight: bold;
  20.  
  21.             }
  22.          </style>
  23.        <script language="javaScript" type="text/javascript">
  24.  
  25.            function pp(ttt)
  26.             {
  27.                 var t=document.getElementById("text1").value;
  28.                 var m=t+ttt;
  29.                 document.getElementById("text1").value=m;
  30.  
  31.        function PlaySound_2()
  32.            {
  33.  
  34.               var n=document.getElementById("text1").value;
  35.               var wavs = new Array(n);
  36.               for(i=0;i<n.toString().length;i++)
  37.                 {
  38.                        wavs[i]=n.toString().charAt(i);
  39.                        wavMovie = 'WAV_files/' + wavs[i]+'.wav';
  40.                        //alert(wavMovie);
  41.                       Player.setAttribute("src", wavMovie);
  42.                 }
  43.               //document.getElementsByName("filename","WAV_files/"+p+".wav");
  44.              //document.getElementsByTagName("body")[0].appendChild(Player);
  45.                 }
  46.  
  47.  
  48.        </script>
  49.  
  50.     </head>
  51.     <body>
  52.         <form name="Form1" method="post" action="waste.jsp" id="Form1" enctype="multipart/form-data">
  53.  
  54.              <input type="text" name="text1" id="text1" align="Center" style="font-family:'Arial'; font-size:large; height:30px; width:300px; POSITION:relative; top: 17px;" /><br /><br />
  55.              <input type="button" id="Button2" style="LEFT: 3px; POSITION:relative; top: 2px; width: 90px;" value="Play(D)" onclick = "PlaySound_2()"/><br /><br />
  56.              <input type="Reset" id="Button3" style="LEFT: 4px; POSITION:relative; top: 2px; width: 90px;" class="btn2"/><br /><br />
  57.              <table>
  58.                  <tr>
  59.                 <td><input style="height: 30px; width: 26px;" class="try" type="button" value="b" onclick="pp(this.value)" /></td>
  60.                 <td><input style="height: 30px; width: 26px;" class="try" type="button" value="a" onclick="pp(this.value)"/></td>
  61.                 <td><input style="height: 30px; width: 26px;" class="try" type="button" value="t" onclick="pp(this.value)"/></td>
  62.                 <td><input style="height: 30px; width: 26px;" class="try" type="button" value="p" onclick="pp(this.value)"/></td>
  63.                </tr>
  64.  
  65.  
  66.              <tr>
  67.  
  68.             <audio controls id="Player" autoplay>
  69.                 <param name="src"  />
  70.                 <source type="audio/wav">
  71.             </audio>
  72.              </tr>
  73.          </table>
  74.             <%--
  75.                 <td bgcolor="yellow">
  76.              <object id="Player" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,701" standby="loading microsoft windows media player components..." type="audio/wav" width="300" height="300">
  77.              <param name="filename" value=" ">
  78.              <param name="showcontrols" value="true">
  79.              <param name="ShowDisplay" value="true">
  80.              <param name="showcontrols" value="true">
  81.              <param name="quality" value="high" />
  82.              <param name="bgcolor" value="cyan" />
  83.              <param name="allowScriptAccess" value="sameDomain" />
  84.              <embed type="audio/wav" src="b.wav" pluginspage="http://www.microsoft.com/windows/windowsmedia/download/AllDownloads.aspx/"  Name=MediaPlayer ShowControls=1 width=320 height=240>
  85.              </embed>
  86.              </object>
  87.              </td> --%>
  88.  
  89.  
  90.  
  91.  
  92. </form>
  93.  </body>
  94. </html>
May 2 '13 #3
This is the code...folder WAV_files have b.wav ,t.wav ,p.wav ,a.wav files....I m using netbeans IDE
May 2 '13 #4
vijay6
158 100+
Hey preet11, try this code...

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Play</title>
  5.     <script>
  6.         function Play() {
  7.  
  8.             var chars = document.getElementById("textBox1").value;
  9.  
  10.             var n = chars.length;
  11.  
  12.             var charArray = new Array();
  13.  
  14.             for (var i = 0; i < n; i++) {
  15.                 charArray[i] = "\\WAV_files\\" + chars[i] + ".wav";
  16.             }
  17.  
  18.             var audio = new Audio();
  19.             audio.src = charArray[0];
  20.  
  21.             if (n > 0) {
  22.                 audio.play();
  23.             }
  24.  
  25.             var i = 0;
  26.  
  27.             audio.addEventListener('ended', function () {
  28.                 i++;
  29.                 if (i < n) {
  30.                     audio.src = charArray[i];
  31.                     audio.play();
  32.                 }
  33.             }, false);
  34.         }
  35.     </script>
  36. </head>
  37. <body>
  38.     <input type="text" id="textBox1" />
  39.     <button type="button" id="button1" onclick="Play()">Play</button>
  40. </body>
  41. </html>
May 3 '13 #5
thax vijay6....


i too solved dis problem...
here's the code....


Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML>
  2.  
  3. <html>
  4.     <head>
  5.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  6.             <script language="javaScript" type="text/javascript">
  7.             var flag=0,i=0;
  8.              var wavs = new Array();
  9.              wavs[0]="b.wav";
  10.              wavs[1]="s.wav";
  11.              wavs[2]="r.wav";
  12.                 function go()
  13.                 {
  14.  
  15.                      for( ;i<3; )
  16.                      {
  17.                         flag=1;
  18.                         break
  19.                         //alert(document.getElementById("Player").src=wavs[i]);
  20.                      }
  21.                      if(flag==1)
  22.                          {
  23.                              document.getElementById("Player").src=wavs[i];
  24.                              i++;
  25.                          }
  26.                 }
  27.             </script>
  28.     </head>
  29.     <body>
  30.          <audio id="Player" src="t.wav" onended="go()" controls autoplay >
  31.          </audio>
  32.     </body>
  33. </html>
May 3 '13 #6
Sherin
77 64KB
Try This Code

Expand|Select|Wrap|Line Numbers
  1. function playAudio (src) {
  2.     if(window.audio) {
  3.        audio.pause();
  4.     }
  5.     window.audio = new Audio (src);
  6.     window.audio.play();
  7. }
now all you need to do is to call it when you click on a link:

Expand|Select|Wrap|Line Numbers
  1. <tag onclick="playAudio('/link/to/audio.mp3')"> Click Me </tag>
Feb 3 '21 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by John | last post: by
3 posts views Thread by Bill Dandreta | last post: by
1 post views Thread by Lam | last post: by
10 posts views Thread by CM | last post: by
5 posts views Thread by djc | last post: by
2 posts views Thread by p1r0 | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.