我想在幻灯片更改时自动播放tik tok之类的视频。实施后,将显示视频缩略图并播放音频,但不显示视频。
<ion-slides direction="vertical" #slides (ionSlideDidChange)="slideEvent(slides)" (ionSlideWillChange)="isLike(slides)">
<ion-slide *ngFor = "let videoUrl of mainArray" >
<video [id]="videoUrl.id" poster='{{videoUrl.thumbnailUrl}}' preload="none">
<source src="{{videoUrl.url}}" type="video/mp4" autostart="false"/>
</video>
</ion-slide>
</ion-slides>
并尝试从ts播放视频-
playvideo() {
let videoPlayer1: HTMLVideoElement = <HTMLVideoElement>document.getElementById(this.mainArray[this.index].id)
videoPlayer1.pause();
videoPlayer1.currentTime = 0;
const playPromise = videoPlayer1.play();
if (playPromise !== null){
playPromise.catch(() => {
videoPlayer1.play();
videoPlayer1.autoplay = true;
})
}
}
但是只播放音频而不播放视频。