Finishing subrip player support for the web app.

This commit is contained in:
Zoe Roux 2019-09-19 19:14:41 +02:00
parent f67293d065
commit cb306d6a34
3 changed files with 32 additions and 4 deletions

View File

@ -3,6 +3,8 @@
<video id="player" poster="backdrop/{{this.item.showSlug}}" autoplay muted (click)="tooglePlayback()">
<source src="/api/video/{{this.item.link}}" />
<source src="/api/video/{{this.item.link}}/stream" type="video/mp4" />
<!--<track src="/api/subtitle/clannad-s1e1.eng.vtt" lang="English" srclang="en" default/>-->
</video>
</div>
@ -91,7 +93,7 @@
</button>
<div *ngFor="let subtitle of this.item.subtitles">
<button [ngClass]="{'selected': this.selectedSubtitle == subtitle}" mat-menu-item *ngIf="subtitle.codec == 'ass'; else elseBlock" (click)="selectSubtitle(subtitle)">
<button [ngClass]="{'selected': this.selectedSubtitle == subtitle}" mat-menu-item *ngIf="subtitle.codec == 'ass' || subtitle.codec == 'subrip'; else elseBlock" (click)="selectSubtitle(subtitle)">
<span>{{subtitle.displayName}}</span>
</button>

View File

@ -343,7 +343,7 @@ export class PlayerComponent implements OnInit
fullscreen()
{
if (document.fullscreenElement == null)
document.getElementById("root").requestFullscreen();
document.body.requestFullscreen();
else
document.exitFullscreen();
}
@ -400,16 +400,42 @@ export class PlayerComponent implements OnInit
{
this.snackBar.open("Subtitle removed.", null, { verticalPosition: "top", horizontalPosition: "right", duration: 750, panelClass: "info-panel" });
SubtitleManager.remove(this.player);
this.removeHtmlTrack();
}
else
{
this.snackBar.open(subtitle.displayName + " subtitle loaded.", null, { verticalPosition: "top", horizontalPosition: "right", duration: 750, panelClass: "info-panel" });
this.removeHtmlTrack();
if (subtitle.codec == "ass")
SubtitleManager.add(this.player, subtitle.link, true);
else if (subtitle.codec == "subrip")
{
SubtitleManager.remove(this.player);
let track = document.createElement("track");
track.kind = "subtitles";
track.label = subtitle.displayName;
track.srclang = subtitle.language;
track.src = subtitle.link.replace(".srt", ".vtt");
track.default = true;
track.onload = () =>
{
this.player.textTracks[0].mode = "showing";
};
this.player.appendChild(track);
}
}
}
removeHtmlTrack()
{
let elements = this.player.getElementsByTagName("track");
if (elements.length > 0)
elements.item(0).remove();
}
getThumb(url: string)
{
return this.sanitizer.bypassSecurityTrustStyle("url(" + url + ")");

View File

@ -90,7 +90,7 @@ namespace Kyoo.Controllers
public class ConvertSubripToVtt : IActionResult
{
private string path;
private readonly string path;
private string lastLine = "";
public ConvertSubripToVtt(string subtitlePath)
@ -133,7 +133,7 @@ namespace Kyoo.Controllers
line = null;
if (lastLine == null) //The line is a timecode only if the last line is an index line and we already set it to null.
line = line.Replace(',', '.'); //This is never called.
line = line.Replace(',', '.');
return line;
}