-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
790 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/************************************************************************************************* | ||
* Document | ||
*************************************************************************************************/ | ||
|
||
* { | ||
box-sizing: border-box; | ||
} | ||
|
||
html, | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
width: 100vw; | ||
height: 100vh; | ||
} | ||
|
||
body { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
main { | ||
width: 100%; | ||
max-width: 980px; | ||
margin-inline: auto; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<html> | ||
<head> | ||
<title>Vidstack React Sandbox</title> | ||
|
||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
|
||
<link rel="icon" type="image/png" sizes="32x32" href="/sandbox/favicon-32x32.png" /> | ||
|
||
<link rel="stylesheet" href="./document.css" /> | ||
<link rel="stylesheet" href="./player.css" /> | ||
|
||
<script src="./main.tsx" type="module"></script> | ||
</head> | ||
|
||
<body> | ||
<main> | ||
<div id="player"></div> | ||
</main> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
|
||
import ReactDOM from 'react-dom/client'; | ||
|
||
import { Player } from './player'; | ||
|
||
const root = document.getElementById('player')!; | ||
ReactDOM.createRoot(root).render( | ||
<React.StrictMode> | ||
<Player /> | ||
</React.StrictMode>, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
@import '../player/styles/base.css'; | ||
@import '../player/styles/default/buffering.css'; | ||
@import '../player/styles/default/buttons.css'; | ||
@import '../player/styles/default/captions.css'; | ||
@import '../player/styles/default/chapter-title.css'; | ||
@import '../player/styles/default/controls.css'; | ||
@import '../player/styles/default/gestures.css'; | ||
@import '../player/styles/default/icons.css'; | ||
@import '../player/styles/default/menus.css'; | ||
@import '../player/styles/default/poster.css'; | ||
@import '../player/styles/default/sliders.css'; | ||
@import '../player/styles/default/thumbnail.css'; | ||
@import '../player/styles/default/time.css'; | ||
@import '../player/styles/default/tooltips.css'; | ||
@import '../player/styles/default/layouts/audio.css'; | ||
@import '../player/styles/default/layouts/video.css'; | ||
|
||
.player { | ||
--brand-color: #f5f5f5; | ||
--focus-color: #4e9cf6; | ||
|
||
--audio-brand: var(--brand-color); | ||
--audio-focus-ring-color: var(--focus-color); | ||
--audio-border-radius: 2px; | ||
|
||
--video-brand: var(--brand-color); | ||
--video-focus-ring-color: var(--focus-color); | ||
--video-border-radius: 2px; | ||
|
||
/* 👉 https://vidstack.io/docs/player/components/layouts/default#css-variables for more. */ | ||
|
||
width: 100%; | ||
} | ||
|
||
.player[data-view-type='video'] { | ||
aspect-ratio: 16 /9; | ||
} | ||
|
||
.src-buttons { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-evenly; | ||
margin-top: 40px; | ||
margin-inline: auto; | ||
max-width: 300px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { useEffect, useRef, useState } from 'react'; | ||
|
||
import { | ||
isHLSProvider, | ||
MediaPlayer, | ||
MediaProvider, | ||
Poster, | ||
Track, | ||
type MediaCanPlayDetail, | ||
type MediaCanPlayEvent, | ||
type MediaPlayerInstance, | ||
type MediaProviderAdapter, | ||
type MediaProviderChangeEvent, | ||
} from '../src'; | ||
import { | ||
DefaultAudioLayout, | ||
defaultLayoutIcons, | ||
DefaultVideoLayout, | ||
} from '../src/components/layouts/default'; | ||
import { textTracks } from './tracks'; | ||
|
||
export function Player() { | ||
let player = useRef<MediaPlayerInstance>(null), | ||
[src, setSrc] = useState(''); | ||
|
||
useEffect(() => { | ||
// Initialize src. | ||
changeSource('audio'); | ||
|
||
// Subscribe to state updates. | ||
return player.current!.subscribe(({ paused, viewType }) => { | ||
// console.log('is paused?', '->', paused); | ||
// console.log('is audio view?', '->', viewType === 'audio'); | ||
}); | ||
}, []); | ||
|
||
function onProviderChange( | ||
provider: MediaProviderAdapter | null, | ||
nativeEvent: MediaProviderChangeEvent, | ||
) { | ||
// We can configure provider's here. | ||
if (isHLSProvider(provider)) { | ||
provider.config = {}; | ||
} | ||
} | ||
|
||
// We can listen for the `can-play` event to be notified when the player is ready. | ||
function onCanPlay(detail: MediaCanPlayDetail, nativeEvent: MediaCanPlayEvent) { | ||
// ... | ||
} | ||
|
||
function changeSource(type: string) { | ||
const muxPlaybackId = 'VZtzUzGRv02OhRnZCxcNg49OilvolTqdnFLEqBsTwaxU'; | ||
switch (type) { | ||
case 'audio': | ||
setSrc('https://media-files.vidstack.io/sprite-fight/audio.mp3'); | ||
break; | ||
case 'video': | ||
setSrc(`https://stream.mux.com/${muxPlaybackId}/low.mp4`); | ||
break; | ||
case 'hls': | ||
setSrc(`https://stream.mux.com/${muxPlaybackId}.m3u8`); | ||
break; | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<MediaPlayer | ||
className="player" | ||
title="Sprite Fight" | ||
src={src} | ||
crossorigin | ||
onProviderChange={onProviderChange} | ||
onCanPlay={onCanPlay} | ||
ref={player} | ||
> | ||
<MediaProvider> | ||
<Poster | ||
className="vds-poster" | ||
src="https://image.mux.com/VZtzUzGRv02OhRnZCxcNg49OilvolTqdnFLEqBsTwaxU/thumbnail.webp?time=268&width=1200" | ||
alt="Girl walks into campfire with gnomes surrounding her friend ready for their next meal!" | ||
/> | ||
{textTracks.map((track) => ( | ||
<Track {...track} key={track.src} /> | ||
))} | ||
</MediaProvider> | ||
|
||
{/* Layouts */} | ||
<DefaultAudioLayout icons={defaultLayoutIcons} /> | ||
<DefaultVideoLayout | ||
icons={defaultLayoutIcons} | ||
thumbnails="https://image.mux.com/VZtzUzGRv02OhRnZCxcNg49OilvolTqdnFLEqBsTwaxU/storyboard.vtt" | ||
/> | ||
</MediaPlayer> | ||
|
||
<div className="src-buttons"> | ||
<button onClick={() => changeSource('audio')}>Audio</button> | ||
<button onClick={() => changeSource('video')}>Video</button> | ||
<button onClick={() => changeSource('hls')}>HLS</button> | ||
</div> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
@import '../player/styles/base.css'; | ||
@import '../player/styles/default/buffering.css'; | ||
@import '../player/styles/default/buttons.css'; | ||
@import '../player/styles/default/captions.css'; | ||
@import '../player/styles/default/chapter-title.css'; | ||
@import '../player/styles/default/controls.css'; | ||
@import '../player/styles/default/gestures.css'; | ||
@import '../player/styles/default/icons.css'; | ||
@import '../player/styles/default/menus.css'; | ||
@import '../player/styles/default/poster.css'; | ||
@import '../player/styles/default/sliders.css'; | ||
@import '../player/styles/default/thumbnail.css'; | ||
@import '../player/styles/default/time.css'; | ||
@import '../player/styles/default/tooltips.css'; | ||
@import '../player/styles/default/layouts/audio.css'; | ||
@import '../player/styles/default/layouts/video.css'; | ||
|
||
/************************************************************************************************* | ||
* Player | ||
*************************************************************************************************/ | ||
|
||
media-player { | ||
--brand-color: #f5f5f5; | ||
--focus-color: #4e9cf6; | ||
|
||
--audio-brand: var(--brand-color); | ||
--audio-focus-ring-color: var(--focus-color); | ||
--audio-border-radius: 2px; | ||
|
||
--video-brand: var(--brand-color); | ||
--video-focus-ring-color: var(--focus-color); | ||
--video-border-radius: 2px; | ||
|
||
/* 👉 https://vidstack.io/docs/player/components/layouts/default#css-variables for more. */ | ||
|
||
width: 100%; | ||
} | ||
|
||
media-player[data-view-type='video'] { | ||
aspect-ratio: 16 /9; | ||
} | ||
|
||
/************************************************************************************************* | ||
* Document | ||
*************************************************************************************************/ | ||
|
||
* { | ||
box-sizing: border-box; | ||
} | ||
|
||
html, | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
width: 100vw; | ||
height: 100vh; | ||
} | ||
|
||
body { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
main { | ||
width: 100%; | ||
max-width: 980px; | ||
margin-inline: auto; | ||
} | ||
|
||
.src-buttons { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-evenly; | ||
margin-top: 40px; | ||
margin-inline: auto; | ||
max-width: 300px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export const textTracks = [ | ||
// Subtitles | ||
{ | ||
src: 'https://media-files.vidstack.io/sprite-fight/subs/english.vtt', | ||
label: 'English', | ||
language: 'en-US', | ||
kind: 'subtitles', | ||
default: true, | ||
}, | ||
{ | ||
src: 'https://media-files.vidstack.io/sprite-fight/subs/spanish.vtt', | ||
label: 'Spanish', | ||
language: 'es-ES', | ||
kind: 'subtitles', | ||
}, | ||
// Chapters | ||
{ | ||
src: 'https://media-files.vidstack.io/sprite-fight/chapters.vtt', | ||
kind: 'chapters', | ||
language: 'en-US', | ||
default: true, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@vidstack/react", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "UI component library for building high-quality, accessible video and audio experiences on the web.", | ||
"license": "MIT", | ||
"type": "module", | ||
|
@@ -21,6 +21,8 @@ | |
"prebuild": "node .scripts/prebuild.js", | ||
"build": "pnpm prebuild && rollup -c", | ||
"build:types": "tsc -p tsconfig.build.json", | ||
"sandbox": "node ../../.scripts/sandbox.js", | ||
"sandbox:build": "vite build sandbox", | ||
"types": "pnpm build:types && rollup -c --config-types", | ||
"clean": "rimraf dist styles", | ||
"format": "prettier src --write --loglevel warn" | ||
|
@@ -33,13 +35,14 @@ | |
"media-captions": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@maverick-js/cli": "0.40.2", | ||
"@maverick-js/cli": "0.40.3", | ||
"@rollup/plugin-node-resolve": "^15.1.0", | ||
"@types/fs-extra": "^11.0.1", | ||
"@types/react": "^18.0.0", | ||
"@vitejs/plugin-react": "^4.1.0", | ||
"esbuild": "^0.16.17", | ||
"fs-extra": "^11.0.0", | ||
"maverick.js": "0.40.2", | ||
"maverick.js": "0.40.3", | ||
"media-icons": "^1.0.0", | ||
"react": "^18.0.0", | ||
"react-dom": "^18.0.0", | ||
|
@@ -48,7 +51,8 @@ | |
"rollup-plugin-dts": "^5.3.0", | ||
"rollup-plugin-esbuild": "^5.0.0", | ||
"typescript": "^5.2.2", | ||
"vidstack": "workspace:*" | ||
"vidstack": "workspace:*", | ||
"vite": "^4.4.9" | ||
}, | ||
"contributors": [ | ||
"Rahim Alwer <[email protected]>" | ||
|
Oops, something went wrong.