Tampilkan postingan dengan label HTML Media. Tampilkan semua postingan
Tampilkan postingan dengan label HTML Media. Tampilkan semua postingan

HTML Youtube

HTML - YouTube Videos

The easiest way to play videos (others or your own) in HTML is to use YouTube.

Playing a YouTube Video in HTML

If you want to play a video in a web page, you can upload the video to YouTube and insert the proper HTML code to display the video:

Example - YouTube iFrame

<iframe width="420" height="345"
src="http://www.youtube.com/embed/XGSy3_Czz8k">
</iframe>

Try it yourself »

Example - YouTube Embedded

<embed
width="420" height="345"
src="http://www.youtube.com/v/XGSy3_Czz8k"
type="application/x-shockwave-flash">
</embed>

HTML Video

HTML Videos

Playing Videos in HTML

Example

<video width="320" height="240" controls>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
  <source src="movie.webm" type="video/webm">
  <object data="movie.mp4" width="320" height="240">
    <embed src="movie.swf" width="320" height="240">
  </object>
</video>

Try it yourself »


Problems, Problems, and Solutions

Displaying videos in HTML is not easy!
You must add a lot of tricks to make sure your video will play in all browsers (Internet Explorer, Chrome, Firefox, Safari, Opera) and on all hardware (PC, Mac , iPad, iPhone).
In this chapter W3Schools summarizes the problems and the solutions.

The <embed> Element

The purpose of the <embed> tag is to embed multimedia elements in HTML pages.
The following HTML fragment displays a Flash video embedded in a web page:

Example

<embed src="intro.swf" height="200" width="200">

Try it yourself »
Problems
  • If the browser does not support Flash, the video will not play
  • iPad and iPhone do not support Flash videos
  • If you convert the video to another format, it will still not play in all browsers

Using The <object> Element

The purpose of the <object> tag is to embed multimedia elements in HTML pages.
The following HTML fragment displays a Flash video embedded in a web page:

Example

<object data="intro.swf" height="200" width="200"></object>

Try it yourself »
Problems:
  • If the browser does not support Flash, the video will not play
  • iPad and iPhone do not support Flash videos
  • If you convert the video to another format, it will still not play in all browsers

Using the HTML5 <video> Element

The HTML5 <video> tag defines a video or movie.
The <video> element works in all modern browsers.
The following HTML fragment displays a video in OGG, MP4, or WEBM format:

Example

<video width="320" height="240" controls>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
  <source src="movie.webm" type="video/webm">
Your browser does not support the video tag.
</video>

Try it yourself »
Problems:
  • You must convert your videos to many different formats
  • The <video> element does not work in older browsers

The Best HTML Solution

The example below uses 4 different video formats. The HTML 5 <video> element tries to play the video either in MP4, OGG, or WEBM format. If this fails, the code "falls back" to try the <object> element. If this also fails, it "falls back" to the <embed> element:

HTML 5 + <object> + <embed>

<video width="320" height="240" controls>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
  <source src="movie.webm" type="video/webm">
  <object data="movie.mp4" width="320" height="240">
    <embed src="movie.swf" width="320" height="240">
  </object>
</video>

Try it yourself »
Problems:
  • You must convert your videos to many different formats

The YouTube Solution

The easiest way to display videos in HTML is to use YouTube (see next chapter)!

Using A Hyperlink

If a web page includes a hyperlink to a media file, most browsers will use a "helper application" to play the file.
The following code fragment displays a link to a Flash video. If a user clicks on the link, the browser will launch a helper application to play the file:

Example

<a href="intro.swf">Play a video file</a>

Try it yourself »


A Note About Inline Videos

When a video is included in a web page it is called inline video.
If you plan to use inline videos, be aware that many people find it annoying. Also note that some users might have turned off the inline video option in their browser.
Our best advice is to include inline videos only in pages where the user expects to see a video. An example of this is a page which opens after the user has clicked on a link to see the video.

HTML Multimedia Tags

New : New tags in HTML5.
TagDescription
<embed>Defines an embedded object
<object>Defines an embedded object
<param>Defines a parameter for an object
<audio>NewDefines sound content
<video>NewDefines a video or movie
<source>NewDefines multiple media resources for media elements (<video> and <audio>)
<track>NewDefines text tracks for media elements (<video> and <audio>)

HTML Audio

HTML Audio

Problems, Problems, and Solutions

Playing audio in HTML is not easy!
You must know a lot of tricks to make sure your audio files will play in all browsers (Internet Explorer, Chrome, Firefox, Safari, Opera) and on all hardware (PC, Mac , iPad, iPhone).
In this chapter W3Schools summarizes the problems and the solutions.

Using Plug-ins

A plug-in is a small computer program that extends the standard functionality of the browser.
Plug-ins can be added to HTML pages using the <object> tag or the <embed> tag. 
These tags define containers for resources (normally non-HTML resources), which, depending on the type, will either be displayed by the browsers, or by an external plug-in.

Using The <embed> Element

The <embed> tag defines a container for external (non-HTML) content.
The following code fragment should play an MP3 file embedded in a web page:

Example

