Ao tentar reproduzir pela primeira vez o arquivo lança um nullPointerEx
é preciso reiniciar o programa para reproduzir o arquivo texto em negrito
Método que reproduz o áudio copiado
public synchronized void retornaMus(String path) {
while (ok == false) {
try {
System.out.println("O contador ainda não pode ser usado!!!");
wait();
} catch (InterruptedException ex) {
Logger.getLogger(ArqManager.class.getName()).log(Level.SEVERE, null, ex);
}
}
File ret = new File("src/lf/arq/musicas/" + path);
if (ret.exists()) {
final AudioClip ac = new AudioClip(getClass().getResource("musicas/" + ret.getName()).toString());
ac.play();
} else {
System.out.println("Nao");
}
ok = false;
notifyAll();
}
Método que copia o arquivo
private void copy(File origem, File destino) throws IOException {
Date date = new Date();
OutputStream out;
try (InputStream in = new FileInputStream(origem)) {
out = new FileOutputStream(destino);
byte[] buffer = new byte[1024];
int lenght;
while ((lenght = in.read(buffer)) > 0) {
out.write(buffer, 0, lenght);
}
}
out.close();
Long time = new Date().getTime() - date.getTime();
System.out.println("Copiado com sucesso!!!" + time);
}
Método que seleciona o arquivo
public synchronized void upload(ListView lv, String pasta) {
while (ok) {
try {
wait();
} catch (InterruptedException ex) {
Logger.getLogger(ArqManager.class.getName()).log(Level.SEVERE, null, ex);
}
}
Platform.runLater(new Runnable() {
@Override
public void run() {
FileChooser chooser = new FileChooser();
chooser.setInitialDirectory(PADRAO);
chooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Audio", "*mp3"));
File selected = chooser.showOpenDialog(new Stage());
System.out.println("Bombom Anonimo: " + selected.getPath());
File destino = new File("src/lf/arq/" + pasta + selected.getName());
Date date = new Date();
try {
copy(selected, destino);
listDir(lv, new File("src/lf/arq/musicas"));
} catch (IOException ex) {
Logger.getLogger(ArqManager.class.getName()).log(Level.SEVERE, null, ex);
}
Long time = new Date().getTime() - date.getTime();
System.out.println("Copiado com sucesso!!!" + time);
ok = true;
if (ok == true) {
System.out.println("OK");
}
}
});
notifyAll();
}
Classe que chama o método de reprodução
public class Radio implements Runnable{
public ArqManager am;
public String path;
public Radio(ArqManager manager, String path){
this.am = manager;
this.path = path;
}
public void tocar(String path){
am.retornaMus(path);
}
@Override
public void run() {
tocar(path);
}
}