Making audio players in the home page

Source: Internet
Author: User
Although both Netscape and IE support the playback of audio files, there is a problem in the production process: if you play it in a hidden way, the user without the sound card will make an error, affecting the overall effect of the home page. It is a good idea to make an audio player that is convenient for user control and can play a role in decorating the page. The following is a detailed description of how to use JavaScript to customize audio players.

1. Netscape's audio player

1) Directly Open

Netscape supports. Mid,. wav, and. Au audio file format, you can open the above file directly in the browser, open the following picture of the player window and play it once, continue playing can click the Play button.

2) Program Call

In the home page file, you can embed the following audio console named Mysound to enable automatic looping of audio files in hidden mode:

〈embed src=″jn.mid″//Source file name

hidden=″true″//Hidden Way

autostart=″true″//Auto Play

loop=″true″//Loop Playback

name=″mysound″//embedded object Name

〈/embed〉

2. JavaScript's audio support function

With JavaScript's audio support function, you can control any audio console embedded in the home page. JavaScript provides the following support functions:

Play ({loop[true,falseoranint]},′{url-to-sound}′)/played

Pause ()/Pause

Stop ()//stops playing the current file

StopAll ()//stop playing all files

Start-time ({numberofseconds})

Starting from the first few seconds

End-time ({numberofseconds})

To the end of the first few seconds

Setvol ({percentagenumber-without″%″sign})

Volume percent control

Fade-to ({volumepercentyouwishtofadeto-withoutthe″%″sign})//Cut volume to

Fade-from-to ({Volumepercentstartfade},{volumepercentendfade})

Cut from a volume value to a volume value

Start-at-beginning ()//start from file header

Stop-at-end ()//To end of file stop

The following four are state test functions

IsReady ()//Ready status test

IsPlaying ()//playback status test

Ispaused ()/Pause State test

Getvolume ()//Get current volume value

3. Application examples

The following is an example of all five elements of a Netscape audio player. Given that some users do not have a sound card, AutoPlay is not set in this example. Readers can add individual elements and test functions to the graphics buttons by combining mouse events with their preferences. The list of procedures is as follows:

〈html〉

〈head〉

〈title〉 Audio Player 〈/title〉

〈scriptlanguage=javascript〉

〈!--writer:yuhaihe

Functionplaysound () {

Document.firstSound.play (TRUE);

}

Functionpausesound () {

Document.firstSound.pause ();

}

Functionstopsound () {

Document.firstSound.stop ();

}

Functionvolup () {

Currentvolume=document.firstsound.getvolume ();

Newvolume= (CURRENTVOLUME+10);

if (Document.firstSound.GetVolume () ==100) {

Alert (″ volume has reached its maximum value ″);

}

if (newvolume〈101) {

Document.firstSound.setvol (Newvolume);}

Else

{

if ((newvolume〈=100) && (newvolume〉90)) {

Document.firstSound.setvol (100);

} }

}

Functionvoldown () {

Currentvolume=document.firstsound.getvolume ();

Newvolume= (CURRENTVOLUME-10);

if (Document.firstSound.GetVolume () ==0) {

Alert (″ volume has reached the minimum ″);

}

if (newvolume〉0) {

Document.firstSound.setvol (Newvolume);}

else {

if ((newvolume〉=0) && (newvolume〈10)) {document.firstSound.setvol (0);}}}

endofjavascriptcode--〉

〈/script〉〈/head〉

〈body〉

〈embed Src=″jn. Mid″hidden=true

Autostart=″false″loop=″true″

name=″firstsound″mastersound〉

〈p〉〈ahref=″javascript:playsound () ″〉 play 〈/a〉〈/p〉

〈p〉〈ahref=″javascript:pausesound () ″〉 paused 〈/a〉〈/p〉

〈p〉〈ahref=″javascript:stopsound () ″〉 stop 〈/a〉〈/p〉

〈p〉〈ahref=″javascript:volup () ″〉 volume +〈/a〉〈/p〉

〈p〉〈ahref=″javascript:voldown () ″〉 volume-〈/a〉〈/p〉

〈/body〉〈/html〉


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.