Olá pessoal…
Estou construindo um pequeno player utilizando a biblioteca chamada JLayer, porém estou com dúvidas para parar (stop) a execução do áudio?
Alguém pode me dar alguma sugestão?
Grata!!!
Olá pessoal…
Estou construindo um pequeno player utilizando a biblioteca chamada JLayer, porém estou com dúvidas para parar (stop) a execução do áudio?
Alguém pode me dar alguma sugestão?
Grata!!!
Bom fiz um player uma vez utilizado essa biblioteca http://www.javazoom.net/mp3spi/sources.html e adicionei o jar jl1.0 que está na pasta lib a classe ficou assim e para parar o mp3 usei o close() como pode ser observado no codigo abaixo
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package br.com.siscontrol.principal;
import br.com.siscontrol.extras.FiltrarArquivo;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javazoom.jl.player.Player;
/**
*
* @author Bruno
*/
public class PLAYER {
private String filename;
static private Player player;
public PLAYER(String filename) {
this.filename = filename;
}
public static void main(String[] args) {
String filename = direitorio(new String[]{"mp3"}, "Somente Arquivos de Audio MP3");
PLAYER mp3 = new PLAYER(filename);
mp3.play();
if (JOptionPane.showConfirmDialog(null, "Deseja parar a musica?", "stop!", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
if (player != null) {
player.close();
}
}
}
private void play() {
try {
FileInputStream fis = new FileInputStream(filename);
BufferedInputStream bis = new BufferedInputStream(fis);
player = new Player(bis);
} catch (Exception e) {
}
// run in new thread to play in background
new Thread() {
public void run() {
try {
player.play();
} catch (Exception e) {
}
}
}.start();
}
private static String direitorio(String extensao[], String descricao) {
String path = "";
JFileChooser fc = new JFileChooser();
// restringe a amostra a diretorios apenas
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
if (!(extensao == null)) {
FiltrarArquivo filter = new FiltrarArquivo(extensao, descricao);
fc.setFileFilter(filter);
}
int res = fc.showOpenDialog(null);
if (res == JFileChooser.APPROVE_OPTION) {
File diretorio = fc.getSelectedFile();
path = diretorio.getAbsolutePath();
} else {
return null;
}
return path;
}
}
Muito Obrigada!!!
Mas, seria possível voce também anexar o código da classe FiltrarArquivo, por favor.
Agradeço!!!
obs. essa classe não é minha!
[code]/*
//file filter from sun!
import java.io.File;
import java.util.Enumeration;
import java.util.Hashtable;
import javax.swing.filechooser.FileFilter;
/**
A convenience implementation of FileFilter that filters out
all files except for those type extensions that it knows about.
Extensions are of the type “.foo”, which is typically found on
Windows and Unix boxes, but not on Macinthosh. Case is ignored.
Example - create a new filter that filerts out all files
but gif and jpg image files:
JFileChooser chooser = new JFileChooser();
ExampleFileFilter filter = new ExampleFileFilter(
new String{"gif", "jpg"}, "JPEG & GIF Images")
chooser.addChoosableFileFilter(filter);
chooser.showOpenDialog(this);
@version 1.12 12/03/01
@author Jeff Dinkins
*/
public class FiltrarArquivo extends FileFilter {
private static String TYPE_UNKNOWN = “Type Unknown”;
private static String HIDDEN_FILE = “Hidden File”;
private Hashtable filters = null;
private String description = null;
private String fullDescription = null;
private boolean useExtensionsInDescription = true;
/**
/**
/**
/**
/**
/**
/**
/**
/**
/**
/**
/**
Muito Obrigada!!! Muito me ajudou!!!
=)