[英]Angular 2 Azure Media Services Video Playback
I cannot play an Azure Media Services video using Angular. 我无法使用Angular播放Azure Media Services视频。 I have a simple html page that works:
我有一个简单的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>
But when I add the exact same video tag to an Angular component, it is just a block box that doesn't play my video. 但是,当我将完全相同的视频标签添加到Angular组件时,它只是一个不播放视频的块框。
I added the following to my index.html page: 我在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>
And I added the video tag to my component html page: 然后将视频标签添加到我的组件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>
It's the simplest possible setup, with only one module and one component, and nothing else on the page. 这是最简单的设置,只有一个模块和一个组件,页面上没有其他内容。 I created the project using Angular's latest quickstart sample, so I should have the latest packages.
我使用Angular的最新快速入门示例创建了该项目,因此我应该拥有最新的软件包。 What am I missing?
我想念什么?
I found the answer to this. 我找到了答案。 I needed to download the typescript definitions file from Microsoft: https://amp.azure.net/libs/amp/latest/docs/
我需要从Microsoft下载打字稿定义文件: https : //amp.azure.net/libs/amp/latest/docs/
I put this in my typings folder and added a reference path to my video module: 我将其放在我的类型文件夹中,并为视频模块添加了参考路径:
/// <reference path="../../typings/azuremediaplayer.d.ts" />
You still need to add the azure media player lib files to your index.html: 您仍然需要将Azure Media Player库文件添加到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>
I have a very simple component that only displays the video. 我有一个非常简单的组件,只显示视频。
The html: 的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>
The component code: 组件代码:
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"
});
}
}
From here you can play with the settings. 从这里您可以播放设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.