【问题标题】:Video.js with Mux does not play video带有 Mux 的 Video.js 不播放视频
【发布时间】:2021-06-17 20:13:53
【问题描述】:

我的网站上有一个视频库页面,我需要在此页面上显示上传到 MUX 服务器的视频。我在通过这个库播放视频时遇到问题。文档:https://docs.mux.com/guides/video/playback-videojs-with-mux。 代码示例:

<template>
  <div>
    <div class="video_conteiner_iframe" v-if="video.status === 'ready' && open">
      <iframe
        v-if="video.api_type === '1'"
        :ref="`video_${video.id}`"
        :src="`https://cdn.jwplayer.com/players/${video.key}-hSb3JUAg.html`"
        class="video"
        frameborder="0"
        scrolling="auto"
        :title="video.name"
        allowfullscreen
      />
      <video
        v-else
        :id="video.id"
        class="video-js"
        controls
        preload="auto"
        width="100%"
      >
        <source :src="video.key" type="video/mux" />
      </video>
    </div>
    <div
      v-if="video.status === 'ready' && !open"
      class="img_body"
      @click="openVideo(video.id, video.key)"
    >
      <div class="play_video">
        <div class="play_block" />
      </div>
      <img
        v-if="video.api_type === '1'"
        class="video"
        :src="`https://cdn.jwplayer.com/thumbs/${video.key}-640.jpg`"
        :alt="`${video.key}`"
      >
      <img
        v-else
        class="video"
        :src="`https://image.mux.com/${video.key}/thumbnail.png`"
        :alt="`${video.key}`"
      >
    </div>
  </div>
</template>

<script>
import videojs from '@mux/videojs-kit';
import '@mux/videojs-kit/dist/index.css';

export default {
  name: 'vm-video-play',
  props: {
    video: { type: Object, required: true }
  },
  data() {
    return {
      open: false
    };
  },
  methods: {
    openVideo(id, key) {
      if (window.innerWidth < 1000 && this.$route.name === 'seller-catalogue-id') {
        console.log('modal');
      } else {
        this.open = true;
      }
    }
  }
};
</script>

video.key === PLAYBACK_ID

如果您尝试播放一些 mp4 视频(例如,https://www.w3schools.com/html/mov_bbb.mp4)而不是 MUX 视频文件,那么它可以正常工作,但不会显示 MUX 视频文件。

【问题讨论】:

  • 嘿,我从没用过这个。您能否以某种方式为我们提供一个工作示例?
  • 另外,您能否删除问题中与(mux + video 标签)无关的所有内容?他们可能会干扰,我们只想关注这 2 个。另外,你确定最后你会得到这样的东西吗? &lt;source src="d1231asd" /&gt;?

标签: vue.js nuxt.js html5-video video.js


【解决方案1】:

我自己尝试过,您基本上需要安装 @mux/videojs-kit 并按照文档中的建议提供您的 env 变量。

这是它的样子

<template>
  <div>
    <video id="my-player" 
      class="video-js vjs-16-9" 
      controls 
      preload="auto" 
      width="100%">
    </video>
  </div>
</template>

<script>
import videojs from '@mux/videojs-kit'
import '@mux/videojs-kit/dist/index.css'

export default {
  mounted() {
    const player = videojs('my-player', {
      timelineHoverPreviews: true,
      plugins: {
        mux: {
          debug: false,
          data: {
            env_key: 'gjXXXXXX', // pass your own personal key in an `.env` file
            video_title: 'Example Title',
          },
        },
      },
    })

    player.src({
      // this is the public playback ID without the 'https://stream.mux.com/' prefix
      src: 'yF8oeOw01qAqbrlQ00TdmHOR02U801P015pawn4uQRbvWHgo.m3u8',
      type: 'video/mux',
    })
  },
}
</script>

到目前为止运行良好

【讨论】:

  • 我尝试和你做同样的事情,但它给了我一个错误:'提供的元素或 ID 无效。 (videojs) '
  • @АнтонГоловко 您可能打错了video 标签(或它的类),或者您的ID 错误。也许更新您的代码或双重/三重检查您身边的问题。
猜你喜欢
  • 2012-07-17
  • 1970-01-01
  • 2015-04-18
  • 2013-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-23
  • 1970-01-01
相关资源
最近更新 更多