Interface: RnMediaContentSource
Defined in: packages/player/src/specs/content-source.nitro.ts:41
Turns an Android content:// URI into a file descriptor mpv can read.
Remarks
Why this has to be native at all. A content:// URI is not a path and
not a URL: it names a row in some other app's ContentProvider, and the only
way to read it is to ask Android's ContentResolver to open it for this
process, under the grant the picker handed us. Neither libmpv nor FFmpeg has
— or could have — a handler for the scheme, because the resolution is a
Binder call into another process, not a URI parse. So the bytes have to reach
mpv the one way a Binder-opened file can travel: as a file descriptor.
mpv's own fd:// protocol is the other half. From mpv 0.41.0
DOCS/man/mpv.rst: "fd://123 — Read data from the given file
descriptor", implemented in stream/stream_file.c:298-313, which validates
the descriptor with fcntl(fd, F_GETFD) and then reads it like any other
file. So ContentResolver.openFileDescriptor(uri, "r").detachFd() →
fd://<n> is a complete path from the storage picker to the decoder, with no
copy and no temporary file.
fd://, not fdclose://. fdclose:// makes mpv close() the
descriptor when the stream ends (stream_file.c:313, p->close = true),
which sounds like the tidy choice and is not: the URL a source resolver hands
back must stay byte-identical for the life of the entry (mpv compares the
prefetch and play-time URLs to decide whether it can reuse the prefetched
stream), so the same fd://n is opened again whenever the entry is
replayed — loop, a jumpTo back, a dropped prefetch. mpv re-seeks the
descriptor to 0 on every open (stream_file.c:373-379), so reopening works
— but only if nobody closed it. Ownership therefore stays on this side:
closeContentFd is called when the player is destroyed.
Android-only, by construction. iOS has no content:// scheme and no
ContentResolver; its document picker hands back a file:// URL that mpv
opens directly. There is nothing here for iOS to implement, so this
HybridObject is not declared for it and
NitroModules.createHybridObject('RnMediaContentSource') is never called
there — see src/content-uri.ts, which is the only consumer.
Extends
HybridObject<{android:"kotlin"; }>
Properties
name
readonly name: string;
Defined in: node_modules/react-native-nitro-modules/lib/typescript/HybridObject.d.ts:52
The HybridObject's name.
Inherited from
HybridObject.name
Methods
closeContentFd()
closeContentFd(fd: number): void;
Defined in: packages/player/src/specs/content-source.nitro.ts:61
Close a descriptor handed out by openContentUri.
Parameters
| Parameter | Type | Description |
|---|---|---|
fd | number | The descriptor. Closing one twice, or closing one mpv is still reading, is the caller's bug to avoid; this only reports failures. |
Returns
void
dispose()
dispose(): void;
Defined in: node_modules/react-native-nitro-modules/lib/typescript/HybridObject.d.ts:94
Disposes any resources this HybridObject might hold natively,
and releases this HybridObject's NativeState.
After calling (), this object can no longer be used.
Eagerly disposing a HybridObject could be beneficial for a queue-/handler-architecture
where a bunch of Hybrid Objects are allocated, and later deallocated once a callback (e.g. a render function)
completes.
Returns
void
Note
It is NOT required to call () manually, as the JavaScript
Garbage Collector automatically disposes and releases any resources when needed.
It is purely optional to eagerly-, and manually-, call () here - use with caution!
Inherited from
HybridObject.dispose
equals()
equals(other: HybridObject<{
android: "kotlin";
}>): boolean;
Defined in: node_modules/react-native-nitro-modules/lib/typescript/HybridObject.d.ts:79
Returns whether this HybridObject is the same object as other.
While two HybridObjects might not be equal when compared with ==, they might still
hold the same underlying HybridObject, in which case equals(other)
will return true.
Parameters
| Parameter | Type |
|---|---|
other | HybridObject<{ android: "kotlin"; }> |
Returns
boolean
Example
const hybridA = SomeModule.getExistingHybridInstance()
const hybridB = SomeModule.getExistingHybridInstance()
console.log(hybridA.equals(hybridB)) // true
Inherited from
HybridObject.equals
openContentUri()
openContentUri(uri: string): number;
Defined in: packages/player/src/specs/content-source.nitro.ts:53
Open uri for reading and hand back a detached file descriptor.
Parameters
| Parameter | Type | Description |
|---|---|---|
uri | string | A content:// URI this process holds a read grant for. |
Returns
number
The raw file descriptor number, owned by the caller from here on
— ParcelFileDescriptor.detachFd(), so the Java object no longer closes
it and closeContentFd is the only thing that will.
Throws
When the provider is unknown, the grant has lapsed, the row does not exist, or the provider returned no descriptor. The message names which.
toString()
toString(): string;
Defined in: node_modules/react-native-nitro-modules/lib/typescript/HybridObject.d.ts:64
Returns a string representation of the given HybridObject.
Unless overridden by the HybridObject, this will return the name of the object.
Returns
string
Example
const hybridA = SomeModule.getExistingHybridInstance()
console.log(hybridA.toString()) // [HybridObject HybridA]
Inherited from
HybridObject.toString