Wednesday, February 13, 2013

Add music to your website by HTML5

By on 1:15 AM


Ago to add music to your blog you will have to use a 3rd party plugin support HTML5 flash but when the birth was help for webmasters and content management a much lighter burden. However right now it has become much simpler that you can add music directly on your website with just one card<audio>

HTML5's <audio> card now supports the latest browsers are listed here

However, as a webmaster you need to anticipate some cases may occur as your browser does not support HTML5 (her mentioning this extremely annoyed with these guys IE - stupid beyond description - sr you) . So this article I will guide negate the state plan does not support HTML5 in some older browsers.

1. Simple syntax

Its syntax is very simple, you just insert card <audio> with few parameters is done. The most basic you just need to insert:
<audio src=audio.mp3" controls />
Attribute display controls help a slider control on the browser. It should be noted that this slider will be different on different browsers. As follows

2. Advanced properties

However, in order to completely control cards <audio> , I have to learn a number of important attributes.
scr
It specifies the audio file is played. This property may be familiar with him I would meet the most is when inserting images into posts such <img> tag has this attribute.
controls
As in the example above, this attribute that shows a slider control.
autoplay
This attribute will be automatically tracks a bit as soon as the page loads. Attention offline, brothers very hydrophobic case. There are many sites do not bother to read because disturb others with the background music. If used, they must be sure how readers can turn off the sound quickly.
loop
Loop. When playing music, browsers will automatically play back the track from the beginning all over again. It is an infinity loop infinity loop.
preload {auto | metadata | none}
Preload attribute specifies whether or not to download music files. It only FF, Chrome and Safari support.
  • auto = files will be automatically downloaded.
  • metadata = metadata file only loaded when the page loads (not quite!).
  • none = audio file is downloaded when readers disagree.
View an example to better understand these properties.
<audio src="audio.mp3" controls preload="none" />

3. Support for older browsers

HTML5 is the new and only some versions of the new browser support it, for the browser version older people still have to rely on third-party plugins flash-based activities such as jw player. So how to both use HTML5 to use flash? HTML5 has anticipated this and its solution incredibly simple.
First, we can notice a line of text to the reader to know that their browser does not support HTML5 should not hear the music.
<audio src="audio.mp3" controls>
    <p> Your browser does not support native audio. To listen, please <a href="audio.mp3"> download </ a> the mp3 file to your computer. </ P>
</ Audio>
The browser will automatically skip the audio card and read the entire text between cards <p> . This text can be arbitrary long long it must be between <p> card and card <p> must be between<audio>
But such is not the solution. The solution is the music file to be played on all browsers. And this is the great code.
<audio src="audio.mp3" controls>
   <object data="mediaplayer.swf?audio=audio.mp3">
          <param name="movie" value="mediaplayer.swf?audio=audio.mp3">
        <p> Your browser does not support native audio or Flash. To listen, please <a href="audio.mp3"> download </ a> the mp3 file to your computer. </ P>
    </ Object>
</ Audio>
Card <audio> of HTML5 also allows us to insert into the middle of it an object and so we relaxed by adding the plugin to the music. In case the plugin does not work, there is still text between <p>card

4. Limit Break!

But today's mobile world as more and more products like the iPhone, iPad, smartphone. Tablet web browsing capabilities make stars to the browsers on these devices can also play music?
The code decoders of different browsers led to the kind of file that the browser understands the other browsers do not understand the "tissue" anything. If you want all the browsers on mobile devices are out, you must use the following code.
<audio controls>
   <source src="audio.ogg">
   <source src="audio.mp3">
   <object data="mediaplayer.swf?audio=audio.mp3">
          <param name="movie" value="mediaplayer.swf?audio=audio.mp3">
        <p> Your browser does not support native audio or Flash. To listen, please <a href="audio.mp3"> download </ a> the mp3 file to your computer. </ P>
    </ Object>
</ Audio>
This code works as follows: The browser supports HTML5 will read card <audio> it that to play a music file, but the files? It will start and will play the first file that it understands the file if it does not understand at all, it starts read came <object> and music based on the plugin. If you do not understand any more, it had a line of text between <p> card
With HTML5 now to add music to website easy backstroke, is like inserting an image. HTML5 has revolutionized our help webmasters more "breathable" and great user experience. No doubt HTML5 is the standard of modern web design.

0 comments:

Post a Comment