Converting a regular Youtube 'link' into an embedded video

前端 未结 10 1835
别那么骄傲
别那么骄傲 2021-01-30 02:25

My goal: I am trying to allow users to embed a link to a Youtube video in my site, while giving me control over the player\'s settings.

I would like to do this by only a

10条回答
  •  醉话见心
    2021-01-30 03:17

    This is what youtube uses:

    
    

    Then just use a regexp to change the link from:

    http://www.youtube.com/watch?v=zb-gmJVW5lw
    

    into:

    http://www.youtube.com/embed/zb-gmJVW5lw
    

    Here's a proof of concept regexp for matching regular youtube links:

    • http://rubular.com/r/Fitt7PPJW1

    And here's a proof of concept regexp for matching youtu.be links:

    • http://rubular.com/r/MTgd9nXzFA

    Note that the embed url can also be loaded in the browser which opens a page where the video is fullscreen.

提交回复
热议问题