Audio files three repeat playback function

Source: Internet
Author: User
Tags prefetch

1. Implement with Applet: (simplest method)

Java code AudioClip player = applet.newaudioclip (URL); AudioClip Introduction: The AudioClip interface is a simple abstraction for playing audio clips.                Multiple AudioClip items can be played at the same time and the resulting sound is mixed together to produce a synthetic sound. Repeat: Player.loop ();/a sentence is done.

AudioClip player = applet.newaudioclip (URL);
    
 AudioClip Introduction:
 The AudioClip interface is a simple abstraction for playing audio clips. Multiple AudioClip items can be played at the same time and
         the resulting sound is mixed together to produce a synthetic sound.
         
 repeat: Player.loop ();/a sentence is done.



2. Through the JDK with the audio implementation

Java code sun.audio.audioplayer;//player sun.audio.audiostream;//audio stream do {inputstream = Url.openstream () //Get the input stream of the music file Audiostream as = new Audiostream (IS);//create the audio stream AudioPlayer.player.start (as);/start playing while loop &&as.available () > 0);//If you want to implement a repeat, you must stop here, or you will always have the beginning, because you have been reading repeatedly} while (loop);

sun.audio.audioplayer;//player
sun.audio.audiostream;//audio stream do
   
 {
  InputStream = Url.openstream ();// Get the input stream for the music file
  audiostream as = new Audiostream (IS);//create the audio stream
  AudioPlayer.player.start (as);/start the While
  loop &&as.available () > 0);//If you want to implement a repeat, you must stop here, or you will always have the beginning, because you have been reading repeatedly
 } while (loop);    

3. Implemented through JMF

  Java code     Player player = manager.createplayer (URL);//Create Player Object    Player.addcontrollerlistener (New controllerlistener ()  {//plus the corresponding control listener      @Override      public void controllerupdate (controllerevent e)  {     //  todo auto-generated method stub      if  (e instanceof  Endofmediaevent)  {//if played to the end of the audio file, start playback again       player.setmediatime (new time (0) );       player.start ();         }      if  (e instanceof  Prefetchcompleteevent)  {//prefetch refers to a state of the player       player.start ();     &NBSP}     }   });        player.prefetch ()//This is used to trigger the second time the above listener corresponds to start playing audio file  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.