我想用范围输入来控制我的视频,问题是当我将 video.currentTime 设置为 2 (例如)时,它仍然始终停留在 0 上,并且该值永远不会改变。
这是我的Angular 7代码:
index.component.html
<video *ngIf="product?.video"
id="myVideo"
width="100%"
height="100%"
#myVideo
(loadedmetadata)="onMetadata($event, myVideo)"
(loadeddata)="pauseVideo(myVideo)"
>
<source [src]="serverUrl+product.video.file" type="video/mp4">
Votre navigateur ne supporte pas le plugin des vidéos.
</video>
...
...
<input class="range-slider__range" #slider type="range" value="0" min="0" step="1" [max]="maxDuration"
(input)="updateVideo(slider.value)"
>
index.component.ts
@ViewChild('myVideo') my3DVideo: ElementRef;
maxDuration = 0;
..
..
pauseVideo(myVideo) {
console.log("data loaded.");
myVideo.currentTime = 3; // i used this line to force juming to second 3 but it still always 0
myVideo.pause();
console.log(myVideo.currentTime);
}
updateVideo(value: any) {
console.log("sliding..");
const video = this.my3DVideo.nativeElement;// as HTMLVideoElement;
video.currentTime = value; // this value is never changes too and it still always 0
}
onMetadata($event, my3DVideo) {
this.maxDuration = my3DVideo.duration;
}
此外,我尝试用可用的远程 mp4 视频替换 url,它有效,但在 localmachine 中它不起作用。 另一次尝试,是我在 Firefox 上尝试了这段代码,它就像一个魅力,但在 chrome 中它没有。
我搜索了很多有关此主题的信息,但仍然没有找到任何解决方案,希望您能帮助我。先感谢您。