Swiftpack.co - wxxsw/GSPlayer as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by wxxsw.
wxxsw/GSPlayer 0.2.26
⏯ Video player, support for caching, preload, fullscreen transition and custom control view. 视频播放器,支持边下边播、预加载、全屏转场和自定义控制层
⭐️ 326
🕓 27 weeks ago
iOS macOS
.package(url: "https://github.com/wxxsw/GSPlayer.git", from: "0.2.26")



  • ☑ Fully customizable UI.
  • ☑ Easy to use API and callbacks.
  • ☑ Built-in caching mechanism to support playback while downloading (mp4).
  • ☑ Can preload multiple videos at any time.
  • ☑ Can be embedded into UITableView and UICollectionView.
  • ☑ Provide full screen transition.
  • ☐ Complete Demo.

Quick Start

  1. Add VideoPlayerView to the interface.
let playerView = VideoPlayerView()

// Or in IB, specify the type of custom View as VideoPlayerView.
  1. Play Video.
playerView.play(for: someURL)
  1. Pause/Resume Video.
if playerView.state == .playing {
    playerView.pause(reason: .userInteraction)
} else {
  1. Update control UI based on playback status.
playerView.stateDidChanged = { state in
    switch state {
    case .none:
    case .error(let error):
        print("error - \(error.localizedDescription)")
    case .loading:
    case .paused(let playing, let buffering):
        print("paused - progress \(Int(playing * 100))% buffering \(Int(buffering * 100))%")
    case .playing:



Get the total size of the video cache.


Clean up all caches.



Set the video URL to be preloaded. 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.

VideoPreloadManager.shared.set(waiting: [URL])

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

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


See demo.



An object that manages a player's visual output.

public let playerLayer: AVPlayerLayer { get }

Get current video status.

public enum State {

    /// None
    case none

    /// From the first load to get the first frame of the video
    case loading

    /// Playing now
    case playing

    /// Pause, will be called repeatedly when the buffer progress changes
    case paused(playing: Double, buffering: Double)

    /// An error occurred and cannot continue playing
    case error(NSError)

public var state: State { get }

The reason the video was paused.

public enum PausedReason {

    /// Pause because the player is not visible, stateDidChanged is not called when the buffer progress changes
    case hidden

    /// Pause triggered by user interaction, default behavior
    case userInteraction

    /// Waiting for resource completion buffering
    case waitingKeepUp

public var pausedReason: PausedReason { get }

Number of replays.

public var replayCount: Int { get }

Played progress, value range 0-1.

public var playing: Double { get }

Played length in seconds.

public var currentDuration: Double { get }

Buffered progress, value range 0-1.

public var buffering: Double { get }

Buffered length in seconds.

public var currentBufferDuration: Double { get }

Total video duration in seconds.

public var totalDuration: Double { get }

The total watch time of this video, in seconds.

public var watchDuration: Double { get }

Whether the video is muted, only for this instance.

public var isMuted: Bool { get set }

Video volume, only for this instance.

public var volume: Double { get set }


Playback status changes, such as from play to pause.

public var stateDidChanged: ((State) -> Void)?

Replay after playing to the end.

public var replay: (() -> Void)?


Play a video of the specified url.

func play(for url: URL)

Pause video.

func pause(reason: PausedReason)

Continue playing video.

func resume()


GSPlayer is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'GSPlayer'



If you find a bug or need a help, you can create a issue

Pull Request

We are happy to accept pull requests :D. But please make sure it's needed by most developers and make it simple to use. If you are not sure, create an issue and we can discuss it before you get to coding.


The MIT License (MIT)


Stars: 326
Last commit: 1 week 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