xref: /expo/packages/expo-av/src/AV.types.ts (revision 72b9cd04)
1import { Asset } from 'expo-asset';
2
3import ExponentAV from './ExponentAV';
4
5// @needsAudit
6/**
7 * Check [official Apple documentation](https://developer.apple.com/documentation/avfoundation/avaudiotimepitchalgorithmlowqualityzerolatency) for more information.
8 */
9export enum PitchCorrectionQuality {
10  /**
11   * Equivalent to `AVAudioTimePitchAlgorithmLowQualityZeroLatency`.
12   */
13  Low = ExponentAV && ExponentAV.Qualities && ExponentAV.Qualities.Low,
14  /**
15   * Equivalent to `AVAudioTimePitchAlgorithmTimeDomain`.
16   */
17  Medium = ExponentAV && ExponentAV.Qualities && ExponentAV.Qualities.Medium,
18  /**
19   * Equivalent to `AVAudioTimePitchAlgorithmSpectral`.
20   */
21  High = ExponentAV && ExponentAV.Qualities && ExponentAV.Qualities.High,
22}
23
24// @needsAudit
25/**
26 * The following forms of source are supported:
27 * - A dictionary of the form `AVPlaybackSourceObject`.
28 *   The `overrideFileExtensionAndroid` property may come in handy if the player receives an URL like `example.com/play` which redirects to `example.com/player.m3u8`.
29 *   Setting this property to `m3u8` would allow the Android player to properly infer the content type of the media and use proper media file reader.
30 * - `require('path/to/file')` for a media file asset in the source code directory.
31 * - An [`Asset`](./asset) object for a media file asset.
32 *
33 * The [iOS developer documentation](https://developer.apple.com/library/ios/documentation/Miscellaneous/Conceptual/iPhoneOSTechOverview/MediaLayer/MediaLayer.html)
34 * lists the audio and video formats supported on iOS.
35 *
36 * There are two sets of audio and video formats supported on Android: [formats supported by ExoPlayer](https://google.github.io/ExoPlayer/supported-formats.html)
37 * and [formats supported by Android's MediaPlayer](https://developer.android.com/guide/appendix/media-formats.html#formats-table).
38 * Expo uses ExoPlayer implementation by default. To use `MediaPlayer`, add `androidImplementation: 'MediaPlayer'` to the initial status of the AV object.
39 */
40export type AVPlaybackSource = number | AVPlaybackSourceObject | Asset;
41
42// @needsAudit
43/**
44 * One of the possible forms of the `AVPlaybackSource`.
45 */
46export type AVPlaybackSourceObject = {
47  /**
48   * A network URL pointing to a media file.
49   */
50  uri: string;
51  /**
52   * An optional string overriding extension inferred from the URL.
53   * @platform android
54   */
55  overrideFileExtensionAndroid?: string;
56  /**
57   * An optional headers object passed in a network request.
58   */
59  headers?: Record<string, string>;
60};
61
62/**
63 * @hidden
64 */
65export type AVPlaybackNativeSource = {
66  uri: string;
67  overridingExtension?: string | null;
68  headers?: Record<string, string>;
69};
70
71// @needsAudit
72/**
73 * Object passed to the `onMetadataUpdate` function.
74 */
75export type AVMetadata = {
76  /**
77   * A string with the title of the sound object.
78   */
79  title?: string;
80};
81
82// @needsAudit
83/**
84 * This is the structure returned from all playback API calls and describes the state of the `playbackObject` at that point in time.
85 * It can take a form of `AVPlaybackStatusSuccess` or `AVPlaybackStatusError` based on the `playbackObject` load status.
86 */
87export type AVPlaybackStatus = AVPlaybackStatusError | AVPlaybackStatusSuccess;
88
89// @needsAudit
90export type AVPlaybackStatusError = {
91  /**
92   * A boolean set to `false`.
93   */
94  isLoaded: false;
95  /**
96   * Underlying implementation to use (when set to `MediaPlayer` it uses [Android's MediaPlayer](https://developer.android.com/reference/android/media/MediaPlayer.html),
97   * uses [ExoPlayer](https://google.github.io/ExoPlayer/) otherwise). You may need to use this property if you're trying to play an item unsupported by ExoPlayer
98   * ([formats supported by ExoPlayer](https://google.github.io/ExoPlayer/supported-formats.html), [formats supported by Android's MediaPlayer](https://developer.android.com/guide/appendix/media-formats.html#formats-table)).
99   *
100   * Note that setting this property takes effect only when the AV object is just being created (toggling its value later will do nothing).
101   *
102   * @platform android
103   */
104  androidImplementation?: string;
105  /**
106   * A string only present if the `playbackObject` just encountered a fatal error and forced unload.
107   * Populated exactly once when an error forces the object to unload.
108   */
109  error?: string;
110};
111
112// @needsAudit
113export type AVPlaybackStatusSuccess = {
114  /**
115   * A boolean set to `true`.
116   */
117  isLoaded: true;
118  /**
119   * Underlying implementation to use (when set to `MediaPlayer` it uses [Android's MediaPlayer](https://developer.android.com/reference/android/media/MediaPlayer.html),
120   * uses [ExoPlayer](https://google.github.io/ExoPlayer/) otherwise). You may need to use this property if you're trying to play an item unsupported by ExoPlayer
121   * ([formats supported by ExoPlayer](https://google.github.io/ExoPlayer/supported-formats.html), [formats supported by Android's MediaPlayer](https://developer.android.com/guide/appendix/media-formats.html#formats-table)).
122   *
123   * Note that setting this property takes effect only when the AV object is just being created (toggling its value later will do nothing).
124   *
125   * @platform android
126   */
127  androidImplementation?: string;
128  /**
129   * The location of the media source.
130   */
131  uri: string;
132  /**
133   * The minimum interval in milliseconds between calls of `onPlaybackStatusUpdate`. See `setOnPlaybackStatusUpdate()` for details.
134   */
135  progressUpdateIntervalMillis: number;
136  /**
137   * The duration of the media in milliseconds. This is only present if the media has a duration.
138   * > Note that in some cases, a media file's duration is readable on Android, but not on iOS.
139   */
140  durationMillis?: number;
141  /**
142   * The current position of playback in milliseconds.
143   */
144  positionMillis: number;
145  /**
146   * The position until which the media has been buffered into memory. Like `durationMillis`, this is only present in some cases.
147   */
148  playableDurationMillis?: number;
149  // @docsMissing
150  seekMillisToleranceBefore?: number;
151  // @docsMissing
152  seekMillisToleranceAfter?: number;
153  /**
154   * A boolean describing if the media is supposed to play.
155   */
156  shouldPlay: boolean;
157  /**
158   * A boolean describing if the media is currently playing.
159   */
160  isPlaying: boolean;
161  /**
162   * A boolean describing if the media is currently buffering.
163   */
164  isBuffering: boolean;
165  /**
166   * The current rate of the media.
167   */
168  rate: number;
169  /**
170   * A boolean describing if we are correcting the pitch for a changed rate.
171   */
172  shouldCorrectPitch: boolean;
173  /**
174   * iOS time pitch algorithm setting. See `setRateAsync` for details.
175   */
176  pitchCorrectionQuality?: PitchCorrectionQuality;
177  /**
178   * The current volume of the audio for this media.
179   */
180  volume: number;
181  /**
182   * A boolean describing if the audio of this media is currently muted.
183   */
184  isMuted: boolean;
185  /**
186   * The current audio panning value of the audio for this media.
187   */
188  audioPan: number;
189  /**
190   * A boolean describing if the media is currently looping.
191   */
192  isLooping: boolean;
193  /**
194   * A boolean describing if the media just played to completion at the time that this status was received.
195   * When the media plays to completion, the function passed in `setOnPlaybackStatusUpdate()` is called exactly once
196   * with `didJustFinish` set to `true`. `didJustFinish` is never `true` in any other case.
197   */
198  didJustFinish: boolean;
199};
200
201// @needsAudit
202/**
203 * This is the structure passed to `setStatusAsync()` to modify the state of the `playbackObject`.
204 */
205export type AVPlaybackStatusToSet = {
206  /**
207   * Underlying implementation to use (when set to `MediaPlayer` it uses [Android's MediaPlayer](https://developer.android.com/reference/android/media/MediaPlayer.html),
208   * uses [ExoPlayer](https://google.github.io/ExoPlayer/) otherwise). You may need to use this property if you're trying to play an item unsupported by ExoPlayer
209   * ([formats supported by ExoPlayer](https://google.github.io/ExoPlayer/supported-formats.html), [formats supported by Android's MediaPlayer](https://developer.android.com/guide/appendix/media-formats.html#formats-table)).
210   *
211   * Note that setting this property takes effect only when the AV object is just being created (toggling its value later will do nothing).
212   *
213   * @platform android
214   */
215  androidImplementation?: string;
216  /**
217   * The minimum interval in milliseconds between calls of `onPlaybackStatusUpdate`. See `setOnPlaybackStatusUpdate()` for details.
218   */
219  progressUpdateIntervalMillis?: number;
220  /**
221   * The current position of playback in milliseconds.
222   */
223  positionMillis?: number;
224  // @docsMissing
225  seekMillisToleranceBefore?: number;
226  // @docsMissing
227  seekMillisToleranceAfter?: number;
228  /**
229   * A boolean describing if the media is supposed to play.
230   */
231  shouldPlay?: boolean;
232  /**
233   * The current rate of the media.
234   * @platform android API 23+
235   * @platform ios
236   */
237  rate?: number;
238  /**
239   * A boolean describing if we are correcting the pitch for a changed rate.
240   */
241  shouldCorrectPitch?: boolean;
242  /**
243   * The current volume of the audio for this media.
244   * > Note that this only affect the audio of this `playbackObject` and do NOT affect the system volume.
245   */
246  volume?: number;
247  /**
248   * A boolean describing if the audio of this media is currently muted.
249   * > Note that this only affect the audio of this `playbackObject` and do NOT affect the system volume.
250   */
251  isMuted?: boolean;
252  /**
253   * The current audio panning value of the audio for this media.
254   * > Note that this only affect the audio of this `playbackObject` and do NOT affect the system volume.
255   * > Also note that this is only available when the video was loaded using `androidImplementation: 'MediaPlayer'`
256   * @platform android
257   */
258  audioPan?: number;
259  /**
260   * A boolean describing if the media is currently looping.
261   */
262  isLooping?: boolean;
263  /**
264   * iOS time pitch algorithm setting. See `setRateAsync` for details.
265   */
266  pitchCorrectionQuality?: PitchCorrectionQuality;
267};
268
269// @docsMissing
270export type AVPlaybackTolerance = { toleranceMillisBefore?: number; toleranceMillisAfter?: number };
271