How to record video and upload to Youtube from your website

Youtube Video upload widget

This is the simplest method of using Youtube Widget in your website or blog. To upload vidoes to youtube. The code is as follows:

<div id="widget" style="width:355px;"></div>
<script>
      var tag = document.createElement('script');
      tag.src = "https://www.youtube.com/iframe_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
      var widget;
      var player;
      function onYouTubeIframeAPIReady() {
        widget = new YT.UploadWidget('widget', {
          width: 500,
          events: {
            'onUploadSuccess': onUploadSuccess,
            'onProcessingComplete': onProcessingComplete
          }
        });
      }

      function onUploadSuccess(event) {
alert(event.data.videoId);
//window.location.href='addtoplaylist.php?v='+event.data.videoId;
      }
      function onProcessingComplete(event) {
        player = new YT.Player('player', {
          height: 390,
          width: 640,
          videoId: event.data.videoId,
          events: {}
        });
      }
    </script>
This code needs to be pasted in your html or php and its ready to be used. If you want to do something more to the video like adding to playlist or sending the link to someone then. You have to modify the content inside the onUploadSuccess. If you see above I have an alert function to pop up the video id of the youtube video. So the link for the youtube video will be http://youtube.com/?v=[videoId] . The commented line is used to send the video id to a page addtoplaylist.php which needs to be uncommented to work. And also addtoplaylist.php file should use the video_id for further actions required which is in the variable $_GET['v'].

Comments

Popular posts from this blog

Automate file upload in Selenium IDE

How To Install and Configure Nextcloud