Player
當使用任何Video.js設置方法初始化視頻時,將創建Player類的實例。
創建實例后,可以通過兩種方式在全局訪問:
調用videojs('example_video_1');
直接通過videojs.players.example_video_1使用它;
構造函數
new Player(tag, optionsopt, readyopt)
創建此類的實例
參數:
名稱 | 類型 | 屬性 | 描述 |
---|---|---|---|
tag |
Element | 用於配置選項的原始 video DOM 元素。 |
|
options |
Object | <optional> | 選項名稱和值的對象。 |
ready |
Component~ReadyCallback | <optional> | Ready 回調函數。 |
延伸
- Component
成員
靜態 players :Object
-
全局播放器列表。
方法
靜態 getTagSettings(tag) → {Object}
-
獲取標簽設置
參數:
名稱 類型 描述 tag
Element 播放器標簽
返回值:
Object - 包含播放器標簽的所有設置的對象
$(selector, contextopt) → {Element|null}
-
查找與選擇器匹配的單個DOM元素。 這可以在組件contentEl()或另一個自定義上下文中。
Parameters:
名稱 類型 屬性 默認 描述 selector
string 一個有效的CSS選擇器,它將被傳遞給querySelector。
context
Element | string <optional> this.contentEl() 要查詢的DOM元素。 也可以是選擇器字符串,在這種情況下,第一個匹配元素將用作上下文。 如果缺失則this.contentEl()被使用。 如果this.contentEl()不返回任何東西,它會回到 document。
返回值:
Element | null - 找到的dom元素,或null- 繼承自:
-
- Component#$
$$(selector, contextopt) → {NodeList}
-
查找與選擇器匹配的所有DOM元素。 這可以在組件contentEl()或另一個自定義上下文中。
參數:
名稱 類型 屬性 默認 描述 selector
string 一個有效的CSS選擇器,它將被傳遞給
querySelectorAll
.context
Element | string <optional> this.contentEl() 要查詢的DOM元素。 也可以是選擇器字符串,在這種情況下,第一個匹配元素將用作上下文。 如果缺失則this.contentEl()被使用。 如果this.contentEl()不返回任何東西,它會回到 document。
返回值:
NodeList - 找到的dom元素的列表- 繼承自:
-
- Component#$$
addChild(child, optionsopt, indexopt) → {Component}
-
在當前組件中添加子組件。
參數:
名稱 類型 屬性 默認 描述 child
string | Component 要添加的子級的名稱或實例。
options
Object <optional> {} 將要傳遞給子級的子組件選項的鍵/值存儲。
index
number <optional> this.children_.length 嘗試添加子元素的索引。
返回值:
Component - 作為子項添加的組件。 當使用字符串時,組件將由此過程創建。- 繼承自:
-
- Component#addChild
addClass(classToAdd)
-
參數:
名稱 類型 描述 classToAdd
string 添加的CSS類名稱
- 繼承自:
-
- Component#addClass
addRemoteTextTrack(options, manualCleanupopt) → {HTMLTrackElement}
-
創建遠程TextTrack和HTMLTrackElement。 每當源更改時,它將從視頻元素中自動刪除,除非manualCleanup設置為false。
參數:
名稱 類型 屬性 默認 描述 options
Object 在創建期間傳遞到HTMLTrackElement的選項。 請參閱您應該使用的對象屬性的HTMLTrackElement。
manualCleanup
boolean <optional> true 如果設置為false,TextTrack 不會自動刪除
返回值:
HTMLTrackElement -已創建並添加到HTMLTrackElementList和遠程TextTrackList的HTMLTrackElement
- 已棄用:
-
- 在即將到來的Video.js版本中,“manualCleanup”參數的默認值默認為“false”
addTextTrack(kindopt, labelopt, languageopt) → {TextTrack|undefined}
-
用於向TextTrackList添加TextTrack的輔助方法。
除了W3C設置,我們允許通過選項添加附加信息。
參數:
名稱 類型 屬性 描述 kind
string <optional> 您要添加的TextTrack的類型
label
string <optional> 標簽給出TextTrack標簽
language
string <optional> 在TextTrack上設置的語言
返回值:
TextTrack | undefined - 已被添加的TextTrack或undefined (如果沒有技術)
aspectRatio(ratioopt) → {string|undefined}
-
用於播放器寬高比的getter / setter。
參數:
名稱 類型 屬性 描述 ratio
string <optional> 設置播放器寬高比的值。
返回值:
string | undefined -- 播放器當前的縱橫比,獲取時
- undefined 設置時
- 播放器當前的縱橫比,獲取時
audioTracks() → {AudioTrackList}
-
獲取AudioTrackList
返回值:
AudioTrackList -當前音軌列表
autoplay(valueopt) → {string}
-
獲取或設置autoplay屬性。
參數:
名稱 類型 屬性 描述 value
boolean <optional> - true 表示我們應該自動播放
- false 表示我們應該不自動播放
返回值:
string -獲取時自動播放的當前值
- true 表示我們應該自動播放
blur()
-
從此組件中刪除焦點
- 繼承自:
-
- Component#blur
buffered() → {TimeRange}
-
使用已下載的視頻時間數組獲取TimeRange對象。 如果您只想要下載的視頻的百分比,請使用bufferedPercent。
返回值:
TimeRange - 模擬TimeRange對象(遵循HTML規范)
bufferedEnd() → {number}
-
獲取上次緩沖時間范圍的結束時間這在進度條中用於封裝所有時間范圍。
返回值:
number - 最新緩沖時間范圍的結束
bufferedPercent() → {number}
-
獲取已下載視頻的百分比(十進制)。 此方法不是原生HTML video API的一部分。
返回值:
number - 0和1之間的小數表示緩沖的百分比,0是0%,1是100%
abstract(抽象修飾) buildCSSClass() → {string}
-
構建默認DOM類名稱。 應該被子組件覆蓋。
返回值:
string - 此對象的DOM類名稱。- 繼承自:
-
- Component#buildCSSClass
cancelAnimationFrame(id) → {number}
-
取消傳遞到Component#requestAnimationFrame(rAF)的排隊回調。
如果您通過Component#requestAnimationFrame對rAF回調進行排隊,請使用此函數,而不是window.cancelAnimationFrame。 如果沒有,你的Dispose偵聽器將不會被清除,直到Component#dispose!
參數:
名稱 類型 描述 id
number 要清除的rAF ID。 Component#requestAnimationFrame的返回值。
返回值:
number - 返回已清除的rAF ID。- 繼承自:
-
- Component#cancelAnimationFrame
canPlayType(type) → {string}
-
檢查播放器是否可以播放給定的mimetype
參數:
名稱 類型 描述 type
string 要檢查的mimetype
返回值:
string - 'probably', 'maybe', or '' (empty string) - 很有可能、可能、空字符串 -
children() → {Array}
-
獲取所有子組件的數組
返回值:
Array - 子組件的數組- 繼承自:
-
- Component#children
clearInterval(intervalId) → {number}
-
清除通過window.setInterval或Component#setInterval創建的間隔。 如果通過組件#setInterval設置一個inteval,則使用此函數,而不是使用window.clearInterval。 如果你不這樣做,你的配置偵聽器將不會被清理,直到Component#dispose!
參數:
名稱 類型 描述 intervalId
number 要清除的間隔的ID。Component#setInterval或window.setInterval的返回值。
返回值:
number - 返回已清除的間隔ID。- 繼承自:
-
- Component#clearInterval
clearTimeout(timeoutId) → {number}
-
清除通過window.setTimeout或Component#setTimeout創建的超時。 如果通過Component#setTimeout設置超時,則使用此函數,而不是使用window.clearTimout。 如果你不這樣做,你的配置偵聽器將不會被清理,直到Component#dispose!
參數:
名稱 類型 描述 timeoutId
number 要清除的超時的ID。 Component#setTimeout或window.setTimeout的返回值。
返回值:
number - 返回已清除的超時id。- 繼承自:
-
- Component#clearTimeout
contentEl() → {Element}
-
返回組件DOM元素。 這是子組件插入的地方。 這通常與Component#el中返回的元素相同。
返回值:
Element - 組件的內容元素。- 繼承自:
-
- Component#contentEl
controls(boolopt) → {boolean}
-
獲取或設置控件是否顯示。
參數:
名稱 類型 屬性 描述 bool
boolean <optional> - true 打開控制
- false 關閉控制
觸發器:
- Player#event:controlsenabled
返回值:
boolean - 獲取時controls的當前值 - true 打開控制
createEl() → {Element}
-
創建播放器的DOM元素。
返回值:
Element - 創建的DOM元素。- 覆蓋:
-
- Component#createEl
createModal(content, optionsopt) → {ModalDialog}
-
創建一個簡單的模態對話框(ModalDialog組件的一個實例),立即用任意內容覆蓋播放器,並在關閉時刪除它自己。
參數:
名稱 類型 屬性 描述 content
string | function | Element |Array | null 與ModalDialog#content的同名參數相同。 最直接的用法是提供一個字符串或DOM元素。
options
Object <optional> 將被傳遞到ModalDialog的額外選項。
返回值:
ModalDialog - 創建的ModalDialog
currentDimension(widthOrHeight) → {number}
-
獲取組件元素計算樣式的寬度或高度。 使用window.getComputedStyle。
參數:
名稱 類型 描述 widthOrHeight
string 包含“width”或“height”的字符串。 無論你想得到什么。
返回值:
number - 獲取要求的維度,如果未為該維度設置任何內容,則為0。- 繼承自:
-
- Component#currentDimension
currentDimensions() → {Component~DimensionObject}
-
獲取包含組件計算樣式的寬度和高度值的對象。
返回值:
Component~DimensionObject - 組件元素的尺寸- 繼承自:
-
- Component#currentDimensions
currentHeight() → {number}
-
獲取組件計算樣式的高度。 使用window.getComputedStyle。
返回值:
number - 組件計算樣式的高度。- Inherited From:
-
- Component#currentHeight
currentSource() → {Tech~SourceObject}
-
返回當前資源對象。
返回值:
Tech~SourceObject - 當前資源對象
currentSources() → {Array.<Tech~SourceObject>}
-
返回所有當前資源對象。
Returns:
Array.<Tech~SourceObject> - 當前資源對象數組
currentSrc() → {string}
-
返回當前資源值的完全限定網址,例如 http://mysite.com/video.mp4可以與currentType結合使用,以幫助重建當前源對象。
返回值:
string - 當前資源網址
currentTime(secondsopt) → {number}
-
獲取或設置當前時間(以秒為單位)
參數:
名稱 類型 屬性 描述 seconds
number | string <optional> 設置時尋找的時間,以秒為單位
返回值:
number -- 獲取時以秒為單位的當前時間
currentType() → {string}
-
獲取當前的資源類型,例如 video / mp4,這可以允許您重建當前源對象,以便以后可以加載相同的資源和技術
返回值:
string - 資源的MIME類型
currentWidth() → {number}
-
獲取組件計算樣式的寬度。 使用window.getComputedStyle。
返回值:
number - 組件計算樣式的寬度。- 繼承自:
-
- Component#currentWidth
defaultMuted(defaultMutedopt) → {boolean|Player}
-
獲取當前的defaultMuted狀態,或打開或關閉defaultMuted。 defaultMuted表示初始播放時靜音的狀態。
var myPlayer = videojs('some-player-id'); myPlayer.src("http://www.example.com/path/to/video.mp4"); // 獲取的值為false console.log(myPlayer.defaultMuted()); // 設置為true myPlayer.defaultMuted(true); // 獲取的值為 true console.log(myPlayer.defaultMuted());
參數:
名稱 類型 屬性 描述 defaultMuted
boolean <optional> - true 設置為靜音
- false 取消靜音
返回值:
boolean | Player -- 如果defaultMuted為on並獲取,則為true
- 如果defaultMuted為off並獲取,則為
false
- 設置時引用的當前播放器
- true 設置為靜音
defaultPlaybackRate(rateopt) → {number|Player}
-
獲取或設置當前默認播放速率。 例如默認回放速率1.0表示正常速度,0.5表示半速回放。 defaultPlaybackRate只會表示視頻的初始playbackRate,而不是當前的playbackRate。
參數:
名稱 類型 屬性 描述 rate
number <optional> 要設置的新默認播放速率。
返回值:
number | Player -- 獲取時的默認播放速率 or 1.0
- 設置時返回播放器
- 獲取時的默認播放速率 or 1.0
dimension(dimension, valueopt) → {number} 維度
-
播放器寬度和高度的getter / setter。
參數:
名稱 類型 屬性 描述 dimension
string 此字符串可能是:
- 'width' - 'height'
value
number <optional> 第一個參數中指定的維度值。
返回值:
number - 獲取時制定的維度參數值 (width/height).- 覆蓋:
-
- Component#dimension
dimensions(width, height)
-
同時設置Component元素的寬度和高度。
參數:
名稱 類型 描述 width
number | string 要設置的Component元素的寬度。
height
number | string 要設置的Component元素的高度。
- 繼承自:
-
- Component#dimensions
dispose()
-
銷毀視頻播放器並進行任何必要的清理。
如果您要動態向DOM添加視頻和從DOM中刪除視頻,這一點尤其有用。
觸發:
- Player#event:dispose
- 覆蓋:
-
- Component#dispose
duration(secondsopt) → {number}
-
通常獲取視頻的時間長度(以秒為單位); 除了最罕見的用例之外,參數不會被傳遞給方法
注意:視頻必須在已知持續時間之前開始加載,對於Flash,在視頻開始播放之前可能無法知道。
參數:
名稱 類型 屬性 描述 seconds
number <optional> 視頻設置的持續時間(以秒為單位)
Fires:
- Player#event:durationchange
返回值:
number -- 獲取視頻的時長(以秒為單位)
el() → {Element}
-
獲取組件的的dom元素
返回值:
Element -The DOM element for this
Component
.- Inherited From:
enableTouchActivity()
-
此函數在觸摸事件發生時報告用戶活動。這可以關閉任何想要觸摸事件以另外一種方式運行的子組件
觸摸事件發生時報告用戶觸摸活動。用戶活動用於確定控件何時應顯示/隱藏。它是簡單的,當涉及到鼠標事件,因為任何鼠標事件應該顯示控件。因此,我們捕獲向玩家發出的鼠標事件,並在發生時報告活動。有觸摸事件它不像touchstart和touchend切換播放器控件一樣簡單。所以觸摸事件不能幫助我們在播放器級別。
異步檢查用戶活動。所以可能發生的是在視頻上的點擊事件關閉控制。然后,touchend事件冒泡向玩家。其中,如果它報告用戶活動,將重新打開控件。我們也不想完全阻止觸摸事件冒泡。此外,touchmove事件和除了水龍頭之外的任何東西,不應該重新打開控制。
監聽下列事件:
- Component#event:touchstart
- Component#event:touchmove
- Component#event:touchend
- Component#event:touchcancel
- 繼承自:
-
- Component#enableTouchActivity
ended() → {Boolean}
-
返回玩家是否處於“已結束”狀態。
返回值:
Boolean -如果玩家處於結束狀態,則返回True ,否則返回false 。
enterFullWindow()
-
當不支持全屏時,我們可以將視頻容器拉伸到瀏覽器允許的寬度。
Fires:
- Player#event:enterFullWindow
error(erropt) → {MediaError|null}
-
設置或獲取當前的MediaError
參數:
名稱 類型 屬性 描述 err
MediaError | string | number <optional> MediaError或要變成MediaError的字符串/數字
Fires:
- Player#event:error
返回值:
MediaError | null -當獲取時的當前MediaError(或null)
exitFullscreen()
-
在全屏模式后,將視頻恢復到正常大小
Fires:
- Player#event:fullscreenchange
exitFullWindow()
-
退出全窗口模式
Fires:
- Player#event:exitFullWindow
flexNotSupported_() → {boolean}
-
確定是否支持flexbox
返回值:
boolean -- true 如果支持flexbox
- false 如果不支持flexbox
- true 如果支持flexbox
fluid(boolopt) → {boolean|undefined}
-
Player上的vjs-fluid className的getter / setter / toggler。
參數:
名稱 類型 屬性 描述 bool
boolean <optional> - 值為 true 則添加此calss.
-值為 false 則移除此 class. - 沒有值將toggle the fluid class.
返回值:
boolean | undefined -- The value of fluid when getting.
- `undefined` when setting.
- 值為 true 則添加此calss.
focus()
-
將焦點設置到此組件
- Inherited From:
-
- Component#focus
fullWindowOnEscKey(event)
-
在ESC鍵上檢查呼叫是退出完整窗口還是全屏
參數:
名稱 類型 描述 event
string Event to check for key press
getAttribute(attribute) → {string|null}
-
獲取Components元素上的屬性值。
參數:
名稱 類型 描述 attribute
string 要獲取值的屬性的名稱。
返回值:
string | null -- 要求的屬性的值。
- 如果該屬性不存在或沒有值,則可能是某些瀏覽器上的空字符串 - 如果屬性不存在或沒有值,大多數瀏覽器將返回null。
- Inherited From:
-
- Component#getAttribute
- See:
-
-
DOM API
-
- 要求的屬性的值。
getCache() → {Object}
-
獲取緩存值的對象。
返回值:
Object -獲取當前對象緩存
getChild(name) → {Component|undefined}
-
返回具有給定名稱的子組件。
參數:
名稱 類型 描述 name
string 要獲取的子組件的名稱。
返回值:
Component | undefined -具有給定名稱的子組件或未定義。
- Inherited From:
-
- Component#getChild
getChildById(id) → {Component|undefined}
-
返回具有給定ID的子組件。
參數:
名稱 類型 描述 id
string 要獲取的子組件的id。
- Inherited From:
-
- Component#getChildById
hasClass(classToCheck) → {boolean}
-
檢查組件的元素是否具有CSS類名稱。
參數:
名稱 類型 描述 classToCheck
string 要檢查的CSS類名稱。
返回值:
boolean -- True if the
Component
has the class.- False if the `Component` does not have the class`
- Inherited From:
-
- Component#hasClass
- True if the
hasPlugin(name) → {boolean}
-
報告播放器是否有可用的插件。
這里不報告插件是否已經在這個播放器上被初始化了。 為此,usingPlugin。
參數:
名稱 類型 描述 name
string 插件的名稱。
返回值:
boolean -該播放器是否具有可用的請求插件。
hasStarted(hasStarted) → {boolean}
-
Add/remove the vjs-has-started class
參數:
名稱 類型 描述 hasStarted
boolean - true: adds the class
- false: remove the class
Fires:
- Player#event:firstplay
返回值:
boolean -the boolean value of hasStarted
- true: adds the class
height(valueopt) → {number}
-
A getter/setter for the
Player
's height.參數:
名稱 類型 屬性 描述 value
number <optional> The value to set the `Player's heigth to.
返回值:
number -The current height of the
Player
when getting.- Overrides:
-
- Component#height
hide()
-
Hide the
Component
s element if it is currently showing by adding the 'vjs-hidden` class name to it.- Inherited From:
-
- Component#hide
id() → {string}
-
Get this
Component
s ID返回值:
string -The id of this
Component
- Inherited From:
-
- Component#id
initChildren()
-
根據選項添加和初始化默認的子組件。
- Inherited From:
-
- Component#initChildren
isAudio(bool) → {boolean}
-
Gets or sets the audio flag
參數:
名稱 類型 描述 bool
boolean - true signals that this is an audio player
- false signals that this is not an audio player
返回值:
boolean -The current value of isAudio when getting
- true signals that this is an audio player
isFullscreen(isFSopt) → {boolean}
-
檢查播放器是否處於全屏模式,或者告訴播放器它是或不是全屏模式。
注意:根據最新的HTML5規范,isFullscreen不再是官方屬性,而是使用document.fullscreenElement。 但isFullscreen仍然是內部播放器運行的有價值的屬性。
參數:
名稱 類型 屬性 描述 isFS
boolean <optional> 設置播放器當前的全屏狀態
返回值:
boolean -- true 如果全屏是開啟的並且獲取時
- false 如果全屏是關閉的並且獲取時
- true 如果全屏是開啟的並且獲取時
language(codeopt) → {string}
-
The player's language code NOTE: The language should be set in the player options if you want the the controls to be built with a specific language. Changing the lanugage later will not update controls text.
參數:
名稱 類型 屬性 描述 code
string <optional> the language code to set the player to
返回值:
string -The current language code when getting
languages() → {Array}
-
Get the player's language dictionary Merge every time, because a newly added plugin might call videojs.addLanguage() at any time Languages specified directly in the player options have precedence
返回值:
Array -An array of of supported languages
load()
-
Begin loading the src data.
localize(string) → {string}
-
Localize a string given the string in english.
參數:
名稱 類型 描述 string
string The string to localize.
返回值:
string -The localized string or if no localization exists the english string.
- Inherited From:
loop(valueopt) → {string}
-
Get or set the loop attribute on the video element.
參數:
名稱 類型 屬性 描述 value
boolean <optional> - true means that we should loop the video
- false means that we should not loop the video
返回值:
string -The current value of loop when getting
- true means that we should loop the video
muted(mutedopt) → {boolean}
-
Get the current muted state, or turn mute on or off
參數:
名稱 類型 屬性 描述 muted
boolean <optional> - true to mute
- false to unmute
返回值:
boolean -- true if mute is on and getting
- false if mute is off and getting
- true to mute
name() → {string}
-
Get the
Component
s name. The name gets used to reference theComponent
and is set during registration.返回值:
string -The name of this
Component
.- Inherited From:
networkState() → {number}
-
從以下列表中的代碼返回元素的網絡活動的當前狀態。
- NETWORK_EMPTY (numeric value 0) 元素尚未初始化, 所有屬性都處於初始狀態。
- NETWORK_IDLE (numeric value 1) 元素的資源選擇算法處於活動狀態,並且已經選擇了一個資源,但此時並不實際使用該網絡。
- NETWORK_LOADING (numeric value 2) 用戶代理正在積極嘗試下載數據。
- NETWORK_NO_SOURCE (numeric value 3) 元素的資源選擇算法處於活動狀態,但尚未找到要使用的資源。
返回值:
number -當前網絡活動狀態
options(obj) → {Object}
-
Deep merge of options objects with new options.
Note: When both
obj
andoptions
contain properties whose values are objects. The two properties get merged using module:mergeOptions參數:
名稱 類型 描述 obj
Object The object that contains new options.
返回值:
Object -A new object of
this.options_
andobj
merged together.- Inherited From:
- Deprecated:
-
- since version 5
pause() → {Player}
-
Pause the video playback
paused() → {boolean}
-
Check if the player is paused or has yet to play
返回值:
boolean -- false: if the media is currently playing
- true: if media is not currently playing
- false: if the media is currently playing
play() → {Promise|undefined}
-
start media playback
返回值:
Promise | undefined -Returns a
Promise
if the browser returns one, for most browsers this will return undefined.
playbackRate(rateopt) → {number}
-
Gets or sets the current playback rate. A playback rate of 1.0 represents normal speed and 0.5 would indicate half-speed playback, for instance.
參數:
名稱 類型 屬性 描述 rate
number <optional> New playback rate to set.
返回值:
number -The current playback rate when getting or 1.0
played() → {TimeRange}
-
Get a TimeRange object representing the current ranges of time that the user has played.
返回值:
TimeRange -A time range object that represents all the increments of time that have been played.
player() → {Player}
-
Return the Player that the
Component
has attached to.- Inherited From:
poster(srcopt) → {string}
-
Get or set the poster image source url
參數:
名稱 類型 屬性 描述 src
string <optional> Poster image source URL
Fires:
返回值:
string -The current value of poster when getting
preload(valueopt) → {string}
-
獲取或設置preload屬性
參數:
名稱 類型 屬性 描述 value
boolean <optional> - true 意味着要預加載
- false 意味着不需要預加載
返回值:
string -獲取時的preload屬性值
- true 意味着要預加載
ready() → {Component}
-
將偵聽器綁定到組件的就緒狀態。 與事件偵聽器不同的是,如果ready事件已經發生,它將立即觸發該功能。
返回值:
Component -返回自己; 方法可以鏈接。
- Inherited From:
-
- Component#ready
readyState() → {number}
-
從下面的列表中的代碼返回一個值,表示當前呈現當前播放位置的元素的當前狀態。
HAVE_NOTHING(數值0)沒有關於媒體資源的信息可用。
HAVE_METADATA(數值1)已獲得足夠的資源,資源的持續時間可用。
HAVE_CURRENT_DATA(數值2)即時當前播放位置的數據可用。
HAVE_FUTURE_DATA(數值3)即時當前播放位置的數據可用,以及足夠的數據供用戶代理在播放方向上提前播放當前位置。
HAVE_ENOUGH_DATA(數值4)用戶代理估計足夠的數據可用於播放以不間斷地繼續。- HAVE_NOTHING(數值0)沒有關於媒體資源的信息可用。
- HAVE_METADATA(數值1)已獲得足夠的資源,資源的持續時間可用。
- HAVE_CURRENT_DATA (數值 2) 當前播放位置的即時數據可用。
- HAVE_FUTURE_DATA (數值 3) 當前播放位置的即時數據可用, 以及足夠的數據供用戶代理在播放方向上提前播放當前位置。
- HAVE_ENOUGH_DATA (數值 4) 用戶代理估計足夠的數據可用於播放以不間斷地繼續。
返回值:
number -當前播放渲染狀態
remainingTime() → {number}
-
計算視頻中剩余多少時間。 不是原生視頻API的一部分。
返回值:
number -剩余時間以秒為單位
remoteTextTrackEls() → {HTMLTrackElementList}
-
Get the remote HTMLTrackElementList tracks.
removeAttribute(attribute)
-
Remove an attribute from the
Component
s element.參數:
名稱 類型 描述 attribute
string Name of the attribute to remove.
- Inherited From:
- See:
removeChild(component)
-
Remove a child
Component
from thisComponent
s list of children. Also removes the childComponent
s element from thisComponent
s element.參數:
名稱 類型 描述 component
Component The child
Component
to remove.- Inherited From:
removeClass(classToRemove)
-
Remove a CSS class name from the
Component
s element.參數:
名稱 類型 描述 classToRemove
string CSS class name to remove
- Inherited From:
removeRemoteTextTrack(track) → {undefined}
-
Remove a remote TextTrack from the respective TextTrackList and HTMLTrackElementList.
參數:
名稱 類型 描述 track
Object Remote TextTrack to remove
返回值:
undefined -does not return anything
reportUserActivity(event)
-
Report user activity
參數:
名稱 類型 描述 event
Object Event object
requestAnimationFrame(fn) → {number}
-
Queues up a callback to be passed to requestAnimationFrame (rAF), but with a few extra bonuses:
-
Supports browsers that do not support rAF by falling back to Component#setTimeout.
-
The callback is turned into a Component~GenericCallback (i.e. bound to the component).
-
Automatic cancellation of the rAF callback is handled if the component is disposed before it is called.
參數:
名稱 類型 描述 fn
Component~GenericCallback A function that will be bound to this component and executed just before the browser's next repaint.
Listens to Events:
返回值:
number -Returns an rAF ID that gets used to identify the timeout. It can also be used in Component#cancelAnimationFrame to cancel the animation frame callback.
- Inherited From:
- See:
-
requestFullscreen()
-
將視頻的大小增加到全屏在某些瀏覽器中,全屏不被原生支持,因此進入“完整窗口模式”,視頻填充瀏覽器窗口。 在支持原生全屏的瀏覽器和設備中,有時會顯示瀏覽器的默認控件,而不是Video.js的自定義外觀。 這包括大多數移動設備(iOS,Android)和較舊版本的Safari。
Fires:
- Player#event:fullscreenchange
reset()
-
重置播放器. 加載techOrder的第一個技術,並且調用tech上的重置
scrubbing(isScrubbingopt) → {boolean}
-
返回用戶是否正在“擦除”。 擦洗是當用戶點擊進度條手柄並沿着進度條拖動時。
參數:
名稱 類型 屬性 描述 isScrubbing
boolean <optional> 用戶是否擦除
返回值:
boolean -獲取時scrubbing的值
seekable() → {TimeRanges}
-
返回當前可用於尋找的媒體的TimeRanges。
返回值:
TimeRanges -媒體時間軸的可尋找間隔
seeking() → {Boolean}
-
返回玩家是否處於“尋求”狀態。
返回值:
Boolean -如果玩家處於尋求狀態,則為真,否則為假。
selectSource(sources) → {Object|boolean}
-
Select source based on tech-order or source-order Uses source-order selection if
options.sourceOrder
is truthy. Otherwise, defaults to tech-order selection參數:
名稱 類型 描述 sources
Array The sources for a media asset
返回值:
Object | boolean -Object of source and tech order or false
setAttribute(attribute, value)
-
Set the value of an attribute on the
Component
's element參數:
名稱 類型 描述 attribute
string Name of the attribute to set.
value
string Value to set the attribute to.
- Inherited From:
- See:
setInterval(fn, interval) → {number}
-
創建一個每x毫秒運行的函數。 這個函數是一個圍繞window.setInterval的包裝器。 用這個函數代替有以下原因。
- 當Component#dispose被調用時,它通過Component#clearInterval清除。
- 函數回調將是一個Component〜GenericCallback
參數:
名稱 類型 描述 fn
Component~GenericCallback 每x秒運行一次的函數。
interval
number 每x毫秒執行指定的函數。
Listens to Events:
- Component#event:dispose
返回值:
number -返回可用於標識interval的ID。 也可以在Component#clearInterval中使用它來清除間隔
- Inherited From:
-
- Component#setInterval
-
setTimeout(fn, timeout) → {number}
-
Creates a function that runs after an
x
millisecond timeout. This function is a wrapper aroundwindow.setTimeout
. There are a few reasons to use this one instead though:創建在x毫秒超時后運行的函數。 這個函數是一個圍繞window.setTimeout的包裝器。 使用這個函數的一些原因:
- 當Component#dispose被調用時,它通過Component#clearTimeout清除。
- 函數回調將變成一個Component〜GenericCallback
注意:您可以在此函數返回的id上使用window.clearTimeout。 這將使其dispose listene不被清理! 請使用Component#clearTimeout或Component#dispose。
參數:
名稱 類型 描述 fn
Component~GenericCallback 超時后運行的函數。
timeout
number 在執行指定功能之前延遲(以毫秒為單位)。
Listens to Events:
- Component#event:dispose
返回值:
number -返回用於標識超時的超時ID。 它也可以在Component#clearTimeout中使用,以清除設置的超時。
- Inherited From:
-
- Component#setTimeout
-
show()
-
Show the
Component
s element if it is hidden by removing the 'vjs-hidden' class name from it.- Inherited From:
src(sourceopt) → {string}
-
The source function updates the video source There are three types of variables you can pass as the argument. URL string: A URL to the the video file. Use this method if you are sure the current playback technology (HTML5/Flash) can support the source you provide. Currently only MP4 files can be used in both HTML5 and Flash.
參數:
名稱 類型 屬性 描述 source
Tech~SourceObject | Array.<Tech~SourceObject> <optional> One SourceObject or an array of SourceObjects
返回值:
string -The current video source when getting
supportsFullScreen() → {boolean}
-
檢查當前的技術可以支持原生的全屏(例如,內置的控件,如iOS,所以不是我們的Flash swf)
返回值:
boolean -if native fullscreen is supported
tech(safetyopt) → {Tech}
-
Return a reference to the current Tech. It will print a warning by default about the danger of using the tech directly but any argument that is passed in will silence the warning.
參數:
名稱 類型 屬性 描述 safety
* <optional> Anything passed in to silence the warning
textTracks() → {TextTrackList}
-
Get the TextTrackList
textTracks() → {TextTrackList}
-
Get the remote TextTrackList
toggleClass(classToToggle, predicateopt)
-
Add or remove a CSS class name from the component's element.
classToToggle
gets added when Component#hasClass would return false.classToToggle
gets removed when Component#hasClass would return true.
參數:
名稱 類型 屬性 描述 classToToggle
string The class to add or remove based on (@link Component#hasClass}
predicate
boolean | Dom~predicate <optional> An Dom~predicate function or a boolean
- Inherited From:
toJSON() → {Object}
-
returns a JavaScript object reperesenting the current track information. DOES not return it as JSON
返回值:
Object -Object representing the current of track info
triggerReady()
-
觸發此組件的所有就緒偵聽器。
發起:
- Component#event:ready
- 繼承自:
-
- Component#triggerReady
userActive(boolopt) → {boolean}
-
Get/set if user is active
參數:
名稱 類型 屬性 描述 bool
boolean <optional> - true if the user is active
- false if the user is inactive
Fires:
返回值:
boolean -The current value of userActive when getting
- true if the user is active
usingNativeControls(boolopt) → {boolean}
-
Toggle native controls on/off. Native controls are the controls built into devices (e.g. default iPhone controls), Flash, or other techs (e.g. Vimeo Controls) This should only be set by the current tech, because only the tech knows if it can support native controls
參數:
名稱 類型 屬性 描述 bool
boolean <optional> - true to turn native controls on
- false to turn native controls off
Fires:
返回值:
boolean -The current value of native controls when getting
- true to turn native controls on
usingPlugin(name) → {boolean}
-
Reports whether or not a player is using a plugin by name.
For basic plugins, this only reports whether the plugin has ever been initialized on this player.
參數:
名稱 類型 描述 name
string The name of a plugin.
返回值:
boolean -Whether or not this player is using the requested plugin.
videoHeight() → {number}
-
Get video height
返回值:
number -current video height
videoTracks() → {VideoTrackList}
-
Get the VideoTrackList
videoWidth() → {number}
-
Get video width
返回值:
number -current video width
volume(percentAsDecimalopt) → {number}
-
Get or set the current volume of the media
參數:
名稱 類型 屬性 描述 percentAsDecimal
number <optional> The new volume as a decimal percent:
- 0 is muted/0%/off - 1.0 is 100%/full - 0.5 is half volume or 50%
返回值:
number -The current volume as a percent when getting
width(valueopt) → {number}
-
A getter/setter for the
Player
's width.參數:
名稱 類型 屬性 描述 value
number <optional> The value to set the `Player's width to.
返回值:
number -The current width of the
Player
when getting.- Overrides:
-
- Component#width
事件
abort
-
當音頻/視頻的加載中止時觸發。
類型:
- EventTarget~Event
canplay
-
媒體具有 HAVE_FUTURE_DATA 或更大的readyState。
類型:
- EventTarget~Event
canplaythrough
-
媒體具有HAVE_ENOUGH_DATA或更大的readyState。 這意味着整個媒體文件可以無緩沖播放。
類型:
- EventTarget~Event
componentresize
-
調整組件大小時觸發。
類型:
- EventTarget~Event
- 繼承自:
-
- Component#event:componentresize
controlsdisabled
控制條禁用時觸發。
-
類型:
- EventTarget~Event
controlsenabled
控制條啟用時觸發。
-
類型:
- EventTarget~Event
dispose
-
播放器被銷毀時調用。
類型:
- EventTarget~Event
此事件的監聽器:
- Plugin
- 覆蓋:
-
- Component#event:dispose
durationchange
播放時長被更改時調用。
-
類型:
- EventTarget~Event
此事件的監聽器:
- DurationDisplay#updateContent
- LiveDisplay#updateShowing
- RemainingTimeDisplay#updateContent
emptied
-
當前播放列表為空時觸發。
類型:
- EventTarget~Event
ended
-
當媒體資源結束時觸發 (currentTime == duration)
類型:
- EventTarget~Event
此事件監聽器:
- SeekBar#update
enterFullWindow
當運行enterFullWindow(瀏覽器不支持全屏時的全屏)方法時觸發
-
類型:
- EventTarget~Event
error
發生錯誤是觸發
-
類型:
- EventTarget~Event
exitFullWindow
當運行enterFullWindow(瀏覽器不支持全屏時的退出全屏)方法時觸發,
-
類型:
- EventTarget~Event
firstplay
-
首次播放視頻時觸發。 不是HLS規范的一部分,並且這可能不是最好的實現,所以使用謹慎。 如果你沒有理由阻止播放,使用 myPlayer.one('play'); 代替。
類型:
- EventTarget~Event
fullscreenchange
在進入和退出全屏時觸發。
-
類型:
- EventTarget~Event
此事件的監聽器:
- FullscreenToggle#handleFullscreenChange
- TextTrackDisplay#updateDisplay
loadeddata
-
當播放器已在當前播放位置數據加載完后時觸發。
類型:
- EventTarget~Event
loadedmetadata
-
瀏覽器加載完成音頻/視頻的元數據時觸發。(播放器獲取初始持續時間和尺寸信息)
類型:
- EventTarget~Event
此事件的監聽器:
- DurationDisplay#updateContent
loadstart
-
當用戶代理開始查找媒體數據時觸發。
類型:
- EventTarget~Event
此事件監聽器:
- MuteToggle#update
- PlaybackRateMenuButton#updateVisibility
- TextTrackDisplay#toggleDisplay
pause
-
每當媒體暫停時觸發
類型:
- EventTarget~Event
此事件的監聽器:
- PlayToggle#handlePause
play
-
每當發生Tech#play事件時觸發。 表示播放已開始或恢復。
類型:
- EventTarget~Event
此事件的監聽器:
- PlayToggle#handlePlay
playing
-
媒體不再被阻止播放,並已開始播放。
類型:
- EventTarget~Event
pluginsetup
-
表示插件剛剛在播放器上設置。
類型:
- Plugin~PluginEventHash
posterchange
-
當海報圖片在播放器上更改時,此事件觸發。
類型:
- EventTarget~Event
此事件的監聽器:
- PosterImage#update
progress
-
在用戶代理正在下載媒體數據時觸發。
類型:
- EventTarget~Event
此事件的監聽器:
- LoadProgressBar#update
ready
-
組件准備就緒時觸發。
類型:
- EventTarget~Event
- 繼承自:
-
- Component#event:ready
resize
-
視頻的內部尺寸更改時觸發。
類型:
- event
seeked
-
當播放器完成跳躍到新的時間時觸發
類型:
- EventTarget~Event
seeking :尋找
-
當播放器跳到新的時間時觸發
類型:
- EventTarget~Event
stalled :停頓
-
在瀏覽器嘗試獲取媒體數據時觸發,但數據不可用。
類型:
- EventTarget~Event
suspend :中斷
-
當瀏覽器故意未獲取媒體數據時觸發。
類型:
- EventTarget~Event
tap
-
當組件被點擊時觸發。
類型:
- EventTarget~Event
- 繼承自:
-
- Component#event:tap
textdata
-
當我們從tech獲取textdata事件時觸發
類型:
- EventTarget~Event
timeupdate
-
當前播放位置已更改時觸發。在播放期間,每15 - 250毫秒觸發一次,具體取決於使用的播放技術。
類型:
- EventTarget~Event
此事件的監聽器:
- CurrentTimeDisplay#updateContent
- DurationDisplay#updateContent
- RemainingTimeDisplay#updateContent
- SeekBar#update
useractive
-
類型:
- EventTarget~Event
userinactive
-
類型:
- EventTarget~Event
usingcustomcontrols
-
播放器正在使用自定義HTML控件時觸發
類型:
- EventTarget~Event
usingnativecontrols
-
播放器正在使用本地設備控件時觸發
類型:
- EventTarget~Event
volumechange
-
音量更改時觸發
類型:
- EventTarget~Event
此事件的監聽器:
- MuteToggle#update
- VolumeBar#updateARIAAttributes
waiting
-
DOM元素上的readyState更改已導致播放停止。
類型:
- EventTarget~Event
如果屬性不存在或沒有值,大多數瀏覽器將返回null。