如果获得以下YouTube视频链接:
https://youtu.be/PqkaBUmJpq8?list=PLmmPGQQTKzSZSPd3pa6q9UQ-PkeCx1fam
是否可以从YouTube iFrame API中使用video id
中提取<md-grid-list cols="4" md-cols-sm="2" md-cols-md="4" md-cols-lg="8" md-cols-gt-lg="12" rowHeight="250px" gutterSize="20px">
<md-grid-tile *ngFor="let data of myData">
<md-card [style.background]="'lightBlue'" [style.minHeight]="'100%'" >
<md-card-title></md-card-title>
<md-card-title></md-card-title>
<md-card-content>
<h2>
</h2>
</md-card-content>
</md-card>
</md-grid-tile>
</md-grid-list>
?
答案 0 :(得分:0)
刚刚写完这个函数:
function extractVideoIdFromYouTubeUrl (url) {
var stepOne = url.split('?')[0];
var stepTwo = stepOne.split('/');
var videoId = stepTwo[stepTwo.length-1];
return videoId;
}
答案 1 :(得分:0)
function extractVideoIdFromYouTubeUrl(url) {
let id = url.substring(url.lastIndexOf("v=")+2,url.length);
return id;
}
此解决方案假定视频ID位于URL的末尾。 我只建议将它用于我需要的简单情况,where the user can't enter a URL, and the Youtube Player API creates a limited possible set of URLs。