---
url: /en-us/standard/blocks/media.md
---
* Type ID: `4`
* Type: Map

**Media places an external resource on the page**: an image, an SVG, a page of a PDF, audio or video. The main file stores only the resource's path, position, size and playback parameters; the resource itself is kept in the [resource package](../file/extra) `filename.uink.extra`.

::: tip Levels

* **Standard**: images (PNG, JPEG, SVG) and their `width`, `height`, `transform`, `opacity`, `fit`, `crop`.
* **Full**: PDF pages, audio, video and playback parameters.
* Core and Basic readers skip Media.
  :::

## Fields

### Common fields

| Field | Type | Requirement | Level | Description |
| --- | --- | --- | --- | --- |
| `type` | uint16 | Required | Standard | Always `4` |
| `contentId` | uint32 | Required | Standard | Content sequence number shared with Ink, Shape and Clear (INK-2) |
| `undoId` | uint32 | Required | Standard | Undo group number (INK-3) |
| `path` | string | Required | Standard | Path of the resource in the resource package (EXTRA-3, EXTRA-4) |
| `mimeType` | string | Required | Standard | MIME type of the resource, for example `image/png` |
| `extra` | Map | Optional | — | App-private fields |

### Visual media

Images, SVG, PDF pages and video add:

| Field | Type | Requirement | Level | Description |
| --- | --- | --- | --- | --- |
| `width` | float32 | Required | Standard | Box width before transform, greater than `0` |
| `height` | float32 | Required | Standard | Box height before transform, greater than `0` |
| `transform` | `Array<float32>(6)` | Optional | Standard | Affine matrix; defaults to the identity matrix |
| `opacity` | float32 | Optional | Standard | `0`–`1`; defaults to `1` |
| `fit` | int32 | Optional | Standard | How the resource fits into the box; defaults to `0` Fill |
| `crop` | Map | Optional | Standard | Show only part of the resource, see below |

### `fit`

| Value | Name | Effect |
| --- | --- | --- |
| `0` | Fill | Stretched to fill the box, aspect ratio not kept |
| `1` | Contain | Aspect ratio kept, fully inside the box, centered; empty space transparent |
| `2` | Cover | Aspect ratio kept, fills the box, centered; overflow cropped |
| `3` | None | At the resource's original pixel size (1 resource pixel = 1 Canvas unit), placed at the top-left corner of the box; overflow cropped |
| `4`–`127` | Reserved | — |
| `128`+ | Private | — |

### `crop`

| Field | Type | Requirement | Description |
| --- | --- | --- | --- |
| `x` | float32 | Required | X of the top-left corner of the crop area |
| `y` | float32 | Required | Y of the top-left corner of the crop area |
| `width` | float32 | Required | Width of the crop area, greater than `0` |
| `height` | float32 | Required | Height of the crop area, greater than `0` |

Units are the resource's own coordinates: pixels for bitmaps, `viewBox` units for SVG, points (1/72 inch) for PDF pages.

### PDF pages (Full)

| Field | Type | Requirement | Description |
| --- | --- | --- | --- |
| `pageCount` | uint32 | Optional | Total number of pages in the document, greater than `0` |
| `pageIndex` | uint32 | Optional | Page currently shown, starting at `0`; defaults to `0` |

### Audio and video (Full)

| Field | Type | Default | Description |
| --- | --- | --- | --- |
| `autoplay` | bool | `false` | Play automatically when the page opens |
| `loop` | bool | `false` | Loop playback |
| `volume` | float32 | `1` | Volume, `0`–`1` |
| `startTime` | float64 | `0` | Start position, in seconds |
| `playbackRate` | float32 | `1` | Playback speed, a finite positive number |

## Rules

### Geometry

* **MEDIA-1** The box of visual media is the rectangle with top-left corner `(0, 0)` and bottom-right corner `(width, height)`, in Canvas units. First take part of the resource according to `crop`, then fit it into the box according to `fit`, finally apply `transform`, and map it with the page's `viewport` (CANVAS-17).
* **MEDIA-2** `transform` is stored as `[a, b, c, d, e, f]`:

  ```text
  x' = a × x + c × y + e
  y' = b × x + d × y + f
  ```

  The matrix handles scaling, rotation, skew and translation. When it is missing, its length is not 6, or it contains non-finite numbers, the identity matrix is used and a warning is reported.
* **MEDIA-3** When `crop` extends beyond the resource, its intersection with the resource is used; when the intersection is empty or the fields are invalid, `crop` is ignored. An unknown `fit` is treated as Fill.

### Content order

* **MEDIA-4** Media shares `contentId` and `undoId` with Ink, Shape and Clear and is drawn in object stream order (FILE-14).
* **MEDIA-5** Erase Ink does not affect Media (INK-11); Clear clears earlier Media.

### Resources

* **MEDIA-6** When the resource package, an entry or the resource is unavailable, keep the Media's position and order and indicate that the resource is missing; strokes, shapes and other Media must not be affected (EXTRA-11).
* **MEDIA-7** SVG is handled as a static image (EXTRA-9).
* **MEDIA-8** UInk registers `application/pdf` as the standard document type. Other documents such as Word and PowerPoint may be used as private types, with no guarantee of interoperability across apps.

### PDF and playback

* **MEDIA-9** When the PDF can be parsed, the actual page count is authoritative; when it disagrees with `pageCount`, the actual page count is used and a warning is reported. An out-of-range `pageIndex` is clamped to the valid range. When the resource is missing, `pageCount` and `pageIndex` may be used to show a page-number placeholder.
* **MEDIA-10** Clamp `startTime` to the range from `0` to the media duration; an invalid `playbackRate` becomes `1`.
* **MEDIA-11** Autoplay may be restricted by platform permissions, muting policies or user settings; failing to autoplay is not an error.

### Error tolerance

* **MEDIA-12** A finite but out-of-range `opacity` or `volume` is clamped to `0`–`1`.
* **MEDIA-13** A Media missing `path` or `mimeType`, or visual media missing `width` / `height`, is skipped and a warning is reported, without affecting the following content.

### Saving

* **MEDIA-14** When Media is present, a full save follows the [resource package commit order](../file/extra#commit-order).

## Example

::: tabs

@tab Image (Standard)

```jsonc
{
  "type": 4,
  "contentId": 2,
  "undoId": 1,
  "path": "images/diagram.png",
  "mimeType": "image/png",
  "width": 800.0,
  "height": 450.0,
  "transform": [1.0, 0.0, 0.0, 1.0, 120.0, 80.0],
  "opacity": 0.9,
  "fit": 1,                                         // Contain
  "crop": { "x": 0.0, "y": 40.0, "width": 1600.0, "height": 900.0 }
}
```

@tab PDF page (Full)

```jsonc
{
  "type": 4,
  "contentId": 3,
  "undoId": 2,
  "path": "documents/lesson.pdf",
  "mimeType": "application/pdf",
  "width": 1280.0,
  "height": 720.0,
  "transform": [1.0, 0.0, 0.0, 1.0, 80.0, 60.0],
  "pageCount": 24,
  "pageIndex": 5
}
```

@tab Audio (Full)

```jsonc
{
  "type": 4,
  "contentId": 4,
  "undoId": 3,
  "path": "audio/explanation.mp3",
  "mimeType": "audio/mpeg",
  "volume": 0.8,
  "startTime": 2.5
}
```

:::

## Fallback

| Capability the reader lacks | How it is shown |
| --- | --- |
| Media (Core, Basic) | Skipped |
| PDF, audio, video (Standard) | Layout placeholder kept, with an "unsupported" notice |

When exporting to Core or Basic, Media may be removed; a PDF may have its current page rasterized to PNG. See [Compatible export](../compatibility#compatible-export).

## Related

* [Resource Package](../file/extra)
* [Canvas Block](canvas)
* [Compatibility and Fallback](../compatibility)
