Skip to content

Repository files navigation

KMP Video Player 🎬

A cross-platform video player application built with Kotlin Multiplatform (KMP) for Android and iOS, featuring integration with the Pexels Video API.

Features ✨

  • 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

Tech Stack πŸ› οΈ

Shared Layer (Kotlin Multiplatform)

  • Kotlin Coroutines - Async operations & state management
  • Ktor Client - HTTP networking library
  • Kotlinx Serialization - JSON parsing
  • Pexels Video API - Video data source

Android

  • Jetpack Compose - Modern declarative UI framework
  • Media3 (ExoPlayer) - Professional video player
  • Lifecycle - ViewModel & state management
  • Coil - Image loading library

iOS

  • SwiftUI - Apple's modern UI framework
  • AVPlayer - Native video playback
  • Combine - Reactive programming framework

Project Structure πŸ“

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)

Screenshots πŸ“Έ

Android App

Video List Screen

Android Video List Screen

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

Video Player Screen

Android Video Player Screen

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

Getting Started πŸš€

Installation Steps

1. Clone the Repository

cd MoviePlayer

2. Get Pexels API Key

  1. Visit Pexels API
  2. Click "Request API" button
  3. Sign up for a free account

3. Configure API Key

For Android:

  1. Open androidApp/src/main/kotlin/dev/rrb/movieplayer/android/MainActivity.kt
  2. Replace YOUR_PEXELS_API_KEY_HERE with your actual API key
VideoSearchScreen(apiKey = "YOUR_ACTUAL_API_KEY")

For iOS:

  1. Open iosApp/iosApp/ContentView.swift
  2. Replace YOUR_PEXELS_API_KEY_HERE with your actual API key
VideoPlayerViewModel(apiKey: "YOUR_ACTUAL_API_KEY")

4. Build and Run

Android:

# Build the app
./gradlew androidApp:build

# Install on connected device or emulator
./gradlew androidApp:installDebug

# Or run directly
./gradlew androidApp:run

iOS:

# Navigate to iOS app directory
cd iosApp/iosApp

# Open in Xcode
open iosApp.xcodeproj

# Select simulator or device
# Press Cmd + R to run

Usage πŸ’‘

Android App Flow

  1. Launch App β†’ Popular videos load automatically
  2. Browse Videos β†’ Scroll through video list with thumbnails
  3. Search Videos β†’ Enter search term and tap "Search"
  4. Play Video β†’ Tap any video card to open player
  5. Control Playback β†’ Use ExoPlayer controls (play, pause, seek, volume)
  6. Return to List β†’ Tap "Back to List" button

iOS App Flow

  1. Launch App β†’ Popular videos load automatically
  2. Browse Videos β†’ Scroll through video list
  3. Search Videos β†’ Enter search term and tap "Search"
  4. Play Video β†’ Tap any video to open player
  5. Control Playback β†’ Use AVPlayer controls
  6. Return to List β†’ Tap "Back to List" button

API Integration πŸ”Œ

Pexels Video API

Endpoint: https://api.pexels.com/videos/search

Shared Layer (KMP)

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

Android Layer

ui/
β”œβ”€β”€ VideoSearchScreen.kt       # Video list UI
β”œβ”€β”€ VideoPlayerScreen.kt       # Player UI
β”œβ”€β”€ VideoSearchViewModel.kt    # ViewModel
└── VideoSearchViewModelFactory.kt

iOS Layer

Models/
└── VideoModels.swift

ViewModels/
└── VideoPlayerViewModel.swift

Views/
β”œβ”€β”€ VideoListView.swift
└── VideoPlayerView.swift

Data Flow

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

About

Cross-platform video player built with Kotlin Multiplatform. Features Pexels API integration, ExoPlayer for Android, AVPlayer for iOS, and beautiful UI with Compose & SwiftUI

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages