# Java project



## trublu (Jul 29, 2008)

I was thinking of making a multimedia player as a part of my Java project.It wud b a basic one,other features wud b added as i learn more.So,the question is,can it b done using Java only? Or do i need to study ne thing else?Pls suggest some useful resources too.


----------



## chandru.in (Jul 29, 2008)

Java alone is more than enough.  You need to use JMF (Java Media Framework) for this.


----------



## prasath_digit (Jul 30, 2008)

Or check this out, this is source code for a bare-bone command-line Java mp3 player:- 

*www.javalobby.org/java/forums/t18465.html

I've modified the Command-line player with a JFrame window :-


```
import java.io.FileInputStream;
import java.io.IOException;
import javax.sound.sampled.*;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.Thread;

import Limit.*;
 
public class Jmp3 extends JFrame implements ActionListener
{    

    JButton open,close;
    JFileChooser jfc;      

    Jmp3()
    {
       super("Java MP3 Player");
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       setLayout(new FlowLayout());
       setSize(400,300);
       setVisible(true);
       close = new JButton("Close");
       open = new JButton("Open");
       close.addActionListener(this);
       open.addActionListener(this);
       this.add(close);
       this.add(open);
  
       jfc = new JFileChooser();
       jfc.addChoosableFileFilter(new ImageFilter());       
    }

    public void actionPerformed(ActionEvent ae)
    {
       if(ae.getActionCommand() == "Close")
            System.exit(0);
       if(ae.getActionCommand() == "Open")
            play();
            
    }

    public void play()
    {
        if(jfc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
        {
    AudioInputStream din = null;      
    try 
        {              
        FileInputStream file = new FileInputStream(jfc.getSelectedFile());
        AudioInputStream in = AudioSystem.getAudioInputStream(file);
        AudioFormat baseFormat = in.getFormat();
        AudioFormat decodedFormat = new AudioFormat(
                                        AudioFormat.Encoding.PCM_SIGNED,
                    baseFormat.getSampleRate(), 16, baseFormat.getChannels(),
                    baseFormat.getChannels() * 2, baseFormat.getSampleRate(),
                    false);
        din = AudioSystem.getAudioInputStream(decodedFormat, in);
        DataLine.Info info = new DataLine.Info(SourceDataLine.class, decodedFormat);
        SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info);
        if(line != null) 
                {
            line.open(decodedFormat);
            byte[] data = new byte[4096];

            // Start

            line.start();
                
            int nBytesRead;

            while ((nBytesRead = din.read(data, 0, data.length)) != -1) 
                        {    
                line.write(data, 0, nBytesRead);
            }
                }
            
    }
    catch(Exception e) 
        {
        e.printStackTrace();
    }
    finally 
        {
        if(din != null) 
                {
            try 
                        { 
                                din.close(); 
                        }
                        catch(IOException e) 
                        {
                                // Nothing here
                        }
        }
    }
        }
    }

    public static void main(String[] args) 
    {
        new Jmp3();
    }
}
```


```
package Limit;

import java.io.File;
import javax.swing.*;
import javax.swing.filechooser.*;

public class ImageFilter extends FileFilter 
{
    public boolean accept(File f) 
    {
        String extension = Utils.getExtension(f);
        if (extension != null) 
        {
            if (extension.equals(Utils.bpt))
            {
                    return true;
            } 
            else 
            {
                return false;
            }
        }
        return false;
    }

    public String getDescription() 
    {
        return "MP3 Audio File (.mp3)";
    }
}

class Utils 
{
    public final static String bpt = "mp3";

    public static String getExtension(File f) 
    {
        String ext = null;
        String s = f.getName();
        int i = s.lastIndexOf('.');

        if (i > 0 &&  i < s.length() - 1)         
            ext = s.substring(i+1).toLowerCase();        

        return ext;
    }
}
```


----------



## trublu (Jul 30, 2008)

Thankx both of you.
@prasath_amd,thanx for the code.but i prefer to do it myself.

how do i add codec support?


----------



## prasath_digit (Jul 30, 2008)

trublu said:


> @prasath_amd,thanx for the code.but i prefer to do it myself.



I gave it only to give u some basic idea tats all.......



trublu said:


> how do i add codec support?



don know abt tat.....but i think JMF should do it.......

*JMF:-*

*java.sun.com/javase/technologies/desktop/media/jmf/index.jsp

*This may be useful for u:-*

*www.javaranch.com/


----------



## trublu (Jul 31, 2008)

prasath_amd said:


> I gave it only to give u some basic idea tats all.......



I really appreciate your help.I just said dat i wanna do it myself.


----------



## Plasma_Snake (Aug 2, 2008)

Sorry for budging in but I too have to give a Minor Project after my vacations. I know Core JAVA only and was thinking about making a Torrent Client. Is it possible to make one with my limited knowledge of the subject? Where can i get its exemplary Source Code?


----------



## bukaida (Aug 9, 2008)

Search here:-

*java.codeproject.com/

BTW You must know how to write the project report too. It should follow a specified format.


----------



## shwetz (Aug 9, 2008)

i also need to make a java project...i knw basic java programming till applets..i also want to giv it a interface....


----------



## QwertyManiac (Aug 10, 2008)

Learn AWT and then Swing for that.


----------



## mahender_joshi (Sep 21, 2008)

i need hrlp for search engine project on JAVA,,i m begnner for this,,,plzzzzzz


----------

