Logo F2FInterview

Applet Interview Questions

Q   |   QA

import java.io.File; import java.io.IOException;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;

public class PlayAudio
{
private static final int EXTERNAL_BUFFER_SIZE = 128000;
public static void main(String[] args)
{
String file1 = args[0];
File file2 = new File(file1);
AudioInputStream ais = null;
try
{
ais = AudioSystem.getAudioInputStream(file2);
}
catch (Exception e)
{
e.printStackTrace();
System.exit(1);
}
AudioFormat af = ais.getFormat();
SourceDataLine sdf = null;
DataLine.Info dli = new DataLine.Info(SourceDataLine.class, af);
try
{
sdf = (SourceDataLine) AudioSystem.getLine(dli);
sdf.open(af);
}
catch (LineUnavailableException e)
{
e.printStackTrace();
System.exit(1);
}
catch (Exception e)
{
e.printStackTrace();
System.exit(1);
}
sdf.start();

int dat = 0;
byte[] data1 = new byte[EXTERNAL_BUFFER_SIZE];
while (dat != -1)
{
try
{
dat = ais.read(data1, 0, data1.length);
}
catch (IOException e)
{
e.printStackTrace();
}
if (dat >= 0)
{
int nBytesWritten = sdf.write(data1, 0, dat);
}
}
sdf.drain();
sdf.close();
System.exit(0);
}
} 

  1. Place the .class file in the directory containing the HTML document into which you want to insert the applet.
  2. Copy the <applet>...</applet> tag from your applet implementation or examples to the clipboard.
  3. In FrontPage select the "HTML" tab from the lower left hand corner.
  4. Paste the <applet>...</applet> tag in an appropriate place between the <body> and </body> tags. You'll find a gray box with the aqua letter "J" in the "Normal" view indicating the the applet tag has been inserted.
  5. To see the applet appearance select the "Preview" tab. 

In order to link this F2FInterview's page as Reference on your website or Blog, click on below text area and pres (CTRL-C) to copy the code in clipboard or right click then copy the following lines after that paste into your website or Blog.

Get Reference Link To This Page: (copy below code by (CTRL-C) and paste into your website or Blog)
HTML Rendering of above code: