【问题标题】:Youtube upload widget timeYoutube 上传小部件时间
【发布时间】:2013-06-09 15:48:35
【问题描述】:

是否可以在有限的时间内(例如 3 分钟)和上传此视频后使用有用的 Youtube 上传小工具来捕获网络摄像头视频?

谢谢!这是我的代码:

    <script>
      // 2. Asynchronously load the Upload Widget and Player API code.
      var tag = document.createElement('script');
      tag.src = "https://www.youtube.com/iframe_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

      // 3. Define global variables for the widget and the player.
      //    The function loads the widget after the JavaScript code
      //    has downloaded and defines event handlers for callback
      //    notifications related to the widget.
      var widget;
      var player;
      function onYouTubeIframeAPIReady() {
        widget = new YT.UploadWidget('widget', {
          width: 500,
          events: {
            'onUploadSuccess': onUploadSuccess,
            'onProcessingComplete': onProcessingComplete
          }
        });
      }

      // 4. This function is called when a video has been successfully uploaded.
      function onUploadSuccess(event) {
        alert('Video ID ' + event.data.videoId + ' was uploaded and is currently being processed.');
      }

      // 5. This function is called when a video has been successfully
      //    processed.
      function onProcessingComplete(event) {
        player = new YT.Player('player', {
          height: 390,
          width: 640,
          videoId: event.data.videoId,
          events: {}
        });
      }
    </script>

【问题讨论】:

    标签: youtube google-api youtube-api


    【解决方案1】:

    例如,我通过发送 ajax 请求来检查视频处理后的视频长度。

         function onProcessingComplete(event) {
                $.ajax({
                url:'http://gdata.youtube.com/feeds/api/videos/'+event.data.videoId+'?v=2&alt=json',
                success:function(data){
                    var sec = data['entry']['media$group']['yt$duration']['seconds'];
                    if(sec < 60){
                        var errorText = "Video must be long at least 1 min";
                        showError(errorText);
                    }else{
    //OK                    
                    }
                },
                error: function (xhr, textStatus, thrownError) {
                    showError("Failed to make request.");
                },
                dataType: 'json'
            });
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-11
      • 1970-01-01
      • 2015-10-05
      • 2013-11-09
      • 2018-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多