/** Runs the thread. */ public void run() { try { music.play(); } catch (Exception e) { e.printStackTrace(); } }
public static void playSound(String filename) { try { FileInputStream fis = new FileInputStream("sounds/" + filename); try { Player p = new Player(fis); p.play(); } catch (JavaLayerException e) { } } catch (FileNotFoundException e) { } }
// ShoutcastStreamer(String urlAsString) { // try { // URL url = new URL(urlAsString); // URLConnection uc = url.openConnection(); // uc.addRequestProperty("Icy-MetaData", "1"); // // //get all headers // Map<String, List<String>> map = uc.getHeaderFields(); // for (Map.Entry<String, List<String>> entry : map.entrySet()) { // System.out.println("Key : " + entry.getKey() // + " ,Value : " + entry.getValue()); // } // // System.out.println(map.size()); // //metaint = Integer.parseInt(uc.getHeaderField("icy-metaint")); // metaint = 32768; // System.out.println(metaint); // // InputStream in = uc.getInputStream(); // byte[] buffer = new byte[metaint]; // for (int i = 0; i < buffer.length; i++) { // buffer[i] = (byte) in.read(); // } // int metaLength = in.read() * 16; // String metaData = new String(); // for (int i = 0; i < metaLength; i++) { // metaData = metaData.concat(String.valueOf((char) in.read())); // } // System.out.println(metaData); // // } catch (IOException ex) { // Logger.getLogger(ShoutcastStreamer.class.getName()).log(Level.SEVERE, null, ex); // } // } private void playInputStream(InputStream stream) { try { if (player != null) { player.close(); } player = new Player(stream); player.play(); } catch (Exception ex) { Logger.getLogger(ShoutcastPlayer.class.getName()).log(Level.SEVERE, null, ex); } }
private static void playSoundRunnable(final String name) { try { String song = "sounds/" + name + ".mp3"; FileInputStream input = new FileInputStream(song); BufferedInputStream bufferedInput = new BufferedInputStream(input); player = new Player(bufferedInput); player.play(); } catch (Exception e) { e.printStackTrace(); } }
/** Starts the background music */ private void playMe() { try { File file = new File(Resource.SOUND_BACKGROUDN); FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); player = new Player(bis); player.play(); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } }