html - Ionic ng用于视频播放
问题描述
我试图从离子组件中的 ts 开始视频,但如果我调用 video.play() 视频会重新创建,我想。
我的html代码
<video
poster="https://images.unsplash.com/photo-1545486332-9e0999c535b2?ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8YmxhY2t8ZW58MHx8MHx8&ixlib=rb-1.2.1&w=1000&q=80"
[class.blur]="asset.isHide && !asset.isSave" [attr.id]="'fullscreen-video' + i" #video
(click)="playPause(video)">
<source [src]="asset.url" type="video/mp4">
Sorry, your browser doesn't support embedded videos,
but don't worry, you can download it
and watch it with your favorite video player!
</video>
我的ts代码
public playPause(video: HTMLVideoElement): void {
if (video.paused === true) {
video.play();
this.isPlay = true;
} else {
this.isPlay = false;
}
}
仅在调试模式下检测到的错误:executeListenerWithErrorHandling
出现该错误后,将重新创建 html 中的视频元素
解决方案
您应该通过 Id: 获取视频元素。
html:
<video
poster="https://images.unsplash.com/photo-1545486332-9e0999c535b2?ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8YmxhY2t8ZW58MHx8MHx8&ixlib=rb-1.2.1&w=1000&q=80"
[class.blur]="asset.isHide && !asset.isSave" [attr.id]="'fullscreen-video' + i" #video (click)="playPause($event, 'fullscreen-video' + i)" controls="false">
<source [src]="asset.url" type="video/mp4">
Sorry, your browser doesn't support embedded videos,
but don't worry, you can download it
and watch it with your favorite video player!
</video>
.ts:
playPause($event, id) {
let myVideo: any = document.getElementById(id);
if (myVideo.paused) {
myVideo.play();
}
else {
myVideo.pause();
}
}
推荐阅读
- .net - Powershell 和 WinApi EnumWindows 函数
- r - DESCEND 的函数 'selectGenes' 需要永远在稀疏矩阵上完成,并且也没有显示错误消息
- reactjs - 覆盖所有变体的 React Material UI 进度条颜色
- java - 如何在 JAVA 中使用 Apache 2.0.1 LDAP API 进行持久搜索
- python-3.x - PySide2 / QButtonGroup setExclusive 不起作用
- algorithm - 在搜索中找到最佳建议
- amazon-web-services - 当我运行 terraform 应用
- javascript - 为什么函数上的方法似乎不适用于 vue.js?
- javascript - 编辑嵌入字段的正确方法
- mysql - mysql sum and count 2个表按问题分组