<embed height="50" width="100" src="horse.mp3">

Try it yourself »

Problems:

  • Different browsers support different audio formats
  • If a browser does not support the file format, the audio will not play without a plug-in
  • If the plug-in is not installed on the users' computer, the audio will not play
  • If you convert the file to another format, it will still not play in all browsers

Using The <object> Element

The <object tag> tag can also define a container for external (non-HTML) content.
The following code fragment should play an MP3 file embedded in a web page:

Example

<object height="50" width="100" data="horse.mp3"></object>

Try it yourself »

Problems:

  • Different browsers support different audio formats
  • If a browser does not support the file format, the audio will not play without a plug-in
  • If the plug-in is not installed on the users' computer, the audio will not play
  • If you convert the file to another format, it will still not play in all browsers

Using the HTML5 <audio> Element

The HTML5 <audio> tag defines sound, such as music or other audio streams.
The <audio> element works in all modern browsers.
The following example uses the <audio> tag, and specifies one MP3 file (for Internet Explorer, Chrome, and Safari), and one OGG file (for Firefox and Opera). If anything fails it displays a text:

Example

<audio controls>
  <source src="horse.mp3" type="audio/mpeg">
  <source src="horse.ogg" type="audio/ogg">
  Your browser does not support this audio format.
</audio>

Try it yourself »

Problems:

  • You must convert the audio files into different formats
  • The <audio> element does not work in older browsers

The Best HTML Solution

The example below uses the HTML5 <audio> element and tries to play the audio either as MP3 or OGG. If it fails, the code "falls back" to try the <embed> element:

Example

<audio controls height="100" width="100">
  <source src="horse.mp3" type="audio/mpeg">
  <source src="horse.ogg" type="audio/ogg">
  <embed height="50" width="100" src="horse.mp3">
</audio>

Try it yourself »

Problems:

  • You must convert the audio files into different formats
  • The <embed> element cannot "fall-back" to display an error message

Yahoo Media Player - An Easy Way to Add Audio to Your Site

The FREE Yahoo Media Player is definitely a favorite: You simply let Yahoo do the job of playing your songs.
It plays MP3 and a lot of other formats. You can add it to your page (or blog) with a single line of code, and easily turn your HTML page into a professional playlist:

Example

<a href="horse.mp3">Play Sound</a>

<script src="http://mediaplayer.yahoo.com/latest"></script>

Try it yourself »
To use it, insert the following JavaScript at the bottom of your web page:
<script src="http://mediaplayer.yahoo.com/latest"></script>
Then, simply link to your audio files in your HTML, and the JavaScript code automatically creates a play button for each song:

<a href="song1.mp3">Play Song 1</a>
<a href="song2.wav">Play Song 2</a>
...
...
The Yahoo Media Player presents your readers with a small play button instead of a full player. However, when you click the button, a full player pops up. Note that the player is always docked and ready at the bottom of the window. Just click on it to slide it out.

Using A Hyperlink

If a web page includes a hyperlink to a media file, most browsers will use a "helper application" to play the file.
The following code fragment displays a link to an MP3 file. If a user clicks on the link, the browser will launch a helper application to play the file:

Example

<a href="horse.mp3">Play the sound</a>

Try it yourself »


A Note About Inline Sounds

When sound is included in a web page, or as part of a web page, it is called inline sound.
If you plan to use inline sounds, be aware that many people will find it annoying. Also note that some users might have turned off the inline sound option in their browser.
Our best advice is to include inline sounds only in pages where the user expects to hear sounds. An example of this is a page which opens after the user has clicked on a link to hear a recording.

HTML Multimedia Tags

New : New tags in HTML5.
TagDescription
<embed>Defines an embedded object
<object>Defines an embedded object
<param>Defines a parameter for an object
<audio>NewDefines sound content
<video>NewDefines a video or movie
<source>NewDefines multiple media resources for media elements (<video> and <audio>)
<track>NewDefines text tracks for media elements (<video> and <audio>)

HTML Object

HTML - The <object> Element


HTML Helpers (Plug-ins)

A helper application is a small computer program that extends the standard functionality of the browser. Helper applications are also called plug-ins.
Plug-ins are often used by browsers to play audio and video.
Examples of well-known plug-ins are Adobe Flash Player and QuickTime.
Plug-ins can be added to Web pages through the <object> tag or the <embed> tag. 
Most plug-ins allow manual (or programmed) control over settings for volume, rewind, forward, pause, stop, and play.

What is The Best Way to Play Audio/Video in HTML?

For the best way to embed audio or video in your Web page, please read the next chapters.

QuickTime - Play WAV Audio

Example

<object width="420" height="360"
classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
codebase="http://www.apple.com/qtactivex/qtplugin.cab">
<param name="src" value="liar.wav">
<param name="controller" value="true">
</object>

Try it yourself »


QuickTime - Play MP4 Video

Example

<object width="420" height="360"
classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
codebase="http://www.apple.com/qtactivex/qtplugin.cab">
<param name="src" value="movie.mp4">
<param name="controller" value="true">
</object>

Try it yourself »


Adobe Flash Player - Play SWF Video

Example

<object width="400" height="40"
classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://fpdownload.macromedia.com/
pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">
<param name="SRC" value="bookmark.swf">
<embed src="bookmark.swf" width="400" height="40">
</embed>
</object>

Try it yourself »


Windows Media Player - Play WMV Movie

The example below shows the suggested code used to display a Windows Media file.

Example

<object width="100%" height="100%"
type="video/x-ms-asf" url="3d.wmv" data="3d.wmv"
classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">
<param name="url" value="3d.wmv">
<param name="filename" value="3d.wmv">
<param name="autostart" value="1">
<param name="uiMode" value="full">
<param name="autosize" value="1">
<param name="playcount" value="1">
<embed type="application/x-mplayer2" src="3d.wmv" width="100%" height="100%" autostart="true" showcontrols="true" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"></embed>
</object>

Try it yourself »


Plug-ins

Plug-ins can be used for many purposes: to display maps, scan for viruses, verify your bank id, and much more. The restrictions are few.

HTML Media

HTML Multimedia

Multimedia on the web is sound, music, videos, and animations.
Modern web browsers have support for many multimedia formats.

What is Multimedia?

Multimedia comes in many different formats. It can be almost anything you can hear or see.
Examples: Pictures, music, sound, videos, records, films, animations, and more.
Modern Web pages have often embedded multimedia elements, and modern browsers have support for various multimedia formats.
In this tutorial you will learn about different multimedia formats.

Browser Support

The first Internet browsers had support for text only, and even the text support was limited to a single font in a single color. Then came browsers with support for colors, fonts and text styles, and support for pictures was added.
The support for sounds, animations, and videos is handled in different ways by various browsers. Some multimedia elements is supported, and some requires an extra helper program (a plug-in).
You will learn more about plug-ins in the next chapters.

Multimedia Formats

Multimedia elements (like sounds or videos) are stored in media files.
The most common way to discover the type of a file, is to look at the file extension. When a browser sees the file extension .htm or .html, it will treat the file as an HTML file. The .xml extension indicates an XML file, and the .css extension indicates a style sheet file. Pictures are recognized by extensions like .gif, .png and .jpg.
Multimedia files also have their own formats with different extensions like: .swf, .wav, .mp3, and .mp4.

Video Formats

Videoformats        MP4 is the new and upcoming format for internet video. It is supported by YouTube, Flash players and HTML5.
FormatFileDescription
AVI.aviAVI (Audio Video Interleave) was developed by Microsoft. AVI is supported by all computers running Windows, and by the most popular web browsers. It is a very common format on the Internet, but not always possible to play on non-Windows computers
WMV.wmvWMV (Windows Media Video) was developed by Microsoft. WMV is a common format on the Internet, but it cannot be played on non-Windows computer without an extra (free) component installed. Some later WMVs cannot play at all on non-Windows computers because no player is available
MPEG.mpg
.mpeg
The MPEG (Moving Pictures Expert Group) format is the most popular format on the Internet. It is cross-platform, and supported by all major browsers
QuickTime.movQuickTime was developed by Apple. QuickTime is a common format on the Internet, but QuickTime movies cannot be played on a Windows computer without an extra (free) component installed.
RealVideo.rm
.ram
RealVideo was developed by Real Media. RealVideo allows streaming of video (online video, Internet TV) with low bandwidths. Because of the low bandwidth priority, the quality is often reduced
Flash.swf
.flv
Flash was developed by Macromedia. Flash requires an extra component to play. This component comes preinstalled with all major browsers
MP4.mp4Mpeg-4 (MP4) is the new format for the internet. YouTube recommends using MP4. YouTube accepts multiple formats, and then converts them all to .flv or .mp4 for distribution

Sound Formats

MP3 is the newest format for compressed recorded music. The term MP3 has become synonymous with digital music. If your website is about recorded music, the MP3 format is the choice.
FormatFileDescription
MIDI.mid
.midi
MIDI (Musical Instrument Digital Interface) is a format for electronic music devices like synthesizers and PC sound cards. MIDI files do not contain sound, but digital musical instructions (notes) that can be played by electronics (like your PC's sound card). Since MIDI files only contains instructions; they are extremely small. The example above is only 23K in size, but it plays for nearly 5 minutes. MIDI is supported by many software systems/platforms. MIDI is supported by all the most popular Internet browsers.
MP3.mp3MP3 files are actually the sound part of MPEG files. MPEG was originally developed for video by the Moving Pictures Experts Group. MP3 is the most popular format for music. The encoding system combines good compression (small files) with high quality
RealAudio.rm
.ram
RealAudio was developed Real Media. It allows streaming of audio (online music, Internet radio) with low bandwidths. Because of the low bandwidth priority, the quality is often reduced
WAV.wavWAVE (more known as WAV) was developed by IBM and Microsoft. WAVs are compatible with Windows, Macintosh, and Linux operating systems
WMA.wmaWMA (Windows Media Audio), compares in quality to MP3, and is compatible with most players, except the iPod. WMA files can be delivered as a continuous flow of data, which makes it practical for use in Internet radio or on-line music.