elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía actualizada para evitar que un ransomware ataque tu empresa


  Mostrar Mensajes
Páginas: [1]
1  Programación / Java / Cómo desarrollar un reproductor de MP3 en Java? en: 28 Noviembre 2007, 05:42 am
Este es el codigo que tengo:

Código
  1. import java.awt.*;
  2. import javax.sound.sampled.*;
  3. import java.io.*;
  4.  
  5. public class mp3m extends java.applet.Applet {
  6.  
  7.    /** Initialization method that will be called after the applet is loaded
  8.      *  into the browser.
  9.      */
  10.    public void init() {
  11.        // TODO start asynchronous download of heavy resources
  12.    }
  13.  
  14.    public void paint(Graphics g) {
  15.  
  16. public void testPlay(String filename)
  17. {
  18.  try {
  19.    File file = new File(filename);
  20.    AudioInputStream in= AudioSystem.getAudioInputStream(file);
  21.    AudioInputStream din = null;
  22.    AudioFormat baseFormat = in.getFormat();
  23.    AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
  24.     baseFormat.getSampleRate(),16,baseFormat.getChannels(), baseFormat.getSampleRate(), false);
  25.    din = AudioSystem.getAudioInputStream(decodedFormat, in);
  26.    // Play now.
  27.    rawplay(decodedFormat, din);
  28.    in.close();
  29.  } catch (Exception e)
  30.    {
  31.        //Handle exception.
  32.    }
  33. }
  34.  
  35. private void rawplay(AudioFormat targetFormat, AudioInputStream din) throws IOException,                                                                                                LineUnavailableException
  36. {
  37.  byte[] data = new byte[4096];
  38.  SourceDataLine line = getLine(targetFormat);
  39.  if (line != null)
  40.  {
  41.    // Start
  42.    line.start();
  43.    int nBytesRead = 0, nBytesWritten = 0;
  44.    while (nBytesRead != -1)
  45.    {
  46.        nBytesRead = din.read(data, 0, data.length);
  47.        if (nBytesRead != -1) nBytesWritten = line.write(data, 0, nBytesRead);
  48.    }
  49.    // Stop
  50.    line.drain();
  51.    line.stop();
  52.    line.close();
  53.    din.close();
  54.  }
  55. }
  56.  
  57. private SourceDataLine getLine(AudioFormat audioFormat) throws LineUnavailableException
  58. {
  59.  SourceDataLine res = null;
  60.  DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
  61.  res = (SourceDataLine) AudioSystem.getLine(info);
  62.  res.open(audioFormat);
  63.  return res;
  64. }
  65.    }
2  Programación / Java / Cómo desarrollar un reproductor de MP3 en Java? en: 27 Noviembre 2007, 22:03 pm
 :D

Qusiera el codigo de como hacer un reproductor de mp3 en jcreator ya que he tenido varios problemas para implementarlo.

Les agradeceria su ayuda.
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines