HTML5 achieves lyrics synchronization and html5 lyrics Synchronization

Source: Internet
Author: User

HTML5 achieves lyrics synchronization and html5 lyrics Synchronization
Opening

HTML5 is most powerful in processing media files. For example, you can use a simple vedio tag to play a video. Similarly, there is a corresponding tag for processing audio files in HTML5, that is, the audio tag.

Online Demo

Audio tag

Implementing an audio tag is very simple. The corresponding html code is as follows:

<Audio id = "player" src = "music/I am eating fried chicken in the People's Republic of China" autoplay controls> </audio>

The above code can play music without a line of js scripts. There are three common attributes: audio source file, automatic playback, and player control. Because there is no ui display, the default style of the audio tag in chrome is as follows:

It can be seen that a basic player also includes functions such as displaying the current time, playing, pausing, and fast forward and return. These functions determine how to synchronize the lyrics well (subsequent introduction ).

Since it is so easy to play music, what is the compatibility of the audio tag in various browsers as a front-end technology?
Browser Compatibility

It can be seen that all major browsers support basic functions of the audio tag, but they do not have the same performance in terms of subtle features. However, these basic functions have already made a good player.

Lyrics

Generally, standard lyric files are composed[Time] contentTags, such:

In order to display the time of each word in each lyrics more accurately, there is a special form of lyrics, as shown below:

The best example of this type of lyrics format is the QRC lyrics file (such as the QQ music player ):

To describe the lyrics in a simple way, this article uses the simplest lyric format as an example to explain how to separate the lyrics and synchronize the lyrics. As follows:

Now we will take a look at the lyrics file:

  • 1. Split each lyrics by unit of action
  • 2. Separate the time tag and content of no lyrics
  • 3. Convert the time to minutes

The conversion process is simple and requires a simple regular expression matching. The process is as follows:

The separated [time, content] can be compared with the current audio playback time. To display the corresponding lyrics, highlight the line, at the same time, you can visually scroll through each update of the top of the corresponding DOM node.

Create the ui of the lyrics.
  • 1. Define a region with realistic lyrics and add the audio control

  • 2. Add a background image and create a title border

  • 3. Add lyrics

At this point, the lyrics synchronization and ui painting are complete.

Online Demo

PS: The markdown style of CSDN is too watery. You can see other links below.

Blog sync

Synchronization of simplified books

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.