Projects

Computer science project

You are not Member of this Project.
Project Owner : KMSARASWATHI
Created Date : Sun, 23/01/2011 - 11:48
Project Description :

An applet is created. An applet will show three buttons-play, loop and stop.
• Whenever user clicks on play button an audio file with .wav
extension starts playing.
• Whenever user clicks on loop button, same audio file will be played
again and again.
• User can click on stop button to stop the audio file.

import java.io.*;
import java.sql.*;
import javax.swing.*;
import javax.media.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
public class Audio extends JFrame implements ActionListener
{
Player player;
Component center;
Component south;
File f;
JButton jb1,jb2,jb3;
Container c;
public static void main(String[] args)
{
Audio vi=new Audio ();
}
Audio ()
{
jb1 = new JButton("Play");
jb2 = new JButton("Loop");
jb3 = new JButton("Stop");
c = getContentPane();
c.setLayout(new FlowLayout());
c.add(jb1);
c.add(jb2);
c.add(jb3);
jb1.addActionListener(this);
jb2.addActionListener(this);
jb3.addActionListener(this);
setSize(300,300);
try
{
f =new File("D:/Devendra/Pracs/Multimedia/2.mp3");
try
{
load(f);
}
catch (Exception e)
{
System.out.println(e);
}
pack();
setVisible(true);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void load(final File file) throws Exception
{
URL url = file.toURL();
if (player != null)
{
player.stop();
}
player = Manager.createPlayer(url);
ControllerListener listener = new ControllerAdapter()
{
public void realizeComplete(RealizeCompleteEvent event)
{
Component vc = player.getVisualComponent();
if (vc != null)
{
c.add(vc,BorderLayout.CENTER);
center = vc;
}
else
{
if (center != null)
{
c.remove(center);
c.validate();
}
}
Component cpc = player.getControlPanelComponent();
if (cpc != null)
{
c.add(cpc,BorderLayout.SOUTH);
south = cpc;
}
else
{
if (south != null)
{
c.remove(south);
c.validate();
}
}
pack();
setTitle(file.getName());
}
};
player.addControllerListener(listener);
}

public void actionPerformed(ActionEvent ae)
{
if (ae.getSource() == jb1)
{
player.start();
}
if (ae.getSource() == jb2)
{
player.stop();
player.start();
}
if (ae.getSource() == jb3)
{
player.stop();
}
}
}
You are not authorized to access this content.
You are not authorized to access this content.
You are not authorized to access this content.
You are not authorized to access this content.
You are not authorized to access this content.