在Safari浏览器下录制的视频,在Angular 8应用程序中会出现加速的问题。解决这个问题的方法是使用video标签并添加playsinline和controls属性。同时,ngAfterViewInit
钩子函数中需设置muted属性为true以确保自动播放,具体实现代码如下:
import { Component, ElementRef, ViewChild } from '@angular/core';
@Component({
selector: 'app-video',
template: `
`
})
export class VideoComponent {
@ViewChild('videoEl') videoElementRef: ElementRef;
ngAfterViewInit() {
const videoEl = this.videoElementRef.nativeElement;
navigator.mediaDevices.getUserMedia({ audio: true, video: true })
.then((stream) => {
videoEl.srcObject = stream;
videoEl.play();
})
.catch(console.error);
}
}
这样,在Safari浏览器下录制的视频,在视频标签中播放时就不会加速了。