Swiftpack.co - wxxsw/VideoPlayer as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by wxxsw.
wxxsw/VideoPlayer 1.2.4
📽 A video player for SwiftUI, support for caching, preload and custom control view. SwiftUI 视频播放器,支持边下边播、预加载、自定义控制层
⭐️ 523
🕓 6 weeks ago
.package(url: "https://github.com/wxxsw/VideoPlayer.git", from: "1.2.4")


codebeat badge



  1. Clone or download the project.
  2. In the terminal, run swift package resolve.
  3. Open VideoPlayer.xcodeproj and run Demo target.


  • ☑ Fully customizable UI.
  • ☑ Plays local media or streams remote media over HTTP.
  • ☑ Built-in caching mechanism to support playback while downloading.
  • ☑ Can preload multiple videos at any time.
  • ☑ Support seek to duration.
  • ☑ Simple API.

Quick Start

struct ContentView : View {
    @State private var play: Bool = true
    var body: some View {
        VideoPlayer(url: someVideoURL, play: $play)


struct ContentView : View {  
    @State private var autoReplay: Bool = true 
    @State private var mute: Bool = false      
    @State private var play: Bool = true       
    @State private var time: CMTime = .zero  
    var body: some View {
        VideoPlayer(url: someVideoURL, play: $play, time: $time)
            .onBufferChanged { progress in
                // Network loading buffer progress changed
            .onPlayToEndTime { 
                // Play to the end time.
            .onReplay { 
                // Replay after playing to the end. 
            .onStateChanged { state in 
                switch state {
                case .loading:
                    // Loading...
                case .playing(let totalDuration):
                    // Playing...
                case .paused(let playProgress, let bufferProgress):
                    // Paused...
                case .error(let error):
                    // Error...


Set the video urls to be preload queue. Preloading will automatically cache a short segment of the beginning of the video and decide whether to start or pause the preload based on the buffering of the currently playing video.

VideoPlayer.preload(urls: [URL])

Set the preload size, the default value is 1024 * 1024, unit is byte.

VideoPlayer.preloadByteCount = 1024 * 1024 // = 1M


Get the total size of the video cache.

let size = VideoPlayer.calculateCachedSize()

Clean up all caches.



Swift Package Manager

  1. Select Xcode -> File -> Swift Packages -> Add Package Dependency...
  2. Enter https://github.com/wxxsw/VideoPlayer.
  3. Click Next, then select the version, complete.


  • iOS 13+
  • Xcode 11+
  • Swift 5+


Banner Design by @aduqin


VideoPlayer is released under the MIT license. See LICENSE for details.


Stars: 523
Last commit: 6 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.


Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics