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"> public void actionPerfor=
med(ActionEvent event) {<BR>
//action for first icon<BR>
Object source =3D event.getSource(=
);<BR>
<BR>
if (source =3D=3D temp) {<BR>
//Try to get the Aud=
ioClip.<BR>
for (int i =3D 0=
; i <p.patterns[currentPattern].length; i++){<BR>
on=
ceClip =3D soundList.getClip(p.patterns[currentPattern][0]);<BR>
on=
ceClip.play(); //Play it once.<BR>
ha=
lt.setEnabled(true);<BR>
lo=
op.setEnabled(true);<BR>
// clips=
Playing[0] =3D true;<BR>
<BR>
// newTe=
mp =3D temp; <BR>
//=
setVisible(true);<BR>
<B=
R>
sh=
owStatus("Playing sound " + p.patterns[currentPattern][0] + "=
.");<BR>
if (onceClip =3D=3D null) {<BR>
&n=
bsp; showStatus("Sound " + p.patterns[currentPattern][0=
] + " not loaded yet.");<BR>
}<BR>
return;<=
BR>
}<BR>
currentSound =3D=
onceClip;<BR>
<BR>
if( event.getS=
ource() =3D=3D go)<BR>
currentS=
ound.loop();<BR>
<BR>
else if( event.getSource() =3D=3D ha=
lt) <BR>
currentS=
ound.stop();<BR>
<BR>
<BR>
//action for second icon<BR>
<BR>
Object source1 =3D event.getSource=
();<BR>
if(source1 =3D=3D temp1){<BR>
twiceCli=
p=3D soundList.getClip(p.patterns[currentPattern][1]);<BR>
twiceCli=
p.play();<BR>
//=
clipsPlaying[1] =3D true;<BR>
<BR>
showStat=
us("Playing sound " + p.patterns[currentPattern][1] + "."=
;);<BR>
if (twiceClip =3D=3D nul=
l) {<BR>
showStat=
us("Sound " + p.patterns[currentPattern][1] + " not loaded ye=
t.");<BR>
}<BR>
return;<BR>
}<BR>
<BR>
currentSound =3D twiceClip;<BR>
if( event.getS=
ource() =3D=3D go)<BR>
currentS=
ound.loop();<BR>
<BR>
else if( event.getSource() =3D=3D ha=
lt) <BR>
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=
> 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--
- Prev by Date: [Advanced-java] fetch url problem
- Next by Date: [Advanced-java] improving performance of recursive algorithm
- Previous by thread: [Advanced-java] fetch url problem
- Next by thread: [Advanced-java] Basic RMI question
- Index(es):