Js *_*oee 1 html javascript html5-video ionic-framework angular
我正在构建一个带有 a=ionic 的移动应用程序,我希望能够从上传的视频中播放 blob 文件,但我在控制台中得到了这个
unsafe:blob:http://localhost:8100/3d42df5b-d852-4cac-83d8-af0c6d514b04 net::ERR_UNKNOWN_URL_SCHEME
Run Code Online (Sandbox Code Playgroud)
这是我的代码
<input type="file"accept="video/*" #fileInput name="proPics" (change)="onSelectedFile($event)">
preview(files) {
var URL = window.URL || window.webkitURL;
this.vidURL = URL.createObjectURL(files)
}
onSelectedFile(event){
this.selectedFile = <File>event.target.files[0]
this.preview(this.selectedFile)
}
Run Code Online (Sandbox Code Playgroud)
当我尝试上传视频文件时,我在控制台中得到了该文件,我需要您的帮助,我做错了什么
你可以在 Html 上这样做:
<input type="file" accept="video/*" (change)="onSelectedFile($event)">
<video
*ngIf="prev_url"
[src]="prev_url"
style="width:300px; height:300px;"
controls></video>
Run Code Online (Sandbox Code Playgroud)
在 ts 文件上:
prev_url : any;
constructor(
private sanitizer : DomSanitizer
) {}
onSelectedFile(ev) {
let file = ev.target.files[0];
var URL = window.URL;
this.prev_url = this.sanitizer.bypassSecurityTrustUrl(URL.createObjectURL(file));
console.log(this.prev_url)
}
Run Code Online (Sandbox Code Playgroud)
这里的工作示例:
https://stackblitz.com/edit/angular-ivy-m8zd1m?file=src%2Fapp%2Fapp.component.ts
| 归档时间: |
|
| 查看次数: |
1219 次 |
| 最近记录: |