Documentation:WebPlugin
这篇文档讲述的是 VLC media player Web plugins 和怎样在网页使用它
Introduction: Building Web pages with Video
VLC media player webplugins 是浏览器原生插件,类似于Flash和Silverlight 插件,并且能够在浏览器中播放所有 VLC media player 能读取的视频。
除了能在网页上播放视频外,你也可以用插件的高级特性来定制自定义页面,并且通过javascript来控制播放或者获取其他的信息。
目前主要有两种插件:一个是IE的Activex插件,另外一个是其他浏览器的NAAPI插件,这两个插件具有相同的特性。
在以前的旧版本中,这些插件很容易崩溃,我们强烈建议你用VLC2.0.0或者更新版本.
浏览器支持
测试了以下浏览器:
Mozilla Firefox(52版本以下,译者注) | |
Internet Explorer | |
Safari | |
Chrome | |
Konqueror | |
Opera |
测试了下面的平台 GNU/Linux, Windows and MacOS.
Embed标签树形
想把插件嵌入到网页中,用下面的 <embed>模版:
如果你在IE上用小于2.2.0版本的vlc,请用下面的<object>模版:
用<param>来给声明标签属性,下面是例子:
你可以用两个标签来兼容火狐浏览器:
必备元素
下面是<embed>标签必备属性:
- width: 指定插件的宽度.
- height: 指定插件的高度
- target (获取下面几个别名之一: mrl, filename, src): 指定视频要加载的资源url
可选元素
这些是<embed>标签的附加属性:
- autoplay, autostart: 指定插件在加载成功后是否自动播放,默认为true
- allowfullscreen (or fullscreenEnabled, fullscreen): (从VLC 2.2.0 开始) 指定是否用户可以切换到全屏模式,默认为 true
- windowless: (从VLC 2.0.6开始,只适用于火狐浏览器)在(非加速)无窗体表面绘制,允许样式叠加(css叠加,3D转换等等),默认为 false
- mute: 指定是否将视频音量初始化为静音,默认为 false
- volume: (从VLC 2.2.2开始) 用百分比来指定初始化音量,默认为100
- loop, autoloop: 指定视频结束后是否循环,默认为 false
- controls (or toolbar): 指定显示默认的控件,默认为true
- bgcolor: 指定视频播放器的背景颜色,默认为: #000000
- text: (仅仅针对MacOS的火狐)指定没有视频显示时显示的文本,默认为empty
- branding: (仅仅针对MacOS上的火狐浏览器使用小于2.2.2版本的VLC),指定是否在web插件中绘制VLC logopecifies whether VLC品牌,默认为 true
正常的DOM元素
- id: DOM id
- name: DOM name
Javascript API 描述
VLC导出很多可以用于设置和获取属性的对象,当不正确使用API的时候,会抛出一个包含异常信息的字符串。例如当你设置vlc.audio.track出界的时候。
VLC 对象
vlc插件包含下列对象s:
audio: 获取视频属性.
input: 获取输入树形.
- input.title: 获取标题树形(版本要求:vlc version >= 2.2.2, 仅支持>= 3.0.0)
- input.chapter: 获取章节属性 (版本要求:vlc version >= 2.2.2, 仅支持 >= 3.0.0)
playlist: 获取播放列表属性.
- playlist.items: 获取播放列表项的属性.
- subtitle: 获取字母属性.
video: 获取视频属性.
- video.deinterlace: 获取各行处理属性.
- video.marquee: 获取视频选取过滤属性.
- video.logo: 访问视频logo过滤器属性.
mediaDescription: 访问媒体信息属性 (版本要求: vlc version >= 2.0.2).
下面的是弃用的对象:
- log: 获取log属性(版本要求: vlc version <= 1.0.0-rc1).
- messages:获取log信息属性 (版本要求: vlc version <= 1.0.0-rc1).
- iterator: 获取log遍历属性 (版本要求: vlc version <= 1.0.0-rc1).
- message: 获取log信息属性(版本要求:vlc version <= 1.0.0-rc1).
举例
下面的js代码展示怎样使用vlc插件,然后展示怎样使用vlc插件的对象。
Root 对象
只读属性
- vlc.VersionInfo: 返回版本信息字符串
可读可写属性
- none
方法
- vlc.versionInfo(): (仅用于火狐) 返回版本信息字符串 (类似于VersionInfo属性)
- vlc.getVersionInfo(): (版本要求vlc version >= 2.2.2) 返回版本信息字符串 (类似于VersionInfo属性和versionInfo()方法)
- vlc.addEventListener(eventname, callback, bubble): (仅用于火狐) 添加一个事件监听器,包括事件名,回调函数,气泡来JS影响js处理事件的顺序(通常设置为false)
- vlc.removeEventListener(eventname, callback, bubble): (仅用于火狐) 移除一个事件监听器,包括事件名,回调函数,气泡来JS影响js处理事件的顺序(通常设置为false)
- vlc.attachEvent(eventname, callback): (仅用于Activex)添加监听器,包括事件名和回调函数
- vlc.detachEvent(eventname, callback): (仅用于Activex) 移除监听器,包括事件名和回调函数
事件
- MediaPlayerNothingSpecial: vlc处于空闲状态,等待发出命令
- MediaPlayerOpening: vlc正打开一个媒体资源
- MediaPlayerBuffering(int cache): vlc正在缓冲
- MediaPlayerPlaying: vlc正在播放媒体
- MediaPlayerPaused: vlc 处于暂停状态
- MediaPlayerStopped: vlc处于停止状态
- MediaPlayerForward: vlc的媒体正在快进 (this never gets invoked)
- MediaPlayerBackward: vlc的媒体正在回退 (this never gets invoked)
- MediaPlayerEncounteredError: vlc遇到错误,无法继续下去
- MediaPlayerEndReached: vlc到达播放列表的结尾
- MediaPlayerTimeChanged(int time): 时间变化
- MediaPlayerPositionChanged(float position): 媒体位置变化
- MediaPlayerSeekableChanged(bool seekable): 媒体搜索标记改变 (true 表示媒体可以搜索到, false表示不可搜索到)
- MediaPlayerPausableChanged(bool pausable): 媒体暂停标记改变 (true 表示媒体是暂停状态, false表示非暂停状态)
- MediaPlayerMediaChanged: (supported in vlc version >= 2.2.0) 媒体改变
- MediaPlayerTitleChanged(int title): (in vlc version < 2.2.0 only for Mozilla) 标题改变 (DVD/Blu-ray)
- MediaPlayerChapterChanged(int chapter): (supported in vlc version >= 3.0.0) 章节改变 (DVD/Blu-ray)
- MediaPlayerLengthChanged(int length): (in vlc version < 2.2.0 only for Mozilla) 长度改变
- MediaPlayerVout(int count): (supported in vlc version >= 2.2.7) 输出的视频数量改变
- MediaPlayerMuted: (supported in vlc version >= 2.2.7) 视频声音静音
- MediaPlayerUnmuted: (supported in vlc version >= 2.2.7) 视频声音开启声音
- MediaPlayerAudioVolume(float volume): (supported in vlc version >= 2.2.7) 视频声音变化
例子
下面的简短代码提供了在所有平台上注册和移除事件回调函数的方法。
Audio 对象
只读属性
- vlc.audio.count: (supported in vlc version >= 1.1.0) 返回视频数量.
读写属性
- vlc.audio.mute:是否静音的布尔值.
- vlc.audio.volume: 音频的百分比,取值为0-200.
- vlc.audio.track: (supported in vlc version > 0.8.6) 取值范围为[1-65535] ,表示播放的音轨或正在播放的音轨。值为0意味着音频将被禁用
- vlc.audio.channel: (supported in vlc version > 0.8.6) 整形值,范围为[1-5], 指示使用哪种音频通道模式,值可以是:“1 =立体声”,“2 =反向立体声”,“3 =左”,“4 =右”,“5 =杜比”。使用vlc.audio.channel检查音频信道模式设置成功了。
方法
- vlc.audio.toggleMute(): 布尔值,根据音频的上一个状态静音和非静音的切换.
- vlc.audio.description(int i): (supported in vlc version >= 1.1.0) 给每个音轨的名字。0对应于禁用和1到第一音轨。
Example
Audio Channel:
Input 对象
只读属性
- vlc.input.length: 输入文件的毫秒数,0表示VLC不能确定长度的直播流或者切片,-1表示没有输入在播放.
- vlc.input.fps: 每秒播放的帧数,浮点型 (典型值 60.0, 50.0, 23.976, 等)
- vlc.input.hasVout: 视频正在显示时返回ture,否则返回false
读写属性
- vlc.input.position: 在0 [ 1 ]之间作为浮点值给出的多媒体流项中的归一化位置
- vlc.input.time:以毫秒为单位的时间的绝对位置,此属性可用于通过流查找。
- vlc.input.state: 输入链的当前状态,取值如下的枚举数:
0 | IDLE |
1 | OPENING |
2 | BUFFERING |
3 | PLAYING |
4 | PAUSED |
5 | STOPPING |
6 | ENDED |
7 | ERROR |
Note: Test for ENDED=6 to catch end of playback. Checking for STOPPING=5 is NOT ENOUGH.
- vlc.input.rate: 浮点型的输入速度 (1.0 表示正常速度 0.5 表示一半速度, 2.0 两倍速率, etc.).
rate > 1 | fast forward |
rate = 1 | normal speed |
rate < 1 | slow motion |
方法
- none
Title 对象
只读属性
- vlc.input.title.count: (supported in vlc version >= 2.2.2)返回可以播放的标题数量
读写属性
- vlc.input.title.track: (supported in vlc version >= 2.2.2) 获取并设置标题轨道,属性值取值范围为 [0..65535],如果没有标题,则返回-1.
方法
- vlc.input.title.description(int i): (supported in vlc version >= 2.2.2) give the i-th title name.
Chapter 对象
只读属性
- vlc.input.chapter.count: (supported in vlc version >= 2.2.2) 返回当前章节的标题数量
读写方法
- vlc.input.chapter.track: (supported in vlc version >= 2.2.2) get and set the chapter track. The property takes an integer as input value [0..65535]. It returns -1 if no chapters are available.
methods
- vlc.input.chapter.description(int i): (supported in vlc version >= 2.2.2) give the i-th chapter name.
- vlc.input.chapter.countForTitle(int i): (supported in vlc version >= 2.2.2) returns the number of chapter available for a specific title.
- vlc.input.chapter.prev(): (supported in vlc version >= 2.2.2) 播放上一章节
- vlc.input.chapter.next(): (supported in vlc version >= 2.2.2) 播放下一章节
Playlist 对象
只读属性
- vlc.playlist.itemCount:返回当前播放列表中的播放项的数量 (deprecated, do not use, see Playlist items)
- vlc.playlist.isPlaying: 返回一个是否当前播放列表项在播放的布尔值
- vlc.playlist.currentItem: (supported in vlc version >= 2.2.0) 播放列表中播放项当前的索引,如果是空或者没有激活,则返回-1.
- vlc.playlist.items: 返回播放列表项集合, 见 Playlist items
读写属性
- none
方法
- vlc.playlist.add(mrl): 给播放列表添加 MRL. MRL格式为字符串格式。返回值为刚刚添加的资源在播放列表中的索引。
- vlc.playlist.add(mrl,name,options): 给播放列表添加包含name,options参数的MRL, options可取的文本参数值为:1,包含空格分隔符的字符串,类似于VLC命令行,2,字符串数组。 返回值为刚刚添加的资源在播放列表中的索引
- vlc.playlist.play(): 开始播放当前播放列表中的项目
- vlc.playlist.playItem(number): 开始播放指定标识符的项目
- vlc.playlist.pause(): 暂停播放当前播放列表中的项目
- vlc.playlist.togglePause(): 切换播放列表中播放项目的暂停状态
- vlc.playlist.stop(): 停止播放当前播放项目
- vlc.playlist.next(): 迭代到下一个播放列表项
- vlc.playlist.prev(): 迭代到上一个播放列表项
- vlc.playlist.clear(): 清空播放列表,所有的播放列表会被删除 (过时的, 不要使用, see Playlist items)
- vlc.playlist.removeItem(number): 移除播放列表中指定索引的播放项目remove the item from playlist whose identifier is number (过时的, 不要使用, see Playlist items)
Playlist items 对象
只读属性
- vlc.playlist.items.count: 当前播放列表中的项目数量
读写属性
- none
方法
- vlc.playlist.items.clear(): 清空播放列表中的项目,(注意: 如果视频正在播放,视频将不会停止播放,也就是说调用这个方法前,先停止播放)
- vlc.playlist.items.remove(number): 从播放列表中删除标识符编号的项。 (注意:这个数字是播放列表中当前的位置. 不是调用vlc.playlist.add()的返回值, 播放列表中的任何一项都可以被移除)
Subtitle 对象
只读属性
- vlc.subtitle.count: (支持版本 >= 1.1.0) 返回可以获得的字幕数量
读写属性
- vlc.subtitle.track: (supported in vlc version >= 1.1.0) get and set the subtitle track to show on the video screen. The property takes an integer as input value [1..65535]. If subtitle track is set to 0, the subtitles will be disabled.
方法
- vlc.subtitle.description(int i): (supported in vlc version >= 1.1.0) give the i-th subtitle name. 0 correspond to disable and 1 to the first subtitle.
Video 对象
只读属性
- vlc.video.width: 返回视频的宽度
- vlc.video.height: 返回视频的高度
- vlc.video.count: (supported in vlc version >= 2.2.7) returns the number of video track available.
读写属性
- vlc.video.fullscreen: 当设置为true的时候,视频全屏,当设置为false的时候,视频非全屏,输入值为布尔值。.
- vlc.video.aspectRatio: get and set the aspect ratio to use in the video screen. The property takes a string as input value. Typical values are: "1:1", "4:3", "16:9", "16:10", "221:100" and "5:4"
- vlc.video.subtitle: (supported in vlc version > 0.8.6a) get and set the subtitle track to show on the video screen. The property takes an integer as input value [1..65535]. If subtitle track is set to 0, the subtitles will be disabled.
- vlc.video.crop: get and set the geometry of the zone to crop. This is set as <width> x <height> + <left offset> + <top offset>. A possible value is: "120x120+10+10"
- vlc.video.teletext: (supported in vlc version >= 0.9.0) get and set teletext page to show on the video stream. This will only work if a teletext elementary stream is available in the video stream. The property takes an integer as input value [0..1000] for indicating the teletext page to view, setting the value to 0 means hide teletext.
- vlc.video.track: (supported in vlc version >= 2.2.7) a value between [1-65535] which indicates the video track to play or that is playing. a value of 0 means the video is/will be disabled.
方法
- vlc.video.takeSnapshot(): (支持版本 >= 0.9.0, only for ActiveX) 生成截图,并保存到桌面
- vlc.video.toggleFullscreen(): 根据上一个状态切换全屏状态
- vlc.video.toggleTeletext(): (supported in vlc version >= 0.9.0) toggle the teletext page to overlay transparent or not, based on the previous setting
- vlc.video.description(int i): (supported in vlc version >= 2.2.7) give the i-th video track name. 0 corresponds to disable and 1 to the first video track.
Deinterlace Object
readonly properties
- none
read/write properties
- none
methods
- vlc.video.deinterlace.enable("my_mode"): (supported in vlc version >= 1.1.0) enable deinterlacing with my_mode. You can enable it with "blend", "bob", "discard", "linear", "mean", "x", "yadif" or "yadif2x" mode. Enabling too soon deinterlacing may cause some problems. You have to wait that all variable are available before enabling it.
- vlc.video.deinterlace.disable(): (supported in vlc version >= 1.1.0) disable deinterlacing.
Marquee Object
readonly properties
- none
read/write properties
- vlc.video.marquee.text: (supported in vlc version >= 1.1.0) display my text on the screen.
- vlc.video.marquee.color: (supported in vlc version >= 1.1.0) change the text color. val is the new color to use (WHITE=0x000000, BLACK=0xFFFFFF, RED=0xFF0000, GREEN=0x00FF00, BLUE=0x0000FF...).
- vlc.video.marquee.opacity: (supported in vlc version >= 1.1.0) change the text opacity, val is defined from 0 (completely transparent) to 255 (completely opaque).
- vlc.video.marquee.position: (supported in vlc version >= 1.1.0) change the text position ("center", "left", "right", "top", "top-left", "top-right", "bottom", "bottom-left", "bottom-right").
- vlc.video.marquee.refresh: (supported in vlc version >= 1.1.0) change the marquee refresh period.
- vlc.video.marquee.size: (supported in vlc version >= 1.1.0) val define the new size for the text displayed on the screen. If the text is bigger than the screen then the text is not displayed.
- vlc.video.marquee.timeout: (supported in vlc version >= 1.1.0) change the timeout value. val is defined in ms, but 0 value correspond to unlimited.
- vlc.video.marquee.x: (supported in vlc version >= 1.1.0) change text abscissa.
- vlc.video.marquee.y: (supported in vlc version >= 1.1.0) change text ordinate.
methods
- vlc.video.marquee.enable(): (supported in vlc version >= 1.1.0) enable marquee filter.
- vlc.video.marquee.disable(): (supported in vlc version >= 1.1.0) disable marquee filter.
Some problems may happen (option like color or text will not be applied) because of the VLC asynchronous functioning. To avoid it, after enabling marquee, you have to wait a little time before changing an option. But it should be fixed by the new vout implementation.
NOTE: [1]
Logo Object
readonly properties
- none
read/write properties
- vlc.video.logo.opacity: (supported in vlc version >= 1.1.0) change the picture opacity, val is defined from 0 (completely transparent) to 255 (completely opaque).
- vlc.video.logo.position: (supported in vlc version >= 1.1.0) change the text position ("center", "left", "right", "top", "top-left", "top-right", "bottom", "bottom-left", "bottom-right").
- vlc.video.logo.delay: (supported in vlc version >= 1.1.0) display each picture for a duration of 1000 ms (default) before displaying the next picture.
- vlc.video.logo.repeat: (supported in vlc version >= 1.1.0) number of loops for picture animation (-1=continuous, 0=disabled, n=n-times). The default is -1 (continuous).
- vlc.video.logo.x: (supported in vlc version >= 1.1.0) change the x-offset for displaying the picture counting from top-left on the screen.
- vlc.video.logo.y: (supported in vlc version >= 1.1.0) change the y-offset for displaying the picture counting from top-left on the screen.
methods
- vlc.video.logo.enable(): (supported in vlc version >= 1.1.0) enable logo video filter.
- vlc.video.logo.disable(): (supported in vlc version >= 1.1.0) disable logo video filter.
- vlc.video.logo.file("file.png"): (supported in vlc version >= 1.1.0) display my file.png as logo on the screen.
Some problems may happen because of the VLC asynchronous functioning. To avoid it, after enabling logo video filter, you have to wait a little time before changing an option. But it should be fixed by the new vout implementation.
MediaDescription Object
readonly properties
- vlc.mediaDescription.title: (supported in vlc version >= 2.0.2) returns title meta information field.
- vlc.mediaDescription.artist: (supported in vlc version >= 2.0.2) returns artist meta information field.
- vlc.mediaDescription.genre: (supported in vlc version >= 2.0.2) returns genre meta information field.
- vlc.mediaDescription.copyright: (supported in vlc version >= 2.0.2) returns copyright meta information field.
- vlc.mediaDescription.album: (supported in vlc version >= 2.0.2) returns album meta information field.
- vlc.mediaDescription.trackNumber: (supported in vlc version >= 2.0.2) returns trackNumber meta information field.
- vlc.mediaDescription.description: (supported in vlc version >= 2.0.2) returns description meta information field.
- vlc.mediaDescription.rating: (supported in vlc version >= 2.0.2) returns rating meta information field.
- vlc.mediaDescription.date: (supported in vlc version >= 2.0.2) returns date meta information field.
- vlc.mediaDescription.setting: (supported in vlc version >= 2.0.2) returns setting meta information field.
- vlc.mediaDescription.URL: (supported in vlc version >= 2.0.2) returns URL meta information field.
- vlc.mediaDescription.language: (supported in vlc version >= 2.0.2) returns language meta information field.
- vlc.mediaDescription.nowPlaying: (supported in vlc version >= 2.0.2) returns nowPlaying meta information field.
- vlc.mediaDescription.publisher: (supported in vlc version >= 2.0.2) returns publisher meta information field.
- vlc.mediaDescription.encodedBy: (supported in vlc version >= 2.0.2) returns encodedBy meta information field.
- vlc.mediaDescription.artworkURL: (supported in vlc version >= 2.0.2) returns artworkURL meta information field.
- vlc.mediaDescription.trackID: (supported in vlc version >= 2.0.2) returns trackID meta information field.
read/write properties
- none
methods
- none
DEPRECATED APIs
DEPRECATED: Log object
- CAUTION: For security concern, VLC 1.0.0-rc1 is the latest (near-to-stable) version in which this object and its children are supported.
This object allows accessing VLC main message logging queue. Typically this queue capacity is very small (no nore than 256 entries) and can easily overflow, therefore messages should be read and cleared as often as possible.
readonly properties
- vlc.log.messages: returns the message collection, see Messages object
read/write properties
- vlc.log.verbosity: write number [-1,0,1,2,3] for changing the verbosity level of the log messages; messages whose verbosity is higher than set will be not be logged in the queue. The numbers have the following meaning: -1 disable, 0 info, 1 error, 2 warning, 3 debug.
methods
- none
DEPRECATED: Messages object
- CAUTION: For security concern, VLC 1.0.0-rc1 is the latest (near-to-stable) version in which this object and its children are supported.
readonly properties
- messages.count: returns number of messages in the log
read/write properties
- none
methods
- messages.clear(): clear the current log buffer. It should be called as frequently as possible to not overflow the message queue. Call this method after the log messages of interest are read.
- messages.iterator(): creates and returns an iterator object, used to iterate over the messages in the log. Don't clear the log buffer while holding an iterator object.
DEPRECATED: Messages Iterator object
- CAUTION: For security concern, VLC 1.0.0-rc1 is the latest (near-to-stable) version in which this object and its children are supported.
readonly properties
- iterator.hasNext: returns a boolean that indicates whether vlc.log.messages.next() will return the next message.
read/write properties
- none
methods
- iterator.next(): returns the next message object in the log, see Message object
DEPRECATED: Message subobject
- CAUTION: For security concern, VLC 1.0.0-rc1 is the latest (near-to-stable) version in which this object and its children are supported.
- message.severity: number that indicates the severity of the log message (0 = info, 1 = error, 2 = warning, 3 = debug)
- message.name: name of VLC module that printed the log message (e.g: main, http, directx, etc...)
- message.type: type of VLC module that printed the log message (eg: input, access, vout, sout, etc...)
- message.message: the message text
This page is part of official VLC media player Documentation (User Guide • Streaming HowTo • Hacker's Guide • Modules) Please read the Documentation Editing Guidelines before you edit the documentation |
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |