mediaelement / mediaelement-plugins

Plugins for the main mediaelement project
405 stars 137 forks source link

How to import plugins into vue component? #168

Closed dannyconnolly closed 4 years ago

dannyconnolly commented 4 years ago

I have a laravel vue app and I'm not sure how to use the plugins from NPM. The player works but just not sure how to implement the plugins. Below is the code I'm using for the component. Do I just import everything from mediaelement-plugins?

<template>
  <video
    id="video__player"
    width="640px"
    height="480px"
    v-bind:poster="video.image"
    preload="none"
    controls
    playsinline
    webkit-playsinline
  >
    <source
      type="video/mp4"
      v-bind:src="file"
    />

    <a
      target="_blank"
      v-bind:title="video.title"
      v-bind:href="file"
    >
      <img
        v-bind:src="'video.image"
        v-bind:alt="video.title"
      />
    </a>
  </video>
</template>

<script>
import "mediaelement";
import "mediaelement-plugins";
import "mediaelement/src/css/mediaelementplayer.css";

export default {
  props: {
    video: Object,
    part: Number,
    file: String
  },
  data: () => ({
    player: null,
    features: [
      "ads",
      "vast",
      "playpause",
      "current",
      "progress",
      "duration",
      "markers",
      "volume",
      "fullscreen"
    ]
  }),
  mounted() {
    this.player = new MediaElementPlayer(this.$el, {
      pluginPath: "https://cdnjs.com/libraries/mediaelement/",
      features: this.features,
      adsPrerollAdEnableSkip: true,
      adsPrerollAdSkipSeconds: 5,
      vastAdTagUrl: "VASTTAGHERE",
      vastAdsType: "vast",
      success: function(mediaElement, originalNode, instance) {
        //   console.log(mediaElement, originalNode, instance);
      }
    });
  }
};
</script>
jaapmarcus commented 4 years ago

See https://github.com/mediaelement/mediaelement/issues/2710 or https://github.com/nuxt/nuxt.js/issues/1992

how ever please be aware that the current preroll only support flash and native html video's no vpaidjs / VMAP supported .