HTMLMediaElement 方法 canPlayType() reports how likely it is that the current browser will be able to play media of a given MIME type.

注意: This feature is not available in Web 工作者 .

句法

canPlayResponse = audioOrVideo.canPlayType(mediaType);
					

参数

mediaType
DOMString containing the MIME type of the media.

返回值

A DOMString indicating how likely it is that the media can be played. The string will be one of the following values:

probably
Media of the type indicated by the mediaType parameter is probably playable on this device.
maybe

Not enough information is available to determine for sure whether or not the media will play until playback is actually attempted.

"" (empty string)

Media of the given type definitely can't be played on the current device.

范例

var obj = document.createElement('video');
console.log(obj.canPlayType('video/mp4')); // "maybe"
					

规范

规范 状态 注释
HTML 实时标准
The definition of 'canplaytype' in that specification.
实时标准
HTML5
The definition of 'HTMLMediaElement.canplaytype' in that specification.
推荐 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
canPlayType() Chrome Yes Edge 12 Firefox 3.5
3.5
Prior to Firefox 28, canPlayType() 返回 probably when asked about WebM audio or video files without the codecs parameter. Since multiple codecs are supported, this is not enough information to determine if a file can be played, so maybe is now correctly returned.
IE 9 Opera Yes Safari 6 WebView Android Yes Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android Yes

图例

完整支持

完整支持

见实现注意事项。

另请参阅

元数据

  • 最后修改:
  1. HTMLMediaElement
  2. 特性
    1. audioTracks
    2. autoplay
    3. buffered
    4. controller
    5. controls
    6. controlsList
    7. crossOrigin
    8. currentSrc
    9. currentTime
    10. defaultMuted
    11. defaultPlaybackRate
    12. duration
    13. ended
    14. error
    15. initialTime
    16. loop
    17. mediaGroup
    18. muted
    19. networkState
    20. onerror
    21. paused
    22. playbackRate
    23. readyState
    24. seekable
    25. sinkId
    26. src
    27. srcObject
    28. textTracks
    29. videoTracks
    30. volume
  3. 方法
    1. canPlayType()
    2. captureStream()
    3. fastSeek()
    4. load()
    5. msInsertAudioEffect()
    6. pause()
    7. play()
    8. seekToNextFrame()
    9. setMediaKeys()
    10. setSinkId()
  4. 事件
    1. abort
    2. canplay
    3. canplaythrough
    4. durationchange
    5. emptied
    6. ended
    7. error
    8. loadeddata
    9. loadedmetadata
    10. loadstart
    11. pause
    12. play
    13. progress
    14. ratechange
    15. seeked
    16. seeking
    17. stalled
    18. suspend
    19. timeupdate
    20. volumechange
    21. waiting
  5. 继承:
    1. HTMLElement
    2. 元素
    3. 节点
    4. EventTarget
  6. HTML DOM 相关页面
    1. BeforeUnloadEvent
    2. DOMStringMap
    3. ErrorEvent
    4. GlobalEventHandlers
    5. HTMLAnchorElement
    6. HTMLAreaElement
    7. HTMLAudioElement
    8. HTMLBRElement
    9. HTMLBaseElement
    10. HTMLBaseFontElement
    11. HTMLBodyElement
    12. HTMLButtonElement
    13. HTMLCanvasElement
    14. HTMLContentElement
    15. HTMLDListElement
    16. HTMLDataElement
    17. HTMLDataListElement
    18. HTMLDialogElement
    19. HTMLDivElement
    20. HTMLDocument
    21. HTMLElement
    22. HTMLEmbedElement
    23. HTMLFieldSetElement
    24. HTMLFormControlsCollection
    25. HTMLFormElement
    26. HTMLFrameSetElement
    27. HTMLHRElement
    28. HTMLHeadElement
    29. HTMLHeadingElement
    30. HTMLHtmlElement
    31. HTMLIFrameElement
    32. HTMLImageElement
    33. HTMLInputElement
    34. HTMLIsIndexElement
    35. HTMLKeygenElement
    36. HTMLLIElement
    37. HTMLLabelElement
    38. HTMLLegendElement
    39. HTMLLinkElement
    40. HTMLMapElement
    41. HTMLMetaElement
    42. HTMLMeterElement
    43. HTMLModElement
    44. HTMLOListElement
    45. HTMLObjectElement
    46. HTMLOptGroupElement
    47. HTMLOptionElement
    48. HTMLOptionsCollection
    49. HTMLOutputElement
    50. HTMLParagraphElement
    51. HTMLParamElement
    52. HTMLPictureElement
    53. HTMLPreElement
    54. HTMLProgressElement
    55. HTMLQuoteElement
    56. HTMLScriptElement
    57. HTMLSelectElement
    58. HTMLShadowElement
    59. HTMLSourceElement
    60. HTMLSpanElement
    61. HTMLStyleElement
    62. HTMLTableCaptionElement
    63. HTMLTableCellElement
    64. HTMLTableColElement
    65. HTMLTableDataCellElement
    66. HTMLTableElement
    67. HTMLTableHeaderCellElement
    68. HTMLTableRowElement
    69. HTMLTableSectionElement
    70. HTMLTemplateElement
    71. HTMLTextAreaElement
    72. HTMLTimeElement
    73. HTMLTitleElement
    74. HTMLTrackElement
    75. HTMLUListElement
    76. HTMLUnknownElement
    77. HTMLVideoElement
    78. HashChangeEvent
    79. 历史
    80. ImageData
    81. 定位
    82. MessageChannel
    83. MessageEvent
    84. MessagePort
    85. Navigator
    86. NavigatorGeolocation
    87. NavigatorID
    88. NavigatorLanguage
    89. NavigatorOnLine
    90. NavigatorPlugins
    91. PageTransitionEvent
    92. Plugin
    93. PluginArray
    94. PopStateEvent
    95. PortCollection
    96. PromiseRejectionEvent
    97. RadioNodeList
    98. Transferable
    99. ValidityState
    100. Window
    101. WindowBase64
    102. WindowEventHandlers
    103. WindowTimers