简体   繁体   中英

Angular 2 Azure Media Services Video Playback

I cannot play an Azure Media Services video using Angular. I have a simple html page that works:

<!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.

I added the following to my index.html page:

<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:

<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. 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/

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:

<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:

<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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM