added autoplay

This commit is contained in:
Nicolas Constant 2019-05-16 23:52:23 -04:00
parent fe8aadd8ff
commit f7045a140c
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
2 changed files with 16 additions and 3 deletions

View File

@ -14,7 +14,8 @@
top: 15px;
right: 20px;
font-size: 24px;
color: $font-link-primary;
color: $font-link-primary;
&:hover {
color: $font-link-primary-hover;
}
@ -33,6 +34,5 @@
width: 95vw;
max-height: 600px;
max-width: 950px;
border: 1px solid greenyellow;
}
}

View File

@ -1,4 +1,4 @@
import { Component, OnInit, Input, Output } from '@angular/core';
import { Component, OnInit, Input, Output, ElementRef, ViewChild } from '@angular/core';
import { SafeHtml } from '@angular/platform-browser';
import { faChevronLeft, faChevronRight, faTimes } from "@fortawesome/free-solid-svg-icons";
import { Subject } from 'rxjs';
@ -13,6 +13,7 @@ import { Attachment } from '../../services/models/mastodon.interfaces';
styleUrls: ['./media-viewer.component.scss']
})
export class MediaViewerComponent implements OnInit {
private _mediaEvent: OpenMediaEvent;
faChevronLeft = faChevronLeft;
@ -30,6 +31,7 @@ export class MediaViewerComponent implements OnInit {
if (value.iframe) {
this.html = value.iframe;
this.autoplayIframe();
} else {
const attachment = value.attachments[value.selectedIndex];
this.loadAttachment(attachment);
@ -40,6 +42,7 @@ export class MediaViewerComponent implements OnInit {
}
@Output() closeSubject = new Subject<boolean>();
@ViewChild('video') myVideo: ElementRef;
constructor() { }
@ -56,6 +59,16 @@ export class MediaViewerComponent implements OnInit {
}
}
private autoplayIframe(): any {
setTimeout(() => {
if(this.myVideo.nativeElement.childNodes[0].src.includes('?')){
this.myVideo.nativeElement.childNodes[0].src+='&autoplay=1&auto_play=1';
} else {
this.myVideo.nativeElement.childNodes[0].src+='?autoplay=1&auto_play=1';
}
}, 500);
}
close(): boolean {
this.closeSubject.next(true);
return false;