-
Notifications
You must be signed in to change notification settings - Fork 14
/
bufferApi.ts
101 lines (92 loc) · 2.62 KB
/
bufferApi.ts
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
import { NativeModules } from 'react-native';
const BufferModule = NativeModules.BufferModule;
/**
* Represents different types of media.
*/
export enum MediaType {
/**
* Audio media type.
*/
AUDIO = 'audio',
/**
* Video media type.
*/
VIDEO = 'video',
}
/**
* Represents different types of buffered data.
*/
export enum BufferType {
/**
* Represents the buffered data starting at the current playback time.
*/
FORWARD_DURATION = 'forwardDuration',
/**
* Represents the buffered data up until the current playback time.
*/
BACKWARD_DURATION = 'backwardDuration',
}
/**
* Holds different information about the buffer levels.
*/
export interface BufferLevel {
/**
* The amount of currently buffered data, e.g. audio or video buffer level.
*/
level?: number;
/**
* The target buffer level the player tries to maintain.
*/
targetLevel?: number;
/**
* The media type the buffer data applies to.
*/
media?: MediaType;
/**
* The buffer type the buffer data applies to.
*/
type?: BufferType;
}
/**
* Collection of {@link BufferLevel} objects
*/
export interface BufferLevels {
/**
* {@link BufferLevel} for {@link MediaType.AUDIO}.
*/
audio: BufferLevel;
/**
* {@link BufferLevel} for {@link MediaType.VIDEO}.
*/
video: BufferLevel;
}
/**
* Provides the means to configure buffer settings and to query the current buffer state.
* Accessible through {@link Player.buffer}.
*/
export class BufferApi {
/**
* The native player id that this buffer api is attached to.
*/
readonly nativeId: string;
constructor(playerId: string) {
this.nativeId = playerId;
}
/**
* Gets the {@link BufferLevel|buffer level} from the Player
* @param type The {@link BufferType} to return the level for.
* @returns a {@link BufferLevels} that contains {@link BufferLevel} values for audio and video.
*/
getLevel = async (type: BufferType): Promise<BufferLevels> => {
return BufferModule.getLevel(this.nativeId, type);
};
/**
* Sets the target buffer level for the chosen buffer {@link BufferType} across all {@link MediaType} options.
*
* @param type The {@link BufferType} to set the target level for. On iOS and tvOS, only {@link BufferType.FORWARD_DURATION} is supported.
* @param value The value to set. On iOS and tvOS when passing `0`, the player will choose an appropriate forward buffer duration suitable for most use-cases. On Android setting to `0` will have no effect.
*/
setTargetLevel = async (type: BufferType, value: number): Promise<void> => {
return BufferModule.setTargetLevel(this.nativeId, type, value);
};
}