Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Advanced-java] Java Sound


  • From: Chairdee@xxxxxxxxxxxxxx (Chairdee)
  • Subject: [Advanced-java] Java Sound
  • Date: Mon, 25 Mar 2002 03:24:02 +0000

> This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

--MS_Mac_OE_3099871443_1246462_MIME_Part
Content-type: text/plain; charset="US-ASCII"
Content-transfer-encoding: 7bit

Hi all

Does any body know how to assign mulitple audioclips to a single Audioclip
object.
I've hit a dead end with this one.

I am repeating loads of code unnecessarily. e.g.

    public void actionPerformed(ActionEvent event) {
       //action for first icon
       Object source = event.getSource();
    
       if (source == temp) {
         //Try to get the AudioClip.
          for (int i = 0; i <p.patterns[currentPattern].length; i++){
            onceClip = soundList.getClip(p.patterns[currentPattern][0]);
            onceClip.play();     //Play it once.
            halt.setEnabled(true);
            loop.setEnabled(true);
           // clipsPlaying[0] = true;
          
           // newTemp = temp;
            //setVisible(true);
            
            showStatus("Playing sound " + p.patterns[currentPattern][0] +
".");
       if (onceClip == null) {
               showStatus("Sound " + p.patterns[currentPattern][0] + " not
loaded yet.");
       }
           return;
          }
          currentSound = onceClip;
       
       if(    event.getSource() == go)
           currentSound.loop();
       
       else if( event.getSource() == halt)
           currentSound.stop();


//action for second icon

       Object source1 = event.getSource();
      if(source1 == temp1){
           twiceClip= soundList.getClip(p.patterns[currentPattern][1]);
           twiceClip.play();
            //clipsPlaying[1] = true;
           
           showStatus("Playing sound " + p.patterns[currentPattern][1] +
".");
         if (twiceClip == null) {
           showStatus("Sound " + p.patterns[currentPattern][1] + " not
loaded yet.");
       }
   return;
       }
       
       currentSound = twiceClip;
       if(    event.getSource() == go)
           currentSound.loop();
       
       else if( event.getSource() == halt)
           currentSound.stop();

I have six icons on a JApplet and each one relates to a musical instrument
(AudioClip). The AppletSoundLoader class, loads and continuously runs all
AudioClips. When an icon is clicked a sampled sound file is played once
(about 4 seconds). This can happen to all icons infinitely.
The code above shows 'currentSound', an AudioClip object, being assigned to
> 1 AudioClip's. This occurs for all 6 icons/sounds.

Ironically it does work if each icon is selected in array order. When I say
'work' I mean all AudioClip's playback synchronously and stop synchronously.

This is propably confusing but I am relatively new to programmiung and would
really appreciate some feedback.

Thanks
Ferg 

--MS_Mac_OE_3099871443_1246462_MIME_Part
Content-type: text/html; charset="US-ASCII"
Content-transfer-encoding: quoted-printable

<HTML>
<HEAD>
<TITLE>Java Sound</TITLE>
</HEAD>
<BODY>
Hi all<BR>
<BR>
Does any body know how to assign mulitple audioclips to a single Audioclip =
object.<BR>
I've hit a dead end with this one.<BR>
<BR>
I am repeating loads of code unnecessarily. e.g.<BR>
<FONT SIZE=3D"2"><FONT FACE=3D"Times New Roman"><BR>
</FONT><FONT FACE=3D"Courier New"> &nbsp;&nbsp;&nbsp;public void actionPerfor=
med(ActionEvent event) {<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//action for first icon<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Object source =3D event.getSource(=
);<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (source =3D=3D temp) {<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Try to get the Aud=
ioClip.<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (int i =3D 0=
; i &lt;p.patterns[currentPattern].length; i++){<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;on=
ceClip =3D soundList.getClip(p.patterns[currentPattern][0]);<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;on=
ceClip.play(); &nbsp;&nbsp;&nbsp;&nbsp;//Play it once.<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ha=
lt.setEnabled(true);<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lo=
op.setEnabled(true);<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// clips=
Playing[0] =3D true;<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// newTe=
mp =3D temp; &nbsp;&nbsp;&nbsp;<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//=
setVisible(true);<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B=
R>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sh=
owStatus(&quot;Playing sound &quot; + p.patterns[currentPattern][0] + &quot;=
.&quot;);<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (onceClip =3D=3D null) {<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;showStatus(&quot;Sound &quot; + p.patterns[currentPattern][0=
] + &quot; not loaded yet.&quot;);<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<=
BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currentSound =3D=
 onceClip;<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if( &nbsp;&nbsp;&nbsp;event.getS=
ource() =3D=3D go)<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currentS=
ound.loop();<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else if( event.getSource() =3D=3D ha=
lt) &nbsp;&nbsp;&nbsp;<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currentS=
ound.stop();<BR>
<BR>
<BR>
//action for second icon<BR>
<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Object source1 =3D event.getSource=
();<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(source1 =3D=3D temp1){<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;twiceCli=
p=3D soundList.getClip(p.patterns[currentPattern][1]);<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;twiceCli=
p.play();<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//=
clipsPlaying[1] =3D true;<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;showStat=
us(&quot;Playing sound &quot; + p.patterns[currentPattern][1] + &quot;.&quot=
;);<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (twiceClip =3D=3D nul=
l) {<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;showStat=
us(&quot;Sound &quot; + p.patterns[currentPattern][1] + &quot; not loaded ye=
t.&quot;);<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
 &nbsp;&nbsp;&nbsp;return;<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currentSound =3D twiceClip;<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if( &nbsp;&nbsp;&nbsp;event.getS=
ource() =3D=3D go)<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currentS=
ound.loop();<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else if( event.getSource() =3D=3D ha=
lt) &nbsp;&nbsp;&nbsp;<BR>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currentS=
ound.stop();<BR>
</FONT></FONT><BR>
I have six icons on a JApplet and each one relates to a musical instrument =
(AudioClip). The AppletSoundLoader class, loads and continuously runs all Au=
dioClips. When an icon is clicked a sampled sound file is played once (about=
 4 seconds). This can happen to all icons infinitely. <BR>
The code above shows 'currentSound', an AudioClip object, being assigned to=
 &gt; 1 AudioClip's. This occurs for all 6 icons/sounds. <BR>
<BR>
Ironically it does work if each icon is selected in array order. When I say=
 'work' I mean all AudioClip's playback synchronously and stop synchronously=
.<BR>
<BR>
This is propably confusing but I am relatively new to programmiung and woul=
d really appreciate some feedback.<BR>
<BR>
Thanks<BR>
Ferg
</BODY>
</HTML>


--MS_Mac_OE_3099871443_1246462_MIME_Part--