Java network programming - from the voice network access

  Java from the network and access to sound files of audio programming method there are two types, the first play using Java (URL) and play (URL, String) Direct broadcast sound files on the network, and the other is through getAudioClip ( URL) or getAudioClip (URL, String) first network access to audio files, and generate AudioClip type of object, and then the object to operate. 

  The former format is the use of: 

  String Audur = "node URL"; 
  Try ( 
  Play (new URL (Audur)); 
  ) Catch (Exception e) () 
  Or 

  String Audur = "node URL"; 
  Try ( 
  Play (new URL (Audur), sound files); 
  ) Catch (Exception e) () 
  The latter use of the format is: 

  String Audur = "node URL"; 
  AudioClip loopClip; 
  Try ( 
  GetAudioClip loopClip = (new URL (Audur)); 
  ) 
  Catch (Exception e) ( 
  System.out.println ( "Can't open the URL"); 
  ) 
  Or 

  String Audur = "node URL"; 
  AudioClip loopClip; 
  Try ( 
  GetAudioClip loopClip = (new URL (Audur), sound files); 
  ) 
  Catch (Exception e) ( 
  System.out.println ( "Can't open the URL"); 
  ) 
  The four are above format will generate some URL object - "new URL (url)" as a direct or getAudioClip play the parameters before and dealt with the case of images, but also could be used "new URL (url)" access a URL object, then pass play or 
  GetAudioClip.    On the first play (URL) format can be applied in the following programming format: 

  URL Audur = null; 
  Try ( 
  Audur = new URL ( "node URL"); 
  ) Catch (Exception e) ( 
  System.out.println ( "Can't open the URL"); 
  ) 
  Play (Audur); 
  Below the aforementioned four from the network to access and audio format of the document cite a simple example, for programming reference: 

  ● procedures for a 4 format 

  Import java.applet .*; 
  Import java.awt .*; 
  Import java.net .*; 
  Public class sound1 extends Applet 
  (AudioClip loopClip; 
  Public void paint (Graphics g) ( 
  String Audur = "http://www.shu.edu.cn/ ~ xyx / java / Animator / audio / bark.au"; 
  Try ( 
  Play (new URL (Audur)); 
  ) Catch (Exception e) () 
  ) 
  ) 
  ● 5 format two procedures 

  Import java.applet .*; 
  Import java.awt .*; 
  Import java.net .*; 
  Public class sound2 extends Applet 
  (AudioClip loopClip; 
  Public void paint (Graphics g) ( 
  String Audur = "http://www.shu.edu.cn/ ~ xyx / java / Animator / audio /"; 
  Try ( 
  Play (new URL (Audur), "bark.au"); 
  ) Catch (Exception e) () 
  ) 
  ) 
  ● procedures format 6 3 

  Import java.applet .*; 
  Import java.awt .*; 
  Import java.net .*; 
  Public class sound extends Applet ( 
  AudioClip loopClip; 
  Public void init () ( 
  String Audur = "http://www.shu.edu.cn/ ~ xyx / java / Animator / audio / bark.au"; 
  Try ( 
  GetAudioClip loopClip = (new URL (Audur)); 
  ) Catch (Exception e) () 
  ) 

  Public void paint (Graphics g) ( 
  LoopClip.loop (); 
  ) 
  ) 
  ● 7 format four procedures 

  Import java.applet .*; 
  Import java.awt .*; 
  Import java.net .*; 
  Public class sound0 extends Applet ( 
  AudioClip loopClip; 
  URL auur; 
  Public void init () ( 
  Try ( 
  Auur = new URL ( "http://www.shu.edu.cn/ ~ xyx / java / Animator / audio /"); 
  ) 
  Catch (MalformedURLException e) ( 
  System.out.println ( "Can't open the URL"); 
  ) 
  LoopClip = getAudioClip (auur, "bark.au"); 
  ) 

  Public void paint (Graphics g) ( 
  LoopClip.loop (); 
  ) 
  ) 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags: , ,

Releated Java Articles

Comments

Leave a Reply