Html5, audio, and html5 music players

Source: Internet
Author: User

Html5, audio, and html5 music players

Finally, I did what I had always wanted to achieve. The result was that once something was done, it was not very difficult. Now I am listening to my player's "glorious years" to write this blog post on Saturday morning. I am not writing very well, but I also ask my predecessors to take care of this cainiao that I don't know. I also hope that my predecessors will actively correct my mistakes. I am very grateful to my younger brother!

Before the formal content, you can first preview the effect, http://xxyy.ahthw.com/myMusic/MyMusic.html (here, thank you again Wang brother provided server !)

This project mainly uses the html5 audio tag and its built-in methods and attributes, which are compatible with IE9 + browsers.

For APIs related to audio, see: http://www.w3school.com.cn/tags/html_ref_audio_video_dom.asp

It is worth mentioning that, in the project, we encountered such a problem. According to normal thinking, the playing process of a music is as follows:

Click the event to change the src of audio, reload the music, and audio. load (), and then play the music audio. play (), and then get the total length of music, audio. duration, but the general design of the time obtained at this time is NaN. This problem has plagued me for a long time. I think it is possible to analyze the cause of the problem. When the Browser executes audio. when playing (), the music may have not been loaded and audio has been executed. duration, so the obtained time value is always NaN. Thanks again for the solution provided by brother without marks. By listening to whether this song has been played (canplay), get time, related Api, http://www.w3school.com.cn/tags/av_event_canplay.asp

Solution code:

MusicPlayer. addEventListener ('canplay', function (e) {$ AllTime. text (makeTime (MusicPlayer. duration); // makeTime is the function that processes seconds into the format of AllTime = MusicPlayer. duration;}, false );
In fact, this problem is caused by my first writing, less experience, and not carefully looking at the Api. I hope that cainiao like me will not make the same mistakes as me.

In the overall effect, a virtual scroll bar is added based on the height of the content and the height of the container. For details about the scroll bar code, refer to the previous blog:

Http://blog.csdn.net/u014703834/article/details/44159921

The specific project code is not here. If you are interested, you can add QQ: 756500909 or leave an email address online. I will share the source file with you. Hope you can share your skills and experience together!

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.