How can I embed private youtube video in my site?

后端 未结 6 1108
名媛妹妹
名媛妹妹 2020-12-24 06:30

I have to display some private Youtube videos in my blog. I cannot embed them directly. What should I use to do this.

6条回答
  •  离开以前
    2020-12-24 07:06

    I didn't try this workaround yet but theoritcally it should work, you need to use YouTube API V 3 and follow the below steps:

    1. Set the video's privacy status to unlisted through API.
    2. Embed the video via API in a hidden div.
    3. Use onPlayerStateChange event to check if the video player is currently playing the video, use the API to pause the video at the first second.
    4. If the state changed to "playing" then send an AJAX request to a server side script to revert the the video's privacy status to be private, once you get a confirmation message display the video and use the API to play it.

    This should keep the video private even if the user copy & paste the URL in another tab, s/he should get a message that the video is private.

    Here is a reference to YouTube iFrame API, which gives you an example for onPlayerStateChange Event

    Please refer to this link to change the privacy status via API v 3

提交回复
热议问题