Angular视频无法自动播放问题
创始人
2024-10-29 12:00:31
0

需要在组件中添加一个方法,以在用户第一次交互之后开始视频播放。

在组件中添加以下代码:

import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';

@Component({ selector: 'app-video', templateUrl: './video.component.html', styleUrls: ['./video.component.css'] })

export class VideoComponent implements OnInit { @ViewChild('videoPlayer') videoplayer: ElementRef;

constructor() { }

ngOnInit() { }

ngAfterViewInit() {
    this.videoplayer.nativeElement.muted = true;
    this.videoplayer.nativeElement.play();
}

unmute() {
    this.videoplayer.nativeElement.muted = false;
}

}

在模板文件中添加以下代码:

这里,“videoPlayer”是对元素的引用,它可以在代码中使用,让你得以控制视频的播放。在ngAfterViewInit生命周期钩子中,我们将视频设置为静音并立即播放。我们像这样定义了一个名为“unmute()”的函数,以在用户点击视频时取消静音。

相关内容

热门资讯

第一分钟模块!wepoker透... 第一分钟模块!wepoker透视底牌脚本(透视)切实真的是有辅助辅助(哔哩哔哩)一、wepoker透...
第9分钟绝活儿!红龙poker... 第9分钟绝活儿!红龙poker作必弊指令(透视)竟然存在有辅助工具(哔哩哔哩)一、红龙poker作必...
第3分钟办法!哈糖大菠萝破解器... 第3分钟办法!哈糖大菠萝破解器(透视)总是是有辅助教程(哔哩哔哩)1、进入到哈糖大菠萝破解器是否有挂...
四分钟步骤!wejoker辅助... 四分钟步骤!wejoker辅助软件视频(透视)确实存在有辅助神器(哔哩哔哩)进入游戏-大厅左侧-新手...
6分钟攻略!wejoker辅助... 6分钟攻略!wejoker辅助软件(透视)都是是真的有辅助透视(哔哩哔哩)wejoker辅助软件辅助...
第五分钟指南书!hhpoker... 第五分钟指南书!hhpoker免费透视脚本(透视)其实是真的有辅助教程(哔哩哔哩)1)hhpoker...
第九分钟绝活!wepoker有... 第九分钟绝活!wepoker有没有机器人(透视)一贯是有辅助教程(哔哩哔哩)1、wepoker有没有...
第9分钟讲义!wepoker透... 第9分钟讲义!wepoker透视底牌脚本(透视)总是真的是有辅助透视(哔哩哔哩)1、许多玩家不知道w...
四分钟大纲!epoker免费透... 四分钟大纲!epoker免费透视脚本(透视)竟然是真的有辅助下载(哔哩哔哩)1、任何epoker免费...
第二分钟指南!wepoker免... 第二分钟指南!wepoker免费透视脚本(透视)都是是有辅助透视(哔哩哔哩)1、许多玩家不知道wep...