|
| 1 | +# Material UI Player - Agent Guide |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +React component library for audio and video playback styled with Material UI. Exports three components: `AudioCard`, `VideoCard`, and `SoundButton`. |
| 6 | + |
| 7 | +- **Package**: `material-ui-player` (v2.0.0) |
| 8 | +- **Language**: TypeScript |
| 9 | +- **Framework**: React 18+ with Material UI 7+ |
| 10 | +- **Build**: Webpack 5 (output: CommonJS) |
| 11 | +- **Docs**: Storybook 7 |
| 12 | + |
| 13 | +## Repository Structure |
| 14 | + |
| 15 | +``` |
| 16 | +src/ |
| 17 | +├── components/ # Exported components + internal sub-components |
| 18 | +│ ├── AudioCard.tsx # Full audio player with controls |
| 19 | +│ ├── VideoCard.tsx # Full video player with controls |
| 20 | +│ ├── SoundButton.tsx # Simple play-audio icon button |
| 21 | +│ ├── ControlKeys.tsx # Play/Pause/Stop/Forward/Backward buttons |
| 22 | +│ ├── Progress.tsx # Seek slider |
| 23 | +│ ├── VolumeBar.tsx # Volume slider + mute |
| 24 | +│ ├── SpeedBar.tsx # Playback speed control |
| 25 | +│ └── MediaTime.tsx # Time display (current / duration) |
| 26 | +├── hooks/ |
| 27 | +│ └── useMedia.ts # Core hook: manages playback state via useReducer |
| 28 | +├── state/ |
| 29 | +│ ├── types.ts # Action type constants |
| 30 | +│ └── reducer.ts # Reducer handling PLAY, PAUSE, UPDATE_TIME, etc. |
| 31 | +├── icons/ # Custom SVG icon components (Play, Pause, Stop, etc.) |
| 32 | +├── lib/ |
| 33 | +│ └── utils.ts # Time formatting, MIME detection, slider sizing, fade math |
| 34 | +├── types/ |
| 35 | +│ └── index.ts # Public TypeScript interfaces and types |
| 36 | +├── stories/ # Storybook stories (public/ = exported API demos) |
| 37 | +└── index.ts # Package entry point (re-exports the 3 components) |
| 38 | +``` |
| 39 | + |
| 40 | +## Key Commands |
| 41 | + |
| 42 | +```bash |
| 43 | +# Build the library (TypeScript → dist/) |
| 44 | +npm run build |
| 45 | + |
| 46 | +# Start Storybook dev server on port 6006 |
| 47 | +npm run storybook |
| 48 | + |
| 49 | +# Build static Storybook site to public/ |
| 50 | +npm run build-storybook |
| 51 | +``` |
| 52 | + |
| 53 | +There is no test suite configured. |
| 54 | + |
| 55 | +## Architecture |
| 56 | + |
| 57 | +### State Management |
| 58 | + |
| 59 | +Each player instance uses `useReducer` with a local reducer (`src/state/reducer.ts`). The `useMedia` hook (`src/hooks/useMedia.ts`) wraps the reducer and exposes actions: `play`, `pause`, `stop`, `setCurrentTime`, `setProgress`, `load`, `setSize`. |
| 60 | + |
| 61 | +Playback time updates are driven by `setInterval` during play, dispatching `UPDATE_TIME` on each tick. |
| 62 | + |
| 63 | +### Source Resolution |
| 64 | + |
| 65 | +The `src` prop accepts four forms: |
| 66 | +- `string` — direct URL |
| 67 | +- `Promise<string>` — resolved when play is clicked |
| 68 | +- `() => string` — called on play |
| 69 | +- `() => Promise<string>` — called on play, then awaited |
| 70 | + |
| 71 | +This deferred resolution enables dynamic URLs (e.g., Firebase Storage signed URLs). |
| 72 | + |
| 73 | +### Component Hierarchy |
| 74 | + |
| 75 | +``` |
| 76 | +AudioCard / VideoCard |
| 77 | +├── <audio> / <video> (hidden/visible HTML element) |
| 78 | +├── Progress (seek slider) |
| 79 | +├── ControlKeys (play/pause/stop/fwd/bwd buttons) |
| 80 | +├── VolumeBar (volume slider + mute) |
| 81 | +├── SpeedBar (playback rate) |
| 82 | +└── MediaTime (time display) |
| 83 | +
|
| 84 | +SoundButton |
| 85 | +└── IconButton + hidden <audio> |
| 86 | +``` |
| 87 | + |
| 88 | +### Styling |
| 89 | + |
| 90 | +Components use Material UI's `sx` prop and `Grid` layout. Slider appearance is customized via the `thickness` prop (`thin` | `medium` | `large`), which maps to pixel values in `utils.ts`. The `color` prop (`primary` | `secondary`) passes through to MUI components. All components must be rendered inside a MUI `<ThemeProvider>`. |
| 91 | + |
| 92 | +### Video Fade Effect |
| 93 | + |
| 94 | +`VideoCard` supports optional `fadeSettings` (`{ fadeInTime, fadeOutTime }`) that adjust the video element's opacity at the beginning and end of playback, calculated in `utils.ts:getFade()`. |
| 95 | + |
| 96 | +## Peer Dependencies |
| 97 | + |
| 98 | +``` |
| 99 | +@emotion/react >= 11.0.0 |
| 100 | +@emotion/styled >= 11.0.0 |
| 101 | +@mui/material >= 7.0.0 |
| 102 | +react >= 18.0.0 |
| 103 | +react-dom >= 18.0.0 |
| 104 | +``` |
| 105 | + |
| 106 | +These are externalized in the Webpack build and must be provided by the consuming application. |
| 107 | + |
| 108 | +## Public API |
| 109 | + |
| 110 | +Exports from `material-ui-player`: |
| 111 | + |
| 112 | +| Export | Description | |
| 113 | +|---|---| |
| 114 | +| `AudioCard` | Audio player card with full controls | |
| 115 | +| `VideoCard` | Video player card with full controls and optional fade | |
| 116 | +| `SoundButton` | Minimal icon button for short audio playback | |
| 117 | + |
| 118 | +All prop interfaces are defined in `src/types/index.ts`. Key interfaces: `MaterialUIMediaProps` (shared AudioCard/VideoCard props), `BaseProps` (shared by all), `IconButtonProps` (button customization), `FadeSettings` (video fade config). |
| 119 | + |
| 120 | +## Conventions |
| 121 | + |
| 122 | +- Components are default-exported from their files, then re-exported as named exports from `src/index.ts`. |
| 123 | +- Internal sub-components (`ControlKeys`, `Progress`, etc.) are not exported from the package. |
| 124 | +- Icons are custom SVG components in `src/icons/`, not imported from `@mui/icons-material`. |
| 125 | +- No external state libraries — all state is local via `useReducer`. |
| 126 | +- No test framework is set up; interactive testing is done through Storybook. |
0 commit comments