This week's book giveaway is in the Open Source Projects forum.
We're giving away four copies of Spark in Action and have Jean-Georges Perrin on-line!
See this thread for details.
Win a copy of Spark in Action this week in the Open Source Projects forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Why does this Swing (JApplet ) mp3 audio applet not compile!

 
Ranch Hand
Posts: 246
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why does this Swing mp3 audio applet not compile!
// 2 songs hell on high heels
// and two timer live
www.motley.com
both mp3's free and legal to download at the official band's
site!
// 43 has a problem!!!
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class PlayAudioMP3 extends JApplet {
private AudioClip sound1, sound2, currentSound;
private JButton playSound, loopSound, stopSound;
private JComboBox chooseSound;
public void init()
{
Container c = getContentPane();
c.setLayout ( new FlowLayout() );
String choices[] = { " HellOnHighHeels.mp3" , " Two-Timer-Live.mp3"};
chooseSound = new JComboBox ( choices );
//43?
chooseSound.addItemListener {
new ItemListener() {
public void itemStateChanged (ItemEvent e )
{
currentSound.stop();
currentSound = chooseSound.getSelectedIndex() == 0 ?
sound1 : sound2;
}
}
};
c.add( chooseSound );
ButtonHandler handler = new ButtonHandler();
playSound = new JButton ("Play");
playSound.addActionListener( handler);
c.add( playSound);
loopSound = new JButton ( " Loop ");
loopSound.addActionListener( handler);
c.add( loopSound );
stopSound = new JButton (" Stop " );
stopSound.addActionListener( handler);
c.add( stopSound );
sound1 = getAudioClip (
getDocumentBase(), " HellOnHighHeels.mp3" );

sound2 = getAudioClip (
getDocumentBase(), " Two-Timer-Live.mp3 ");
currentSound = sound1;
}

public void stop()
{
currentSound.stop();
}
private class ButtonHandler implements ActionListener {
public void actionPerformed ( ActionEvent e)

{
if ( e.getSource() == playSound )
currentSound.play();
else if ( e.getSource()== loopSound )
currentSound.loop();
else if ( e.getSource()== stopSound)
currentSound.stop();
}
}
}
<html>
<applet code ="PlayAudioMP3.class" width = 350 height =60>
</applet>
</html>

 
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Erich,
There was just a minor syntax problem at 43.
Change this:

to this:

and it will compile fine.
Stephanie
 
erich brant
Ranch Hand
Posts: 246
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your an applet wizard! thanks
also you can use/do anything you want with my applets.
they are free to use by anyone!
 
erich brant
Ranch Hand
Posts: 246
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am downloading java media api and am going to see if that
works with having the applet play mp3s with an update in some
extra coding.
the applet does not work ( it compiles and loads but does not run
so i guess i need java media api for mp3/mpeg support.
also anyone can use the applet and do anything they want with it.
just put my url on your page and in the source.
www.firewallfortress.com ( in dec 2000 )
 
Hot dog! An advertiser loves us THIS much:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic