我无法使用Angular播放Azure Media Services视频。我有一个简单的html页面:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<link href="//amp.azure.net/libs/amp/1.3.0/skins/amp-default/azuremediaplayer.min.css" rel="stylesheet">
<script src="//amp.azure.net/libs/amp/1.3.0/azuremediaplayer.min.js"></script>
</head>
<body>
<video id="azuremediaplayer" class="azuremediaplayer amp-default-skin amp-big-play-centered" controls autoplay width="640" height="400" poster="" data-setup='{"nativeControlsForTouch": false}' tabindex="0">
<source src="http://amssamples.streaming.mediaservices.windows.net/91492735-c523-432b-ba01-faba6c2206a2/AzureMediaServicesPromo.ism/manifest" type="application/vnd.ms-sstr+xml" />
<p class="amp-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video</p>
</video>
</body>
</html>
但是当我向Angular组件添加完全相同的视频标签时,它只是一个不播放我视频的块框。
我在index.html页面中添加了以下内容:
<link href="//amp.azure.net/libs/amp/1.3.0/skins/amp-default/azuremediaplayer.min.css" rel="stylesheet">
<script src="//amp.azure.net/libs/amp/1.3.0/azuremediaplayer.min.js"></script>
我将视频标记添加到我的组件html页面:
<video id="azuremediaplayer" class="azuremediaplayer amp-default-skin amp-big-play-centered" controls autoplay width="640" height="400" poster="" data-setup='{"nativeControlsForTouch": false}' tabindex="0">
<source src="http://amssamples.streaming.mediaservices.windows.net/91492735-c523-432b-ba01-faba6c2206a2/AzureMediaServicesPromo.ism/manifest" type="application/vnd.ms-sstr+xml" />
<p class="amp-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video</p>
</video>
这是最简单的设置,只有一个模块和一个组件,页面上没有其他内容。我使用Angular的最新快速入门示例创建了该项目,因此我应该拥有最新的软件包。我错过了什么?
答案 0 :(得分:3)
我找到了答案。我需要从Microsoft下载typescript定义文件:https://amp.azure.net/libs/amp/latest/docs/
我把它放在我的typings文件夹中,并为我的视频模块添加了参考路径:
/// <reference path="../../typings/azuremediaplayer.d.ts" />
您仍然需要将azure媒体播放器lib文件添加到index.html:
<link href="//amp.azure.net/libs/amp/1.8.0/skins/amp-default/azuremediaplayer.min.css" rel="stylesheet">
<script src="//amp.azure.net/libs/amp/1.8.0/azuremediaplayer.min.js"></script>
我有一个非常简单的组件,只显示视频。
html:
<video
id="vid1"
class="azuremediaplayer amp-default-skin"
autoplay controls width="640" height="400"
poster="poster.jpg" >
<p class="amp-no-js">
To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video
</p>
</video>
组件代码:
import { Component, ElementRef, OnInit } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'my-azure-media-player',
templateUrl: 'azure-media-player.component.html'
})
export class AzureMediaPlayerComponent implements OnInit {
constructor(private elRef: ElementRef) {}
ngOnInit(): void {
var myPlayer = amp('vid1');
console.log(myPlayer.currentTechName());
myPlayer.autoplay(true);
myPlayer.controls(true);
myPlayer.src({
type: "application/vnd.ms-sstr+xml",
src: "//amssamples.streaming.mediaservices.windows.net/91492735-c523-432b-ba01-faba6c2206a2/AzureMediaServicesPromo.ism/manifest"
});
}
}
从这里你可以玩设置。