Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions examples/react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ const App = () => {
},
vimeo: {
color: 'ffffff'
},
spotify: {
preferVideo: true
}
}}
onLoadStart={() => console.log('onLoadStart')}
Expand Down Expand Up @@ -467,6 +470,19 @@ const App = () => {
{renderLoadButton('https://home.wistia.com/medias/bq6epni33s', 'Test C')}
</td>
</tr>
<tr>
<th>Spotify</th>
<td>
{renderLoadButton('https://open.spotify.com/episode/5Jo9ncrz2liWiKj8inZwD2', 'Test A')}
</td>
</tr>
<tr>
<th>Twitch</th>
<td>
{renderLoadButton('https://www.twitch.tv/videos/106400740', 'Test A')}
{renderLoadButton('https://www.twitch.tv/kronovi', 'Test B')}
</td>
</tr>
<tr>
<th>Custom</th>
<td>
Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
"dash-video-element": "^0.1.5",
"deepmerge": "^4.0.0",
"hls-video-element": "^1.5.5",
"spotify-audio-element": "^1.0.1",
"twitch-video-element": "^0.1.0",
"vimeo-video-element": "^1.5.1",
"wistia-video-element": "^1.3.2",
"youtube-video-element": "^1.6.0"
Expand Down
4 changes: 4 additions & 0 deletions src/patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export const MATCH_URL_YOUTUBE =
export const MATCH_URL_VIMEO = /vimeo\.com\/(?!progressive_redirect).+/;
export const MATCH_URL_WISTIA =
/(?:wistia\.(?:com|net)|wi\.st)\/(?:medias|embed)\/(?:iframe\/)?([^?]+)/;
export const MATCH_URL_SPOTIFY = /open\.spotify\.com\/(\w+)\/(\w+)/i;
Copy link

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider anchoring the Spotify URL regex (e.g. using end-of-string or query parameter anchors) to align with other MATCH_URL patterns and prevent unintended partial matches.

Suggested change
export const MATCH_URL_SPOTIFY = /open\.spotify\.com\/(\w+)\/(\w+)/i;
export const MATCH_URL_SPOTIFY = /open\.spotify\.com\/(\w+)\/(\w+)($|\?)/i;

Copilot uses AI. Check for mistakes.
export const MATCH_URL_TWITCH = /(?:www\.|go\.)?twitch\.tv\/([a-zA-Z0-9_]+|(videos?\/|\?video=)\d+)($|\?)/;

const canPlayFile = (url: string, test: (u: string) => boolean) => {
if (Array.isArray(url)) {
Expand All @@ -36,4 +38,6 @@ export const canPlay = {
vimeo: (url: string) =>
MATCH_URL_VIMEO.test(url) && !VIDEO_EXTENSIONS.test(url) && !HLS_EXTENSIONS.test(url),
wistia: (url: string) => MATCH_URL_WISTIA.test(url),
spotify: (url: string) => MATCH_URL_SPOTIFY.test(url),
twitch: (url: string) => MATCH_URL_TWITCH.test(url),
};
18 changes: 18 additions & 0 deletions src/players.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ const Players: PlayerEntry[] = [
() => import(/* webpackChunkName: 'reactPlayerWistia' */ 'wistia-video-element/react')
) as React.LazyExoticComponent<React.ComponentType<VideoElementProps>>,
},
{
key: 'spotify',
name: 'Spotify',
canPlay: canPlay.spotify,
canEnablePIP: () => false,
player: lazy(
() => import(/* webpackChunkName: 'reactPlayerSpotify' */ 'spotify-audio-element/react')
) as React.LazyExoticComponent<React.ComponentType<VideoElementProps>>,
},
{
key: 'twitch',
name: 'Twitch',
canPlay: canPlay.twitch,
canEnablePIP: () => false,
player: lazy(
() => import(/* webpackChunkName: 'reactPlayerTwitch' */ 'twitch-video-element/react')
) as React.LazyExoticComponent<React.ComponentType<VideoElementProps>>,
},
{
key: 'html',
name: 'html',
Expand Down
15 changes: 11 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type { MediaHTMLAttributes, SyntheticEvent } from 'react';
import type HlsVideoElement from 'hls-video-element';
import type SpotifyAudioElement from 'spotify-audio-element';
import type YouTubeVideoElement from 'youtube-video-element';
import type VimeoVideoElement from 'vimeo-video-element';
import type TwitchVideoElement from 'twitch-video-element';

interface VideoHTMLAttributes<T> extends MediaHTMLAttributes<T> {
height?: number | string | undefined;
Expand Down Expand Up @@ -39,11 +44,13 @@ export interface PreviewProps {
}

export interface Config {
html?: Record<string, unknown>;
hls?: Record<string, unknown>;
dash?: Record<string, unknown>;
hls?: HlsVideoElement['config'];
html?: Record<string, unknown>;
mux?: Record<string, unknown>;
youtube?: Record<string, unknown>;
vimeo?: Record<string, unknown>;
spotify?: SpotifyAudioElement['config'];
twitch?: TwitchVideoElement['config'];
vimeo?: VimeoVideoElement['config'];
wistia?: Record<string, unknown>;
youtube?: YouTubeVideoElement['config'];
}