public void player_begin(URL url) { if (h4JmfPlugin.playMP3 != null) { logger.severe("playMP3!=null"); h4JmfPlugin.cnsl.append("playMP3!=null"); return; } if (url == null) { h4JmfPlugin.cnsl.append("url==null"); return; } MediaLocator mediaLocator = new MediaLocator(url); try { // final JPanel jpnl_this=this; DataSource ds = Manager.createDataSource(mediaLocator); // cnsl.append("ds="+ds); h4JmfPlugin.playMP3 = Manager.createPlayer(ds); /** * ********************************************************** ControllerListener moved to * outer class addControllerListener done in h4JmfPlugin ********************************** */ h4JmfPlugin.player_begin(); } catch (Exception e) { logger.severe(e.getMessage()); h4JmfPlugin.cnsl.append(e); return; } // h4JmfPlugin.playMP3.realize(); // logger.info("after realize()"); // but possible [JMF thread: com.sun.media.PlaybackEngine@1ac13d7[ // com.sun.media.PlaybackEngine@1ac13d7 ] ( realizeThread)] [error] PlaybackEngine@1ac13d7 ] ( // realizeThread): Unable to handle format: mpeglayer3, 16000.0 Hz, 16-bit, Mono, // LittleEndian, Signed, 2000.0 frame rate, FrameSize=16384 bits // running tshvr under hedwig :11:17:08 PM [JMF thread: // com.sun.media.content.unknown.Handler@8c7be5 ( prefetchThread)] [error] Handler@8c7be5 ( // prefetchThread): Error: Unable to prefetch com.sun.media.PlaybackEngine@6d3b92 } // player_begin
/** @param args */ public static void main(String[] args) { String url = "rtp://192.168.1.1:22224/audio/16"; MediaLocator mrl = new MediaLocator(url); // Create a player for this rtp session Player player = null; try { player = Manager.createPlayer(mrl); } catch (NoPlayerException e) { e.printStackTrace(); System.exit(-1); } catch (MalformedURLException e) { e.printStackTrace(); System.exit(-1); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } if (player != null) { System.out.println("Player created."); player.realize(); // wait for realizing while (player.getState() != Controller.Realized) { try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } } System.out.println("Starting player"); player.start(); } else { System.err.println("Player doesn't created."); System.exit(-1); } System.out.println("Exiting."); }
public static void main(String args[]) throws Exception { // Take the path of the audio file from command line File f = new File("C:\\Users\\Larry\\AppData\\Local\\Temp\\jgoogle_tts-588881786930740869.mp3"); // Create a Player object that realizes the audio final Player p = Manager.createRealizedPlayer(f.toURI().toURL()); // Start the music p.start(); // Create a Scanner object for taking input from cmd Scanner s = new Scanner(System.in); // Read a line and store it in st String st = s.nextLine(); // If user types 's', stop the audio if (st.equals("s")) { p.stop(); } }
/** * Update handles announcing an event to a group of peers * * @param event the event we are announcing * @param manager the manager * @return arraylist the arraylist of updated peers */ @SuppressWarnings("unchecked") public ArrayList<Peer> update(String event, Manager manager) { this.event = event; this.requestString = createURL(this.announce); HashMap<ByteBuffer, Object> response = null; try { byte[] trackerResponse = sendGETRecieveResponse(); if (trackerResponse == null) { log.severe("Error communicating with tracker"); try { manager.close(); } catch (IOException e) { log.severe("Error closing manager after miscommunication with tracker"); } return null; } response = (HashMap<ByteBuffer, Object>) Bencoder2.decode(trackerResponse); } catch (BencodingException e1) { log.severe("Error decoding tracker response"); try { manager.close(); } catch (IOException e) { log.severe("Error closing manager after miscommunication with tracker"); } return null; } if (response.containsKey(KEY_FAILURE)) { log.severe("Uh-oh. Failure from the tracker!"); try { manager.close(); } catch (IOException e) { log.severe("Error closing manager after miscommunication with tracker"); } return null; } ArrayList<Peer> peers = new ArrayList<Peer>(); this.interval = (Integer) response.get(KEY_INTERVAL); List<Map<ByteBuffer, Object>> peersList = (List<Map<ByteBuffer, Object>>) response.get(KEY_PEERS); // TODO: Check if peersList is null! if (peersList == null) { log.severe("Error: list of peers given by tracker is null"); return null; } for (Map<ByteBuffer, Object> rawPeer : peersList) { int peerPort = ((Integer) rawPeer.get(KEY_PORT)).intValue(); byte[] peerId = ((ByteBuffer) rawPeer.get(KEY_PEERID)).array(); String ip = null; try { ip = new String(((ByteBuffer) rawPeer.get(KEY_IP)).array(), "ASCII"); } catch (UnsupportedEncodingException e) { log.severe("Unable to parse encoding"); continue; } peers.add(new Peer(peerId, peerPort, ip, manager)); } log.fine("Converted: " + (peers)); return peers; }