Example of using native JS to enable synchronous playback of the lyrics of the webpage mobile music player: js music player

Source: Internet
Author: User

Example of using native JS to enable synchronous playback of the lyrics of the webpage mobile music player: js music player

I 've written a few times before, and I 've lost every four times. Today, I spent half a day taking a look at my ideas and sorting out my clues.

// Obtain the text var txt = document. getElementById ("lrc"); var lrc = txt. value; // obtain the value in the text field/* console. log (lrc); */var lrcArr = lrc. split ("["); // remove [/* console. log (lrcArr); */var html = ""; // defines an empty variable to save the text for (var I = 0; I <lrcArr. length; I ++) {var arr = lrcArr [I]. split ("]");/* console. log (arr [1]); */var allTime = arr [0]. split (". "); var time = allTime [0]. split (":"); // get the minute second to convert the time to the second var timer = time [0] * 60 + tim E [1] * 1; var text = arr [1]; if (text) {html + = "<p id =" + timer + ">" + text + "</p>"} con. innerHTML = html <pre class = "html" name = "code" >}</pre> <div> </div> <div> implement lyrics the first thing to do is to get the text box and then combine it with the new properties in H5! </Div> <pre class = "html" name = "code"> // listen to the music broadcasting progress to synchronize the lyrics to myMusic. addEventListener ("timeupdate", function () {// obtain the current playback time var curTime = parseInt (this. currentTime); if (document. getElementById (curTime) {for (var I = 0; I <oP. length; I ++) {oP[ I ].style.css Text = "color: # ccc; font-size: 12px;" ;}document.getelementbyid(curtime=.style.css Text = "color: rgb (242,110,111); font-size: 18px; "; if (oP [num + 7]. id = curTime) // num ++ {con. style. top =-20 * num + "px"; num ++ ;}}); </pre> </div> <pre> </pre>

The above example of using native JS to implement synchronous playback of the lyrics of the webpage mobile music player is all the content shared by Alibaba Cloud xiaobian. I hope you can give us a reference and support the help house.

Related Article

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.