Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for Vue 3 Support in Plyr.io #2850

Open
esg-ammar-alrez opened this issue Feb 16, 2025 · 2 comments
Open

Request for Vue 3 Support in Plyr.io #2850

esg-ammar-alrez opened this issue Feb 16, 2025 · 2 comments

Comments

@esg-ammar-alrez
Copy link

Dear Plyr.io Team,

I hope you are doing well.

I am currently working on a project using Vue 3 and would love to integrate Plyr.io for media playback. However, I couldn't find clear documentation on Vue 3 compatibility.

Could you please confirm if Plyr.io officially supports Vue 3? If not, are there any plans for future support?

@TwT-L
Copy link

TwT-L commented Feb 17, 2025

// components/videoplayer/VideoPlayer.vue
<script setup>
import Plyr from 'plyr';
import 'plyr/dist/plyr.css';
import { ref, defineProps, onMounted, onUnmounted } from 'vue';

const props = defineProps({
  src: String,
});
const player = ref();
const playerId = `video-player-${Math.random().toString(36).substr(2, 9)}`; // generate unique ID

const createPlayer = (source, cover) => {
  player.value = new Plyr(`#${playerId}`, {
    controls: [
      'play-large',
      'play',
      'progress',
      'current-time',
      'mute',
      'volume',
      'captions',
      'fullscreen',
    ],
  });
  player.value.on('enterfullscreen', () => {
    console.log('enterfullscreen');
  });
  player.value.on('exitfullscreen', () => {
    console.log('exitfullscreen');
  });
};

onMounted(() => {
  createPlayer();
});
onUnmounted(() => {
  player.value.destroy();
});
</script>
<template>
  <video
    :src="src"
    :id="playerId"
    crossorigin
    playsinline
    data-plyr-config="{}"
  ></video>
</template>

@esg-ammar-alrez
Copy link
Author

esg-ammar-alrez commented Feb 19, 2025

@TwT-L

how i can pass provider for (youtube or vimeo )
i am tried but i am fail
it work by ifram
thank you


<script setup>
import { ref, defineProps, onMounted, onUnmounted, watch } from 'vue';
import Plyr from 'plyr';
import 'plyr/dist/plyr.css';

const props = defineProps({
  src: String, // YouTube video ID (e.g., "bTqVqk7FSmY")
});

const player = ref(null);
const playerElement = ref(null); // Reference to the video element

const createPlayer = () => {
  if (player.value) {
    player.value.destroy();
  }

  if (playerElement.value) {
    player.value = new Plyr(playerElement.value, {
      controls: [
        'play-large',
        'play',
        'progress',
        'current-time',
        'mute',
        'volume',
        'captions',
        'fullscreen',
      ],
      youtube: {
        noCookie: true, // Use YouTube no-cookie mode
        rel: 0, // Prevent showing related videos at the end
        modestbranding: 1, // Minimal branding
      },
    });

    if (props.src) {
      player.value.source = {
        type: 'video',
        sources: [
          {
            src: props.src,
            provider: 'youtube',
          },
        ],
      };
    }
  }
};

onMounted(() => {
  createPlayer();
});

onUnmounted(() => {
  if (player.value) {
    player.value.destroy();
  }
});

// Watch for `src` changes and reload the video
watch(() => props.src, (newSrc) => {
  if (newSrc && player.value) {
    player.value.source = {
      type: 'video',
      sources: [
        {
          src: newSrc,
          provider: 'youtube',
        },
      ],
    };
  }
});
</script>

<template>
  <div>
    <div class="plyr__video-embed" ref="playerElement">
      <iframe
          :src="`https://www.youtube.com/embed/${src}`"
          allowfullscreen
          allow="autoplay; encrypted-media"
      ></iframe>
    </div>
  </div>
</template>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants