# resolveAdapterType

Resolve which type of adapter plays a source URL, from its host, MIME type, or file extension

## Import

```ts
import { resolveAdapterType } from '@videojs/html';
```

`resolveAdapterType` reads a source URL and returns the type of adapter that plays it, so an app that plays sources from a catalog or from user input can pick the matching [media component](../../guides/media-sources.md). It returns `null` for sources it doesn’t recognize.

Resolution is a pure string check. It doesn’t fetch the source, load an engine, or touch the DOM. It doesn’t rewrite the source either: every source it recognizes, [shorthands](#shorthands) included, is one the matching media component accepts as its `src`.

## Usage

Look up the media component for the result and give it the same `src`:

```ts
import { resolveAdapterType } from '@videojs/html';
import '@videojs/html/media/hlsjs-video';
import '@videojs/html/media/vimeo-video';
import '@videojs/html/media/youtube-video';

const TAGS = { youtube: 'youtube-video', vimeo: 'vimeo-video', hls: 'hlsjs-video', video: 'video' } as const;

function createMedia(src: string) {
  const type = resolveAdapterType(src);
  const tag = type && type in TAGS ? TAGS[type as keyof typeof TAGS] : null;
  if (!tag) return null;

  const media = document.createElement(tag);
  media.setAttribute('src', src);
  return media;
}
```

Each media module you import adds its engine to your bundle, so import the rarely used ones dynamically.

### Adapter types

| Adapter type | Recognized sources | Media component |
| --- | --- | --- |
| `youtube` | `youtube.com` (including `music.youtube.com`), `youtu.be`, and `youtube-nocookie.com` video and playlist URLs | `<youtube-video>` |
| `vimeo` | `vimeo.com` and `player.vimeo.com` URLs | `<vimeo-video>` |
| `wistia` | `wistia.com`, `wistia.net`, and `wi.st` URLs, and pages with a `wvideo` parameter | `<wistia-video>` |
| `mux` | `stream.mux.com` stream URLs, with or without `.m3u8` | `<mux-video>` or `<mux-audio>` |
| `cloudflare` | `cloudflarestream.com` and `videodelivery.net` URLs | `<cloudflare-video>` |
| `spotify` | `open.spotify.com` URLs and `spotify:` URIs | `<spotify-audio>` |
| `soundcloud` | `soundcloud.com` track and set URLs, `api.soundcloud.com` tracks and playlists, and `w.soundcloud.com/player/` embed URLs | `<soundcloud-audio>` |
| `mixcloud` | `mixcloud.com` show URLs and Mixcloud widget embed URLs | `<mixcloud-audio>` |
| `tiktok` | `tiktok.com` video URLs | `<tiktok-video>` |
| `twitch` | `twitch.tv` video and channel URLs, and `player.twitch.tv` embed URLs | `<twitch-video>` |
| `dailymotion` | `dailymotion.com` video and embed URLs, `dai.ly` short links, and `geo.dailymotion.com` player embed URLs | `<dailymotion-video>` |
| `playerjs` | URLs with a `playerjs` query parameter | `<playerjs-video>` |
| `hls` | `.m3u8` files and HLS MIME types | `<hls-video>`, `<hlsjs-video>`, or `<native-hls-video>` |
| `dash` | `.mpd` files and `application/dash+xml` | `<dash-video>` or `<shaka-video>` |
| `video` | `.mp4`, `.webm`, `.mov`, and `.ogv` files, and `video/*` MIME types | `<video>` |
| `audio` | `.mp3`, `.m4a`, `.wav`, `.ogg`, `.flac`, and `.aac` files, and `audio/*` MIME types | `<audio>` |

`hls` covers every HLS adapter and `dash` every DASH adapter, so an HLS stream comes back as `hls` whichever one you play it with; see [Media sources](../../guides/media-sources.md) to choose one. Mux streams served from a custom domain are recognized as plain `hls`.

player.js is a protocol any embed can speak, so nothing in an embed’s URL says it’s one. Add a `playerjs` query parameter, such as `https://streamable.com/e/moo?playerjs`, to resolve the URL as `playerjs` whatever its host or file extension. The player.js media removes the parameter before loading the embed.

### MIME types

Pass a MIME type as the second argument when the URL doesn’t end in a file extension, such as an extensionless manifest or a `blob:` URL. The MIME type takes precedence over the extension; service URLs, such as YouTube or Mux, resolve the same either way.

```ts
resolveAdapterType('https://example.com/manifest', 'application/vnd.apple.mpegurl'); // 'hls'
```

To get the MIME type a file extension implies, use [`resolveMimeType`](./resolve-mime-type.md).

### Bare ids

A bare id returns `null`. An 11-character YouTube id and a 10-character Wistia id look alike, so services are only recognized from URLs, `spotify:` URIs, and [shorthands](#shorthands). If you already know the service, pass the id to its media component directly.

### Shorthands

`resolveAdapterType` recognizes these shorthands, and the YouTube and Vimeo media accept them as `src`:

| Shorthand | Plays |
| --- | --- |
| `youtube/<id>`, `youtube/shorts/<id>` | The YouTube video, from the privacy-enhanced `youtube-nocookie.com` host |
| `vimeo/<id>` | The Vimeo video |
| `vimeo/<id>?hash=<hash>`, `vimeo/<id>?h=<hash>`, `vimeo/<id>/<hash>` | The unlisted Vimeo video |

## API Reference

`resolveAdapterType(src, type?): AdapterType | null`

### Parameters

| Parameter | Type | Default | Description |
| --- | --- | --- | --- |
| `src` (required) | `string` | — | The source URL, or a `youtube/<id>` or `vimeo/<id>` shorthand. |
| `type` | `string` | — | The source's MIME type, when known. It takes precedence over the file extension, so manifests and files without one can still be resolved. Parameters such as `codecs` are ignored. |

### Return Value

| Type |
| --- |
| `'youtube' \| 'vimeo' \| 'wistia' \| 'mux' \| 'cloudflare' \| 'spotify' \| 'soundcloud' \| 'mixcloud' \| 'tiktok' \| 'twitch' \| 'dailymotion' \| 'playerjs' \| 'hls' \| 'dash' \| 'video' \| 'audio' \| null` |