|
| 1 | +# YouTube-Style Video Player Implementation |
| 2 | + |
| 3 | +## Overview |
| 4 | +Successfully implemented a YouTube-style draggable video player with mini player functionality, exactly matching the gesture behavior from the reference repository (https://github.com/guneyural/youtube-clone). |
| 5 | + |
| 6 | +## Key Features |
| 7 | + |
| 8 | +### 1. Pan Gesture Video Player |
| 9 | +- **Drag Down**: Minimizes video to mini player at bottom-right |
| 10 | +- **Drag Up**: Expands mini player back to full screen |
| 11 | +- **Swipe Down Further**: Closes player completely |
| 12 | +- **Tap Mini Player**: Expands to full screen |
| 13 | + |
| 14 | +### 2. Smooth Animations |
| 15 | +All animations use spring physics for natural feel: |
| 16 | +- Video height: 33% screen → 150px → 60px (mini) |
| 17 | +- Video width: 100% → 30% |
| 18 | +- Mini player slides in from right |
| 19 | +- Content opacity fades during drag |
| 20 | +- Position interpolates smoothly |
| 21 | + |
| 22 | +### 3. Mini Player Features |
| 23 | +- Muted video thumbnail continues playing |
| 24 | +- Shows content title (truncated if long) |
| 25 | +- Displays episode info for TV shows (S1 E1) |
| 26 | +- Play/pause button |
| 27 | +- Close button |
| 28 | +- Tap anywhere to expand |
| 29 | + |
| 30 | +### 4. Gesture Thresholds |
| 31 | +- Drag > 100px: Minimizes to mini player |
| 32 | +- Drag < 100px: Snaps back to full screen |
| 33 | +- Drag > screen height - 80px: Closes completely |
| 34 | + |
| 35 | +### 5. Detail Screen Content |
| 36 | +- Full video player with controls |
| 37 | +- Content title and like button |
| 38 | +- Overview/description |
| 39 | +- Episodes list (for TV shows) |
| 40 | +- Similar content recommendations |
| 41 | +- Video scraping integration |
| 42 | + |
| 43 | +### 6. Back Button Handling |
| 44 | +- When expanded: Minimizes to mini player |
| 45 | +- When minimized: Handled by navigation |
| 46 | + |
| 47 | +## Architecture |
| 48 | + |
| 49 | +### New Files Created |
| 50 | + |
| 51 | +#### 1. `src/context/VideoPlayerContext.tsx` |
| 52 | +Global state management for video player: |
| 53 | +```typescript |
| 54 | +interface VideoPlayerState { |
| 55 | + content: Movie | TVShow | null; |
| 56 | + videoUrl: string; |
| 57 | + isPlaying: boolean; |
| 58 | + currentTime: number; |
| 59 | + duration: number; |
| 60 | + selectedSeason?: number; |
| 61 | + selectedEpisode?: number; |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +**Methods:** |
| 66 | +- `openDetailSheet(content)` - Opens player with content |
| 67 | +- `closeDetailSheet()` - Closes player and clears state |
| 68 | +- `setVideoUrl(url)` - Updates video URL |
| 69 | +- `setPlaybackState(isPlaying, currentTime, duration)` - Syncs playback |
| 70 | +- `setEpisodeInfo(season, episode)` - Sets episode info |
| 71 | + |
| 72 | +#### 2. `src/components/VideoPlayerSheet/VideoPlayerSheet.tsx` |
| 73 | +Main video player component with gestures: |
| 74 | +- Pan gesture handler for drag interactions |
| 75 | +- Animated interpolations for smooth transitions |
| 76 | +- Video player integration |
| 77 | +- Content details display |
| 78 | +- Episode selection |
| 79 | +- Similar content recommendations |
| 80 | + |
| 81 | +#### 3. `src/components/VideoPlayerSheet/index.tsx` |
| 82 | +Export file for the component |
| 83 | + |
| 84 | +### Modified Files |
| 85 | + |
| 86 | +#### 1. `App.tsx` |
| 87 | +- Added `VideoPlayerProvider` wrapper |
| 88 | +- Added `AppContent` component to access video player context |
| 89 | +- Conditionally renders `VideoPlayerSheet` when content is selected |
| 90 | + |
| 91 | +#### 2. `src/context/index.ts` |
| 92 | +- Exported `VideoPlayerProvider` and `useVideoPlayer` |
| 93 | + |
| 94 | +#### 3. `src/screens/HomeScreen.tsx` |
| 95 | +- Uses `openDetailSheet()` instead of `navigation.navigate('Detail')` |
| 96 | +- Removed Detail screen navigation |
| 97 | + |
| 98 | +#### 4. `src/screens/SearchScreen.tsx` |
| 99 | +- Uses `openDetailSheet()` instead of `navigation.navigate('Detail')` |
| 100 | +- Removed Detail screen navigation |
| 101 | + |
| 102 | +#### 5. `src/navigation/AppNavigator.tsx` |
| 103 | +- Removed Detail screen from navigation stack |
| 104 | +- Detail content now opens via overlay instead of navigation |
| 105 | + |
| 106 | +#### 6. `src/types/navigation.ts` |
| 107 | +- Removed `Detail` route from `RootStackParamList` |
| 108 | + |
| 109 | +## Technical Implementation |
| 110 | + |
| 111 | +### Gesture Handling |
| 112 | +Uses `react-native-gesture-handler` Gesture API: |
| 113 | +```typescript |
| 114 | +const panGesture = Gesture.Pan() |
| 115 | + .onStart(() => { |
| 116 | + context.value = {y: translationY.value}; |
| 117 | + }) |
| 118 | + .onUpdate(event => { |
| 119 | + translationY.value = event.translationY + context.value.y; |
| 120 | + translationY.value = Math.max(0, translationY.value); |
| 121 | + }) |
| 122 | + .onEnd(() => { |
| 123 | + // Snap to positions based on threshold |
| 124 | + }); |
| 125 | +``` |
| 126 | + |
| 127 | +### Animation Interpolations |
| 128 | +Uses `react-native-reanimated` for 60fps animations: |
| 129 | + |
| 130 | +**Video Height:** |
| 131 | +```typescript |
| 132 | +interpolate( |
| 133 | + translationY, |
| 134 | + [0, SCREEN_HEIGHT - 300, SCREEN_HEIGHT - 80], |
| 135 | + [VIDEO_HEIGHT, 150, MINI_PLAYER_HEIGHT], |
| 136 | + Extrapolation.CLAMP |
| 137 | +) |
| 138 | +``` |
| 139 | + |
| 140 | +**Video Width:** |
| 141 | +```typescript |
| 142 | +interpolate( |
| 143 | + translationY, |
| 144 | + [0, 500, SCREEN_HEIGHT - 80], |
| 145 | + [100, 100, 30], // percentages |
| 146 | + Extrapolation.CLAMP |
| 147 | +) |
| 148 | +``` |
| 149 | + |
| 150 | +**Mini Player Position:** |
| 151 | +```typescript |
| 152 | +interpolate( |
| 153 | + translationY, |
| 154 | + [0, 500, SCREEN_HEIGHT - 80], |
| 155 | + [500, 500, 125], // translateX values |
| 156 | + Extrapolation.CLAMP |
| 157 | +) |
| 158 | +``` |
| 159 | + |
| 160 | +**Opacity:** |
| 161 | +```typescript |
| 162 | +interpolate( |
| 163 | + translationY, |
| 164 | + [0, 350, 600], |
| 165 | + [1, 0.5, 0], |
| 166 | + Extrapolation.CLAMP |
| 167 | +) |
| 168 | +``` |
| 169 | + |
| 170 | +### State Synchronization |
| 171 | +- Video playback state syncs between full player and mini player |
| 172 | +- Episode info persists during minimize/maximize |
| 173 | +- Video URL maintained across transitions |
| 174 | +- Playback continues seamlessly |
| 175 | + |
| 176 | +## Usage |
| 177 | + |
| 178 | +### Opening Content |
| 179 | +```typescript |
| 180 | +const {openDetailSheet} = useVideoPlayer(); |
| 181 | + |
| 182 | +// On content card press |
| 183 | +openDetailSheet(movieOrTVShow); |
| 184 | +``` |
| 185 | + |
| 186 | +### User Interactions |
| 187 | +1. **View Content**: Tap any movie/TV show card |
| 188 | +2. **Minimize**: Drag video player down |
| 189 | +3. **Expand**: Drag mini player up or tap it |
| 190 | +4. **Close**: Swipe mini player down or press close button |
| 191 | +5. **Browse**: Continue browsing with mini player visible |
| 192 | +6. **Select Episode**: Tap episode to play (TV shows) |
| 193 | + |
| 194 | +## Benefits |
| 195 | + |
| 196 | +1. **Better UX**: Browse while video plays |
| 197 | +2. **Familiar Pattern**: YouTube-like interaction |
| 198 | +3. **Smooth Performance**: 60fps animations |
| 199 | +4. **Gesture-Based**: Intuitive swipe controls |
| 200 | +5. **Seamless Playback**: Video continues during transitions |
| 201 | +6. **Episode Support**: Easy episode switching for TV shows |
| 202 | +7. **Content Discovery**: Similar content recommendations |
| 203 | + |
| 204 | +## Dependencies Used |
| 205 | + |
| 206 | +- `react-native-gesture-handler`: Gesture recognition |
| 207 | +- `react-native-reanimated`: High-performance animations |
| 208 | +- `react-native-video`: Video playback |
| 209 | +- `@react-native-vector-icons/material-icons`: Icons |
| 210 | + |
| 211 | +## Testing |
| 212 | + |
| 213 | +To test the implementation: |
| 214 | +1. Run the app |
| 215 | +2. Tap any content card from home or search |
| 216 | +3. Video player sheet slides up |
| 217 | +4. Drag down to minimize |
| 218 | +5. Drag up or tap to expand |
| 219 | +6. Swipe down far to close |
| 220 | +7. Try with TV shows to test episode selection |
| 221 | + |
| 222 | +## Notes |
| 223 | + |
| 224 | +- Mini player shows muted video thumbnail |
| 225 | +- Full player has audio and controls |
| 226 | +- Back button minimizes when expanded |
| 227 | +- Video scraping happens automatically |
| 228 | +- Similar content loads in background |
| 229 | +- Episode list shows first 5 episodes |
| 230 | + |
| 231 | +## Future Enhancements |
| 232 | + |
| 233 | +Possible improvements: |
| 234 | +- Full episode list with seasons selector |
| 235 | +- Picture-in-picture mode |
| 236 | +- Playlist/queue functionality |
| 237 | +- Swipe between episodes |
| 238 | +- Download progress in mini player |
| 239 | +- Cast button integration |
| 240 | +- Subtitle selector in mini player |
0 commit comments