如何从Angularjs URL显示YouTube的缩略图缩略图、Angularjs、URL、YouTube

由网友(生活就是要屁颠屁颠的过)分享简介:我刚开始使用angularjs,我想从YouTube视频的网址显示YouTube的缩略图...有没有显示视频缩略图,当人们在输入网址插入,然后点击按钮的方式,I just start to using angularjs and I want to display youtube thumbnail image fr...

我刚开始使用angularjs,我想从YouTube视频的网址显示YouTube的缩略图...有没有显示视频缩略图,当人们在输入网址插入,然后点击按钮的方式,

I just start to using angularjs and I want to display youtube thumbnail image from the youtube video url ... is there a way to display video thumbnail when people insert url in input and then click the button,

PLUNKER

http://plnkr.co/edit/9SBbTaDONuNXvOQ7lkWe?p=$p$ PVIEW

推荐答案

的Youtube提供其视频的默认缩略图。

Youtube provide default thumbnail image of its video.

您可以使用下面的示例URL创建缩略图。

You can use below sample URL to create thumbnail image.

https://p.xsw88.cn/allimgs/daicuo/20230913/1168.png.jpg

您需要从给定的URL和功放搜索ID;创建网址像上面会给你的缩略图。

Where you need to search id from the given url & create url like above will give you thumbnail image.

控制器

app.controller('MyCtrl', ['$scope',
  function($scope) {
    $scope.inputs = [];

    $scope.addInput = function() {
      $scope.inputs.push({
        field: ''
      });
    }

    $scope.removeInput = function(index) {
      $scope.inputs.splice(index, 1);
    }

    $scope.set2 = function($ayd) {
      var thumb = getParameterByName(this.input.ayd, 'v'),
        url = 'https://p.xsw88.cn/allimgs/daicuo/20230913/1169.png.jpg';
      this.thumb = url
    }

    function getParameterByName(url, name) {
      name = name.replace(/[[]/, "[").replace(/[]]/, "]");
      var regex = new RegExp("[?&]" + name + "=([^&#]*)"),
        results = regex.exec(url);
      return results === null ? "" : decodeURIComponent(results[1].replace(/+/g, " "));
    }
  }
]);

有这样做的方法很多,可以参考 从这里

There many ways to do this, you can refer from here

工作Plunkr 这里

阅读全文

相关推荐

最新文章