Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
747 views
in Technique[技术] by (71.8m points)

html - Angular 2 - change videos src after clicking on div

I have problem with video src. After clicking on my div (camera) in source code I can see that video src is changing properly, but videos arent being played. What should I do?

Below are my components - streaming.component.ts (responsible for displaying videos of chosen camera component) and camera.component.ts (for viewing icon with camera name)

streaming.component.ts

import {Component} from '@angular/core';
import {CameraComponent} from '../camera/camera.component';

@Component({
   moduleId: module.id,
   selector: 'streaming',
   template: `
            <camera cameraName="Kamera 1" (click)='cameraStream("sample.mp4")'></camera>
            <camera cameraName="Kamera 2" (click)='cameraStream("sample2.mp4")'></camera>
            <camera cameraName="Kamera 3" (click)='cameraStream("sample3.mp4")'></camera>
            <camera cameraName="Kamera 4" (click)='cameraStream("sample4.mp4")'></camera>
            <video width="800" controls>
                <source src = "{{cameraSrc}}" type="video/mp4">
                Your browser does not support HTML5 video.
            </video>
            <p>{{cameraSrc}}</p>
            `,
directives: [CameraComponent]
})
export class StreamingComponent {

 cameraSrc:string;
 constructor() { }

 cameraStream(chosenCamera :string){
    this.cameraSrc=chosenCamera;
  }
 }

Videos are working ,because when I put

<source src = "{{cameraSrc}}" type="video/mp4">

everything is fine.

camera.component.ts

import { Component ,Input } from '@angular/core';

@Component({
    moduleId: module.id,
    selector: 'camera',
    templateUrl: 'camera.component.html'
})
export class CameraComponent {
     @Input() cameraName:string = "";

     constructor() { }

 }

Here is what I get after clicking on camera2 for example .

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Don't know why, but that way:

<video width="800" [src] = "cameraSrc" controls>
    Your browser does not support HTML5 video.
</video>

It is working.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...