A cross-platform video player application built with Kotlin Multiplatform (KMP) for Android and iOS, featuring integration with the Pexels Video API.
- Cross-Platform: Shared business logic between Android and iOS
- Video Streaming: Stream videos from Pexels API
- Search Functionality: Search for videos by keywords
- Popular Videos: Auto-load popular videos on app launch
- Thumbnail Preview: Display video thumbnails in the list
- Video Player:
- Android: ExoPlayer with full controls
- iOS: AVPlayer with native controls
- Responsive UI: Beautiful Material Design (Android) and SwiftUI (iOS)
- Error Handling: Graceful error messages and retry options
- High-quality Videos: Multiple resolution options available
- Kotlin Coroutines - Async operations & state management
- Ktor Client - HTTP networking library
- Kotlinx Serialization - JSON parsing
- Pexels Video API - Video data source
- Jetpack Compose - Modern declarative UI framework
- Media3 (ExoPlayer) - Professional video player
- Lifecycle - ViewModel & state management
- Coil - Image loading library
- SwiftUI - Apple's modern UI framework
- AVPlayer - Native video playback
- Combine - Reactive programming framework
MoviePlayer/
βββ shared/ # Shared KMP code
β βββ src/commonMain/kotlin/
β β βββ data/
β β β βββ models/
β β β β βββ PexelsVideo.kt # API response models
β β β βββ remote/
β β β βββ PexelsApiClient.kt
β β βββ domain/
β β βββ PlaylistManager.kt # State management
β βββ build.gradle.kts
β
βββ androidApp/ # Android application
β βββ src/main/kotlin/
β β βββ ui/
β β β βββ VideoSearchScreen.kt
β β β βββ VideoPlayerScreen.kt
β β β βββ VideoSearchViewModel.kt
β β βββ MainActivity.kt
β βββ build.gradle.kts
β
βββ iosApp/ # iOS application
β βββ iosApp/
β β βββ Models/
β β β βββ VideoModels.swift
β β βββ ViewModels/
β β β βββ VideoPlayerViewModel.swift
β β βββ Views/
β β β βββ VideoListView.swift
β β β βββ VideoPlayerView.swift
β β βββ ContentView.swift
β β βββ iOSApp.swift
β β βββ Info.plist
β βββ iosApp.xcodeproj
β
βββ gradle/
β βββ libs.versions.toml # Centralized dependency management
β
βββ build.gradle.kts (root)
Features:
- Auto-loads popular videos on app launch
- Beautiful card design with video thumbnails
- Video duration and photographer name displayed
- Search bar for finding specific videos
- Play button for quick access
Features:
- Full-screen ExoPlayer with native controls
- Play/Pause, Seek, and Volume controls
- Video information displayed below player
- Quick back button to return to list
- Smooth video playback
cd MoviePlayer- Visit Pexels API
- Click "Request API" button
- Sign up for a free account
For Android:
- Open
androidApp/src/main/kotlin/dev/rrb/movieplayer/android/MainActivity.kt - Replace
YOUR_PEXELS_API_KEY_HEREwith your actual API key
VideoSearchScreen(apiKey = "YOUR_ACTUAL_API_KEY")For iOS:
- Open
iosApp/iosApp/ContentView.swift - Replace
YOUR_PEXELS_API_KEY_HEREwith your actual API key
VideoPlayerViewModel(apiKey: "YOUR_ACTUAL_API_KEY")Android:
# Build the app
./gradlew androidApp:build
# Install on connected device or emulator
./gradlew androidApp:installDebug
# Or run directly
./gradlew androidApp:runiOS:
# Navigate to iOS app directory
cd iosApp/iosApp
# Open in Xcode
open iosApp.xcodeproj
# Select simulator or device
# Press Cmd + R to run- Launch App β Popular videos load automatically
- Browse Videos β Scroll through video list with thumbnails
- Search Videos β Enter search term and tap "Search"
- Play Video β Tap any video card to open player
- Control Playback β Use ExoPlayer controls (play, pause, seek, volume)
- Return to List β Tap "Back to List" button
- Launch App β Popular videos load automatically
- Browse Videos β Scroll through video list
- Search Videos β Enter search term and tap "Search"
- Play Video β Tap any video to open player
- Control Playback β Use AVPlayer controls
- Return to List β Tap "Back to List" button
Endpoint: https://api.pexels.com/videos/search
data/
βββ models/
β βββ Video.kt # Main video model
β βββ PlaybackState.kt # Playback state model
β βββ PexelsVideo.kt # Pexels API models
βββ remote/
βββ PexelsApiClient.kt # API communication
domain/
βββ PlaylistManager.kt # Business logic & state management
ui/
βββ VideoSearchScreen.kt # Video list UI
βββ VideoPlayerScreen.kt # Player UI
βββ VideoSearchViewModel.kt # ViewModel
βββ VideoSearchViewModelFactory.kt
Models/
βββ VideoModels.swift
ViewModels/
βββ VideoPlayerViewModel.swift
Views/
βββ VideoListView.swift
βββ VideoPlayerView.swift
API (Pexels)
β
PexelsApiClient (Shared)
β
PlaylistManager (Shared) β StateFlow
β
Android (ViewModel) ββ iOS (ViewModel)
β
UI (Compose) ββ UI (SwiftUI)
```β¨
### Video List Screen
- β
Auto-loads popular videos
- β
Lazy loading with thumbnails
- β
Search functionality
- β
Video duration display
- β
Photographer information
- β
Material Design cards (Android)
- β
SwiftUI native appearance (iOS)
### Video Player
- β
Full-screen video playback
- β
Play/Pause controls
- β
Seek bar with timestamp
- β
Volume control
- β
Video information display
- β
Back navigation
- β
Automatic cleanup on exit
## Performance Optimization β‘
- **Lazy Image Loading**: Thumbnails loaded on-demand with Coil (Android)
- **Efficient Coroutines**: Non-blocking API calls
- **Memory Management**: Proper player resource cleanup
- **Efficient JSON Parsing**: Using kotlinx.serialization
- **Network Optimization**: Connection reuse with Ktor
### Code Style
- Follow Kotlin naming conventions
- Use meaningful variable names
- Add comments for complex logic
- Keep functions small and focused

