Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

<video>

Ten artykuł wymaga przeglądu redakcyjnego. Dowiedz się jak możesz pomóc.

To tłumaczenie jest niekompletne. Pomóż przetłumaczyć ten artykuł z języka angielskiego.

Introduced in HTML5

 

W skrócie

Element <video> został stworzony do umieszczania treści wideo na stronie. Może zawierać wiele różnych źródeł z nagraniami, które określamy poprzez kolejne tagi <source> w nim zawarte albo poprzez atrybut src. Przeglądarka sama wybierze odpowiedni dla niej materiał.

Jeżeli chcesz zobaczyć listę wspieranych formatów, zobacz koniecznie Formaty mediów wspieranych przez elementy audio i video.

Kontekst użycia

  • Content categories Flow content, phrasing content, embedded content. If it has a controls attribute: interactive content and palpable content.
  • Permitted contentIf the element has a src attribute: zero or more <track> element, followed by transparent content that contains no media elements, that is no <audio> or <video>
    Else: zero or more <source> element, followed by zero or more <track> element, followed by transparent content that contains no media elements, that is no <audio> or <video>.
  • Tag omission None, both the starting and ending tag are mandatory.
  • Permitted parent elements Any element that accepts embedded content.
  • DOM interface HTMLVideoElement

Atrybuty

Podobnie jak inne tagi HTML, ten element może mieć przypisane atrybuty globalne.

autoplay
Atrybut typu Boolean; jeżeli go określimy, wideo zostanie odtworzone najszybciej, jak to możliwe bez zatrzymywania na czas dalszego pobierania.
autobuffer
Atrybut typu Boolean; jeżeli go określimy wideo zacznie się buforować nawet wtedy, gdy nie zostało włączone automatyczne odtwarzanie. This should be used for cases in which it is considered likely that the video will be played (for example, if the user navigated to the page specifically to play the video, not if there happens to be a video embedded along with other content). The video is buffered until the media cache is full.
Notka implementacyjna: początkowo jako część wstępnych szkiców HTML5, atrybut autobuffer nie pojawił się już w kolejnych ich wydaniach. Został usunięty w Gecko 2.0 i innych przeglądarkach. W specyfikacji umieszczono nowy atrybut, preload, aby zastąpić atrybut autobuffer z inną składnią. błąd 548523
buffered
An attribute you can read to determine which time ranges of the media have been buffered. This attribute contains a TimeRanges object.
controls
If this attribute is present, Gecko will offer controls to allow the user to control video playback, including volume, seeking, and pause/resume playback.
crossorigin
This enumerated attribute indicates if the fetching of the related image must be done using CORS or not. CORS-enabled resources can be reused in the <canvas> element without being tainted. The allowed values are:
anonymous
A cross-origin request (i.e. with Origin: HTTP header) is performed. But no credential is sent (i.e. no cookie, no X.509 certificate and no HTTP Basic authentication is sent). If the server does not give credentials to the origin site (by not setting the Access-Control-Allow-Origin: HTTP header), the image will be tainted and its usage restricted..
use-credentials
A cross-origin request (i.e. with Origin: HTTP header) is performed with credential is sent (i.e. a cookie, a certificate and HTTP Basic authentication is performed). If the server does not give credentials to the origin site (through Access-Control-Allow-Credentials: HTTP header), the image will be tainted and its usage restricted.
When not present, the resource is fetched without a CORS request (i.e. without sending the Origin: HTTP header), preventing its non-tainted used in <canvas> elements. If invalid, it is handled as if the enumerated keyword anonymous was used. See CORS settings attributes for additional information.
height
The height of the video's display area, in CSS pixels.
loop
A Boolean attribute; if specified, we will, upon reaching the end of the video, automatically seek back to the start.
muted
A Boolean attribute which indicates the default setting of the audio contained in the video. If set, the audio will be initially silenced. Its default value is false, meaning that the audio will be played when the video is played.
played
A TimeRanges object indicating all the ranges of the video that have been played.
preload
This enumerated attribute is intended to provide a hint to the browser about what the author thinks will lead to the best user experience. It may have one of the following values:
  • none: hints that either the author thinks that the user won't need to consult that video or that the server wants to minimize its traffic; in others terms this hint indicates that the video should not be cached.
  • metadata: hints that though the author thinks that the user won't need to consult that video, fetching the metadata (e.g. length) is reasonable.
  • auto: hints that the user needs have priority; in others terms this hint indicated that, if needed, the whole video could be downloaded, even if the user is not expected to use it.
  • the empty string: which is a synonym of the auto value.

If not set, its default value is browser-defined (i.e. each browser can choose its own default value), though the spec advises it to be set to metadata.

Usage notes:
  • The autoplay attribute has precedence over this one as if one wants to automatically play a video, the browser will obviously need to download it. Setting both the autoplay and the preload attributes is allowed by the specification.
  • The browser is not forced by the specification to follow the value of this attribute; it is a mere hint.
poster
Adres URL do zdjęcia ("plakatu"), które zostanie wyświetlone w miejscu elementu wideo dopóki użytkownik nie odtworzy go lub nie przewinie. Jeżeli atrybut niezostanie podany, nic niezostanie wyświetlone dopóki pierwsza klatka nagrania zostanie załadowana; wtedy ona stanie się "plakatem".
src
Adres URL materiału wideo do użycia. Jest to opcjonalne; zamiast tego powinieneś używać elementów <source> wewnątrz elementu wideo do określenia materiału do odtworzenia.
width
Szerokość obszaru wyświetlania obrazu wideo, w pikselach.

Zdarzenia

Element <video> może wywoływać wiele zdarzeń.

Przykłady

<!-- Prosty przykład z elementem video -->
<video src="videofile.ogg" autoplay poster="posterimage.jpg">
  Przepraszamy ale Twoja przeglądarka nie potrafi odtwarzać filmów za pomocą HTML5.
 Nie przejmuj się, bo <a href="videofile.ogg">możesz go stąd pobrać</a>
  i oglądać za pomocą swojego ulubionego odtwarzacza!
</video>

<!-- Wideo z napisami -->
<video src="foo.ogg">
  <track kind="subtitles" src="foo.en.vtt" srclang="en" label="English">
  <track kind="subtitles" src="foo.pl.vtt" srclang="pl" label="Polski">
</video>

Pierwszy przykład polega na odtworzeniu nagrania od razu po tym, jak odpowiednio duża część materiału zostanie pobrana, aby nie pauzować odtwarzania. Zanim zawartość elementu wideo zostanie wyświetlona, obrazek "posterimage.jpg" zostanie umieszczony w jej miejsce.

Drugi przykład pozwala użytkownikowi na wybór odpowiednich napisów.

Wsparcie serwera

Jeżeli typ MIME dla elementu wideo niezostanie poprawnie ustawiony na serwerze, może się on nie pojawić albo pojawić jako szary obszar z X (jeżeli JavaScript jest włączony).

Korzystając z Ogg Theora i pracując na Apache Web Server możesz rozwiązać ten problem dodając rozszerzenia używane przez Twoje pliki wideo (".ogm", ".ogv" i ".ogg" są najpowszechniejsze) do typów MIME "video/ogg" w pliku "mime.types" w folderze "/etc/apache" albo poprzez komendę konfiguracyjną "AddType" w pliku httpd.conf.

AddType video/ogg .ogm
AddType video/ogg .ogv
AddType video/ogg .ogg

Korzystając z WebM i pracując na Apache Web Server możesz rozwiązać ten problem dodając rozszerzenie używane przez Twoje pliki wideo (".webm" jest najpowszechniejszy) do typów MIME "video/webm" w pliku "mime.types" w folderze "/etc/apache" albo poprzez komendę konfiguracyjną "AddType" w pliku httpd.conf.

AddType video/webm .webm

Pamiętaj, że Twój hosting internetowy może dostarczać łatwiejsze sposoby konfiguracji typów MIME, aby obsługiwać najnowsze technologie zanim globalnie zostaną wprowadzone w użycie.

Interfejs DOM

Ten element implementuje interfejs HTMLVideoElement.

Kompatybilność z przeglądarkami

Cecha Chrome Firefox (Gecko) Internet Explorer Opera Safari
Podstawowa obsługa 3.0 3.5 (1.9.1) 9.0 10.5 3.1
atrybut autoplay 3.0 3.5 (1.9.1) 9.0 10.5 3.1
atrybut buffered ? 4.0 (2.0) ? Yes ?
atrybut controls 3.0 3.5 (1.9.1) 9.0 10.5 3.1
atrybut crossorigin ? 12.0 (12.0) ? ? ?
atrybut loop 3.0 11.0 (11.0) 9.0 10.5 3.1
atrybut muted ? 11.0 (11.0) ? Yes ?
właściwość played ? 15.0 (15.0) ? Yes ?
atrybut poster 3.0 3.6 (1.9.2) 9.0 10.5 3.1
atrybut preload 3.0 4.0 (2.0) 9.0 Yes 3.1
atrybut src 3.0 3.5 (1.9.1) 9.0 10.5 3.1
Cecha Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Podstawowa obsługa ? 1.0 (1.0) ? ? ?
atrybut autoplay ? 1.0 (1.0) ? ? iOS 6.0 only
atrybut buffered ? 4.0 (2.0) ? ? ?
atrybut controls ? 1.0 (1.0) ? ? ?
atrybut loop ? 11.0 (11.0) ? ? ?
atrybut muted ? 11.0 (11.0) ? ? ?
właściwość played ? 15.0 (15.0) ? ? ?
atrybut poster ? 1.0 (1.0) ? ? ?
atrybut preload ? 4.0 (2.0) ? ? ?
atrybut src ? 1.0 (1.0) ? ? ?
atrybut crossorigin ? 12.0 (12.0) ? ? ?

 

Zobacz także

Autorzy i etykiety dokumentu

 Autorzy tej strony: Trebor
 Ostatnia aktualizacja: Trebor,