> ## Documentation Index
> Fetch the complete documentation index at: https://docs-unity.molca.id/llms.txt
> Use this file to discover all available pages before exploring further.

# Media system

> MediaLoader and handlers for image, video, document, and text.

**Folder:** `Assets/_MolcaSDK/Code/Scripts/Media/`

| Type                                                                     | Role                            |
| ------------------------------------------------------------------------ | ------------------------------- |
| **MediaLoader**                                                          | Orchestrates load/display       |
| **ImageHandler**, **VideoHandler**, **DocumentHandler**, **TextHandler** | `IMediaHandler` implementations |

**UI:** `UI/MediaPreviewUI`, `MediaInfoCycle` under `Code/Scripts/UI/`.

## When to use

Use **`MediaLoader`** when you need **authenticated download + cache** for images, documents, or video URLs exposed by your backend, with optional **loading modal** progress via [Modal manager](/core/modal-manager). Not a substitute for raw **Addressables** or local **`Resources`** for built-in assets.

## Code

`MediaLoader` is a **`RuntimeSubsystem`**; it requires **`AuthManager.IsAuthenticated`** for **`GetTexture`** (returns **null** if logged out). It uses **`HttpRequestAsset`** fields (**`getTexture2DRequest`**, **`getDocumentRequest`**, **`getVideoRequest`**) and **`CacheManager`** with **`version`** / **`cacheId`**.

```csharp theme={null}
using Molca;
using MolcaSDK.Media;
using UnityEngine;

public class SlideDeck : MonoBehaviour
{
    private async void Start()
    {
        await RuntimeManager.WaitForInitialization();
        var loader = RuntimeManager.GetSubsystem<MediaLoader>();
        if (loader == null) return;

        var texture = await loader.GetTexture("https://example.com/poster.png", version: 1);
        if (texture != null)
        {
            // Assign to RawImage / material
        }
    }
}
```

See **`MediaLoader.cs`** for document/video helpers and parity with the Inspector-configured request assets.

## Troubleshooting

* **Always null texture** — User must be logged in (**`AuthManager.IsAuthenticated`**); URL must be non-empty; **`getTexture2DRequest`** must be assigned.
* **Stale image after CDN update** — Bump **`version`** so **`CacheManager.TryGetCache`** misses old bytes; or change **`cacheId`**.
* **Warning on init** — Any of the three **`HttpRequestAsset`** references missing logs **"Some HTTP request assets are not configured"**; wire all three for production.
* **401 / download errors** — Request sets **`Bearer`** from **`AuthToken`**; renew session if tokens expire mid-session.

## Related

* [HttpClient](/core/http-client) / [HttpRequestAsset](/core/http-client) patterns
* [Modal manager](/core/modal-manager)
* [RuntimeManager](/core/runtime-manager)

## Unity Editor

<Frame caption="Media components">
  <img src="https://mintcdn.com/ptmolcateknologinusantara/qXrgFMk4QevJTANv/images/features/shared/media-loader-inspector.png?fit=max&auto=format&n=qXrgFMk4QevJTANv&q=85&s=f1817471ee81596b8019cecd8b3fb9bc" alt="Media Loader Inspector" width="620" height="215" data-path="images/features/shared/media-loader-inspector.png" />
</Frame>
