Home

Awesome

Build Status Platform License

KSPlayer

KSPlayer is a powerful media play framework for iOS, tvOS, macOS, xrOS, visionOS, Mac Catalyst, SwiftUI, Apple Silicon M1 .

English | 简体中文

Features

Functional differences between GPL version and LGPL version

FeatureLGPLGPL
AV1 hardware decoding
All demuxers, All decoders
Smoothly Play 120 FPS Video
Record video clips at any time
Dovi P5 displays HDR (not overheating)
Live streaming supports rewind viewing
Preload video on hard disk(supports size control)
Support short video hard disk persistence, play from hard disk next time
Picture in Picture supports subtitle display
Annex-B async hardware decoding(Live Stream)
Use the fonts in the video to render subtitles
Use memory cache for fast seek in short time range
Full display of ass subtitles effect(Render as image using libass)
Play videos in a small window in the App (resumable, supports tvos and ios)
FFmpeg version7.0.26.1.0
Record video
360° panorama video
Picture in Picture
Hardware accelerator
Seamless loop playback
De-interlace auto detect
4k/HDR/HDR10/HDR10+/Dolby Vision
Custom url protocols such as nfs/smb/UPnP
Multichannel Audio/Dolby Atmos/Spatial Audio
Text subtitle/Image subtitle/Closed Captions
Search Online Subtitles(shooter/assrt/opensubtitles)
Low latency 4K live video streaming (less than 200ms on LAN)
Automatically switch to multi-bitrate streams based on network

The list of App using this SDK

App Store LinkTestFlight Link
Alplayer
APTV
homeTV IPTV Player
IPTV +
LillyPlayer Video Player
SenPlayer
Smart IPTV
Snappier IPTV
Spatial Video Studio
TracyPlayerTracyPlayer
UHF - Love your IPTV
Zen IPTV

License

KSPlayer defaults to the GPL license (requires open-sourcing your own project code), and we hope everyone will consciously respect the licensing agreement of the KSPlayer project. Additionally, there is a paid version that adopts the LGPL license (contact us).

If due to commercial reasons, you prefer not to adhere to the GPL license or the LGPL license, you can contact us. Through our authorization, you can obtain a more flexible licensing agreement. Email: kingslay@icloud.com

Requirements

Demo

cd Demo
pod install

Quick Start

CocoaPods

Make sure to use the latest version cocoapods 1.10.1+, which can be installed using the command brew install cocoapods

target 'ProjectName' do
    use_frameworks!
    pod 'KSPlayer',:git => 'https://github.com/kingslay/KSPlayer.git', :branch => 'main'
    pod 'DisplayCriteria',:git => 'https://github.com/kingslay/KSPlayer.git', :branch => 'main'
    pod 'FFmpegKit',:git => 'https://github.com/kingslay/FFmpegKit.git', :branch => 'main'
    pod 'Libass',:git => 'https://github.com/kingslay/FFmpegKit.git', :branch => 'main'
end

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/kingslay/KSPlayer.git", .branch("main"))
]

Usage

Initialization

KSOptions.secondPlayerType = KSMEPlayer.self
playerView = IOSVideoPlayerView()
view.addSubview(playerView)
playerView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
    playerView.topAnchor.constraint(equalTo: view.readableContentGuide.topAnchor),
    playerView.leftAnchor.constraint(equalTo: view.leftAnchor),
    playerView.rightAnchor.constraint(equalTo: view.rightAnchor),
    playerView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
])
playerView.backBlock = { [unowned self] in
    if UIApplication.shared.statusBarOrientation.isLandscape {
        self.playerView.updateUI(isLandscape: false)
    } else {
        self.navigationController?.popViewController(animated: true)
    }
}

Setting up a regular video

playerView.set(url:URL(string: "http://baobab.wdjcdn.com/14525705791193.mp4")!)
playerView.set(resource: KSPlayerResource(url: url, name: name!, cover: URL(string: "http://img.wdjimg.com/image/video/447f973848167ee5e44b67c8d4df9839_0_0.jpeg"), subtitleURL: URL(string: "http://example.ksplay.subtitle")))

Multi-definition, with cover video

let res0 = KSPlayerResourceDefinition(url: URL(string: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")!,
                                      definition: "高清")
let res1 = KSPlayerResourceDefinition(url: URL(string: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")!,
                                      definition: "标清")
   
let asset = KSPlayerResource(name: "Big Buck Bunny",
                             definitions: [res0, res1],
                             cover: URL(string: "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Big_buck_bunny_poster_big.jpg/848px-Big_buck_bunny_poster_big.jpg"))
playerView.set(resource: asset)

Setting up an HTTP header

let options = KSOptions()
options.appendHeader(["Referer":"https:www.xxx.com"])
let definition = KSPlayerResourceDefinition(url: URL(string: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")!,
                                            definition: "高清",
                                            options: options)
let asset = KSPlayerResource(name: "Video Name",
                             definitions: [definition])
playerView.set(resource: asset)

Listening status change

// Listen to play time change
playerView.playTimeDidChange = { (currentTime: TimeInterval, totalTime: TimeInterval) in
    print("playTimeDidChange currentTime: \(currentTime) totalTime: \(totalTime)")
}

// Delegates
public protocol PlayerControllerDelegate: class {
    func playerController(state: KSPlayerState)
    func playerController(currentTime: TimeInterval, totalTime: TimeInterval)
    func playerController(finish error: Error?)
    func playerController(maskShow: Bool)
    func playerController(action: PlayerButtonType)
    // `bufferedCount: 0` indicates first time loading
    func playerController(bufferedCount: Int, consumeTime: TimeInterval)
}

Advanced Usage

Effect

gif

Developments and Tests

Any contributing and pull requests are warmly welcome. However, before you plan to implement some features or try to fix an uncertain issue, it is recommended to open a discussion first. It would be appreciated if your pull requests could build and with all tests green. :)

Backers & Sponsors

Open-source projects cannot live long without your help. If you find KSPlayer to be useful, please consider supporting this project by becoming a sponsor.

Become a sponsor through GitHub Sponsors. :heart:

Your user icon or company logo shows up this with a link to your home page.

UnknownCoder807 skrew
Kimentanm nakiostudio andrefmsilva CodingByJerez byMohamedali romaingyh FantasyKingdom

Thanks to nightfall708 for sponsoring a mac mini

Thanks to cdguy UnknownCoder807 skrew and LillyPlayer community for sponsoring a LG S95QR Sound Bar

Thanks to skrew and LillyPlayer community for sponsoring a 2022 Apple TV 4K

Communication

If you have a business cooperation project or want to initiate a paid consultation, you can contact me via email

1