Use HTML5 to create a beautiful webpage music player

Source: Internet
Author: User

Aplayer is a very beautiful HTML5 audio player, it will audio tag encapsulation, and the combination of CSS to create a beautiful player UI, it supports the setting of song name, singers and lyrics, you can set whether AutoPlay, support thumbnails, support playback progress and set the playback source.


Html

The first is to load the player style file, this player style resembles NetEase cloud music player. Then add the player div#player1 to the body and call playback later. Then load the Aplayer.js file.

<link rel= "stylesheet" href= "APlayer.min.css" >
<div id= "Player1" class= "Aplayer" ></div>
<script src= "APlayer.min.js" ></script>
Javascript

Now let's call Aplayer, start with a new object, bind the Player element, set various options, and finally use Ap.init (), and load the player. Note that Aplayer does not rely on Third-party JS libraries such as jquery or Zepto, which encapsulates the audio tags in HTML5, so developers can present beautiful music players on the page with just a few simple lines of code.

var ap = new Aplayer ({
Element:document.getElementById (' Player1 '),
Narrow:false,
Autoplay:true,
Showlrc:false,
Music: {
Title: ' Preparation ',
Author: ' Hans zimmer/richard Harvey ',
URL: ' Http://7xifn9.com1.z0.glb.clouddn.com/Preparation.mp3 ',
Pic: ' Http://7xifn9.com1.z0.glb.clouddn.com/Preparation.jpg '
}
});
Ap.init ();

Options description

Element: A bound player element.
Narrow: Whether to use narrow screen mode, that is, to show only thumbnails and play buttons, see Style 3 in demo demo.
AutoPlay: Whether to play automatically, note that this does not support AutoPlay on the mobile phone.
SHOWLRC: Do you want to show the lyrics, see Style 1 in demo demo.
Music: Used to set up a collection of music-related information, in which title denotes the music title, author the author of the music, the URL represents the address of the playback file, and pic is, of course, the music thumbnail that is played. The
Aplayer also provides player events, such as loading the player: Ap.init (); Playback: Ap.play () and pause: Ap.pause ().

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.