-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnative-pipeline.ts
More file actions
135 lines (109 loc) · 3.69 KB
/
native-pipeline.ts
File metadata and controls
135 lines (109 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import { BasePipeline } from '../base-pipeline';
import type { IPipelineDependencies } from '../../types/pipeline.declarations';
import type { IPlayerAudioTrack } from '../../types/audio-track.declarations';
import { PlayerAudioTrack } from '../../models/player-audio-track';
import type { IQualityLevel } from '../../types/quality-level.declarations';
import type { IPlayerTextTrack } from '../../types/text-track.declarations';
import {
type IRemoteVttThumbnailTrackOptions,
type IPlayerThumbnailTrack,
} from '../../types/thumbnail-track.declarations';
import { PlayerTextTrack } from '../../models/player-text-tracks';
import { PlayerThumbnailTrack } from '../../models/player-thumbnail-tracks';
import { Thumbnails } from '../../consts/text-tracks';
export class NativePipeline extends BasePipeline {
private constructor(dependencies: IPipelineDependencies) {
super(dependencies);
}
public static create(dependencies: IPipelineDependencies): NativePipeline {
dependencies.logger = dependencies.logger.createSubLogger('NativePipeline');
return new NativePipeline(dependencies);
}
public getTextTracks(): Array<IPlayerTextTrack> {
if (this.videoElement_.textTracks) {
return PlayerTextTrack.fromTextTracks(this.videoElement_.textTracks);
}
return [];
}
public removeRemoteThumbnailTrack(id: string): boolean {
if (this.videoElement_.textTracks) {
const trackToRemove = this.videoElement_.textTracks.getTrackById(id);
// disable native track since there is no Track element to remove.
if (trackToRemove && trackToRemove.label.startsWith(Thumbnails)) {
trackToRemove.mode = 'disabled';
return true;
}
}
return false;
}
public addRemoteVttThumbnailTrack(options: IRemoteVttThumbnailTrackOptions): boolean {
// TODO: Request and parse thumbnails from VTT file or manifest.
if (options.url) {
this.videoElement_.addTextTrack('metadata', Thumbnails);
return true;
}
return false;
}
public selectThumbnailTrack(id: string): boolean {
if (this.videoElement_.textTracks) {
const trackToSelect = this.videoElement_.textTracks.getTrackById(id);
if (trackToSelect && trackToSelect.label.startsWith(Thumbnails)) {
trackToSelect.mode = 'hidden';
return true;
}
}
return false;
}
public getThumbnailTracks(): Array<IPlayerThumbnailTrack> {
if (this.videoElement_.textTracks) {
return PlayerThumbnailTrack.fromTextTracks(this.videoElement_.textTracks);
}
return [];
}
public getAudioTracks(): Array<IPlayerAudioTrack> {
if (this.videoElement_.audioTracks) {
return PlayerAudioTrack.fromAudioTracks(this.videoElement_.audioTracks);
}
return [];
}
public selectAudioTrack(id: string): boolean {
if (!this.videoElement_.audioTracks) {
return false;
}
const targetTrack = this.videoElement_.audioTracks.getTrackById(id);
if (!targetTrack) {
return false;
}
if (targetTrack.enabled) {
return false;
}
for (const track of this.videoElement_.audioTracks) {
track.enabled = track.id === id;
}
return true;
}
public getQualityLevels(): Array<IQualityLevel> {
return [];
}
public selectQualityLevel(): boolean {
return false;
}
public selectAutoQualityLevel(): boolean {
return false;
}
public start(): void {
this.videoElement_.src = this.source_.url.toString();
// TODO: check for autoplay/preload/etc
this.videoElement_.load();
}
public dispose(): void {
this.videoElement_.removeAttribute('src');
this.videoElement_.load();
}
public play(): void {
super.play();
}
public pause(): void {
super.pause();
}
}