@160over90/vue-plyr-video 中文文档教程

发布于 5年前 浏览 23 项目主页 更新于 3年前

PlyrVideo

Features

Plyr 视频播放器的 Vue 包装器。 只支持视频播放器,不支持音频播放器。

如果你没有 yarn,你可以在这里下载它。

Instructions for global registration

yarn add @160over90/vue-plyr-video

包含在 main.js(app 入口点)

import PlyrVideo from '@160over90/vue-plyr-video';

Vue.use(PlyrVideo);

Instructions for editing this package

yarn install

Compiles and hot-reloads for development

yarn run serve

Examples

中的最简单的例子。 使用所有默认设置为链接中的视频创建播放器。

<PlyrVideo videoUrl="https://www.youtube.com/watch?v=WaawXXqXExo"/>

当 Plyr 视频准备就绪时使用事件触发方法的示例。

<PlyrVideo
  videoUrl="https://www.youtube.com/watch?v=WaawXXqXExo"
  @ready="ready"
/>
...
methods: {
  ready() {
    // Do something
  },
},

与之前访问 DOM 事件的示例类似。 要访问原始 DOM 事件,请使用特殊的 $event 变量。

<PlyrVideo
  videoUrl="https://www.youtube.com/watch?v=WaawXXqXExo"
  @ready="ready($event)"
/>
...
methods: {
  ready(event) {
    console.log('ready', event);
  },
},

Events

所有 Plyr 事件都已实施。 如需事件列表,请参考 Plyr 文档

Props

所有 Plyr 选项都可以作为道具传递。 有关选项列表,请参考 Plyr 文档。 以下是所有不是 Plyr 选项的道具。

videoUrl(字符串,必需) 视频的 URL。 选项包括 YouTube 网址、Vimeo 网址或自托管网址/路径。

海报(字符串,默认值:未定义) 海报图片的 URL。

类型(字符串,默认值:未定义) 对于不是使用 Vimeo 或 YouTube 托管的视频,这是视频元素上的类型属性。 如果适用,建议使用此选项。 示例:'video/mp4'

background(布尔值,默认值:false) 一组预设,可轻松将视频用作背景视频。 删除所有控件,启用自动播放,禁用点击播放,完全禁用全屏功能,启用循环,并且视频静音。 具体设置如下,不能被覆盖。

controls: [],
autoplay: true,
clickToPlay: false,
fullscreen: { enabled: false, fallback: false, iosNative: false },
loop: true,
muted: true,

Methods

大多数 Plyr 方法已经实现。 有关方法列表,请参考 Plyr 文档。 使用下面详述的全屏方法名称有一些变化。 此外,回调方法尚未实现。 相反,使用 Vue 事件挂钩来实现相同的功能。

fullscreen.enter() 方法可以与 enterFullscreen() 一起使用。 fullscreen.exit() 方法可以与 exitFullscreen() 一起使用。 fullscreen.toggle() 方法可以与 toggleFullscreen() 一起使用。

Polyfill

Plyr 使用的 ES6 尚未在所有浏览器中得到支持。 这意味着某些功能需要填充才能可用,否则您会遇到问题。 我们选择不给 90% 支持这些功能的用户增加额外的 JS 负担,而是让 polyfilling 留给你根据你的需要来解决。 我发现的最简单的方法是使用 polyfill.io,它提供基于用户代理的 polyfill。 这是演示使用的方法。

<script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>

License

麻省理工学院

PlyrVideo

Features

Vue wrapper for the Plyr video player. Only supports the video player and not the audio player.

If you do not have yarn you can download it here.

Instructions for global registration

yarn add @160over90/vue-plyr-video

Include in main.js (app entry point)

import PlyrVideo from '@160over90/vue-plyr-video';

Vue.use(PlyrVideo);

Instructions for editing this package

yarn install

Compiles and hot-reloads for development

yarn run serve

Examples

The simplest example. Creates a player for the video in the link using all the default settings.

<PlyrVideo videoUrl="https://www.youtube.com/watch?v=WaawXXqXExo"/>

An example using an event to trigger a method when the Plyr video is ready.

<PlyrVideo
  videoUrl="https://www.youtube.com/watch?v=WaawXXqXExo"
  @ready="ready"
/>
...
methods: {
  ready() {
    // Do something
  },
},

Similar to the previous example with access to the DOM event. To get access to the original DOM event, use the special $event variable.

<PlyrVideo
  videoUrl="https://www.youtube.com/watch?v=WaawXXqXExo"
  @ready="ready($event)"
/>
...
methods: {
  ready(event) {
    console.log('ready', event);
  },
},

Events

All Plyr events have been implemented. For a list of events, reference the Plyr documentation.

Props

All Plyr options can be passed as a prop. For a list of options, reference the Plyr documentation. Below are all props that aren't Plyr options.

videoUrl (String, Required) The URL for a video. Options are a YouTube URL, Vimeo URL, or a self-hosted URL/path.

poster (String, Default: undefined) The URL for the poster image.

type (String, Default: undefined) For videos not hosted using Vimeo or YouTube, this is the type attribute on the video element. If applicable, this option is recommended. Example: 'video/mp4'

background (Boolean, Default: false) A group of presets to easily use a video as a background video. All controls are removed, autoplay is enabled, click to play is disabled, fullscreen functionality is completely disabled, looping is enabled, and the video is muted. Specific settings are below and cannot be overridden.

controls: [],
autoplay: true,
clickToPlay: false,
fullscreen: { enabled: false, fallback: false, iosNative: false },
loop: true,
muted: true,

Methods

Most Plyr methods have been implemented. For a list of methods, reference the Plyr documentation. There are some changes to using the fullscreen method names detailed below. Also, the callback methods have not been implemented. Instead, use the Vue event hooks to achieve the same functionality.

The method fullscreen.enter() can be used with enterFullscreen(). The method fullscreen.exit() can be used with exitFullscreen(). The method fullscreen.toggle() can be used with toggleFullscreen().

Polyfill

Plyr uses ES6 which isn't supported in all browsers quite yet. This means some features will need to be polyfilled to be available otherwise you'll run into issues. We've elected to not burden the 90% of users that do support these features with extra JS and instead leave polyfilling to you to work out based on your needs. The easiest method I've found is to use polyfill.io which provides polyfills based on user agent. This is the method the demo uses.

<script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>

License

MIT

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文