javascript - visa strömfil i angular 8
jag skapar en komponent för att förhandsgranska fil audio, video, image eller etc.
men jag har problem med detta :
det visar mig ingenting. URL:en är korrekt, när jag skriver ut adressfilen i konsolen och kopierar den i webbläsaren visas filen, men den visas inte i min komponent.
export interface DialogData {
src: string;
type: TypeFile;
apiControllName: string;
}
declare const require: any;
@Component({
selector: 'kt-preview',
templateUrl: './preview.component.html',
styleUrls: ['./preview.component.scss']
})
export class PreviewComponent implements OnInit, OnDestroy {
@Output() showButton = new EventEmitter<boolean>();
subscriptions: Subscription;
thumbnail: any;
fileSource: any;
Video = 'Video';
Picture = 'Picture';
Text = 'Text';
Sound = 'Sound';
type: any;
isLoading: boolean;
showVid: any;
fileType = TypeFile;
show = true;
url: string;
AdressFile: string;
constructor(
@Inject(MAT_DIALOG_DATA) public data: DialogData
, @Inject(APP_CONFIG) private appConfig: IAppConfig
, private dialogRef: MatDialogRef<PreviewComponent>
, private authService: AuthService
, private sanitizer: DomSanitizer) {
}
@HostListener('window:keyup.esc') onKeyUp(): void {
this.dialogRef.close();
}
ngOnInit(): void {
if (this.data.src.startsWith('data:image/png;base64,')) {
this.AdressFile = this.data.src;
} else {
this.AdressFile = this.appConfig.apiEndpoint + '/' + this.data.src + '/?access_token=' + this.authService.getRawAuthToken(AuthTokenType.AccessToken);
}
this.type = this.data.type;
this.AdressFile = this.url;
this.show = false;
}
ngOnDestroy(): void {
if (this.subscriptions) {
this.subscriptions.unsubscribe();
}
}
createImageFromBlob(image: Blob): void {
const blob = new Blob([image], { type: 'application/octet-stream' });
this.fileSource = this.sanitizer.bypassSecurityTrustResourceUrl(window.URL.createObjectURL(blob));
}
close(): void {
this.dialogRef.close();
}
}
och denna HTML-fil :
<div class="toolbar col-md-12 col-sm-12 col-lg-12 col-xl-12 p-0">
<div class="topbar col-md-12 col-xl-12 col-sm-12 col-xl-12 col-lg-12">
<div class="detail-title">
<label>نمایش</label>
</div>
<span>
<i (click)="close()" class="fas fa-times"></i>
</span>
</div>
</div>
<div class="col-md-12 col-sm-12 col-lg-12 col-xl-12 p-0 prev">
<!-- Video Show -->
<div *ngIf="data.type===1">
<video autoplay controls>
<source src="{{data.src}}" type="video/mp4">
<source src="{{data.src}}" type="video/ogg">
Your browser does not support the video tag.
</video>
</div>
<div *ngIf="type===fileType[1]" id="video_bg">
<video controls autoplay>
<source [src]="AdressFile" type="video/mp4">
<source [src]="AdressFile" type="video/ogg">
Your browser does not support the video tag.
</video>
</div>
<!-- PDF Show -->
<div *ngIf="data.type===0">
<a href="{{data.src}}" target="_blank"></a>
</div>
<div *ngIf="type===fileType[0]">
<a [href]="AdressFile" target="_blank"></a>
</div>
<!-- Sound Show -->
<div *ngIf="data.type===2">
<audio controls>
<source src="{{data.src}}" type="audio/ogg">
<source src="{{data.src}}" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</div>
<div *ngIf="type===fileType[2]" id="sound_bg">
<audio controls autoplay>
<source [src]="AdressFile" type="audio/mp3">
</audio>
</div>
<!-- Image Show -->
<div *ngIf="data.type===3">
<div class="img col-md-12 col-xl-12 col-sm-12 col-xl-12 p-0">
<img *ngIf="!isLoading" src="{{AdressFile}}" class=" float-left" alt="...">
</div>
</div>
<div *ngIf="type===fileType[3]">
<div class="img col-md-12 col-xl-12 col-sm-12 col-xl-12 p-0">
<img *ngIf="!isLoading" [src]="AdressFile" class=" float-left" alt="...">
</div>
</div>
</div>
vad är problemet? hur kan jag lösa det??