Swift 4.x 需切换到对应分支(swift4.2 / swift4.0),否则编译不通过;设置本地或远程地址时必须带文件扩展名;带自定义 HTTP 头或播放 iCloud/PHAsset 视频时需改用 asset 或 playerItem 而非 url
Player
piemonteMIT更新放缓用 Swift 封装的轻量级视频播放器,基于 AVFoundation,支持本地播放和流媒体,适合 iOS 与 tvOS 应用快速集成播放能力。
▶️ Play and stream media in Swift
pod "Player", "~> 0.15.0"
或 SPM: .package(url: "https://github.com/piemonte/Player.git", from: "0.15.0")README 未说明;仅支持 iOS 与 tvOS 平台,需 Swift 5.0+
Swift 编写的 iOS/tvOS 视频播放库,几行代码即可播放本地或 HTTP 流媒体
用 Swift 封装的轻量级视频播放器,基于 AVFoundation,支持本地播放和流媒体,适合 iOS 与 tvOS 应用快速集成播放能力。
核心能力
- 支持播放本地媒体和 HTTP 远程流媒体
- 可自定义 UI 与用户交互行为
- 支持屏幕旋转和任意尺寸
- 提供视频帧截图能力
- 通过 delegate 回调播放进度与结束事件
容易踩的坑
暂无 release 数据(可能没有发版,或尚未同步)。
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。

Player
Player is a simple iOS/tvOS video player library written in Swift.
- Looking for an obj-c video player? Check out PBJVideoPlayer (obj-c).
- Looking for a Swift camera library? Check out Next Level.
Need a different version of Swift?
5.0- Target your Podfile to the latest release or master4.2- Target your Podfile to theswift4.2branch4.0- Target your Podfile to theswift4.0branch
Features
- plays local media or streams remote media over HTTP
- customizable UI and user interaction
- no size restrictions
- orientation change support
- simple API
- video frame snapshot support
Quick Start
Player is available for installation using Swift Package Manager, CocoaPods, or by manually copying the Player.swift file into your Xcode project.
Swift Package Manager
Add Player to your Package.swift dependencies:
dependencies: [
.package(url: "https://github.com/piemonte/Player.git", from: "0.15.0")
]
Or add it directly in Xcode via File > Add Package Dependencies and enter the repository URL.
CocoaPods
pod "Player", "~> 0.15.0"
Manual Installation
Simply copy the Player.swift file from the Sources directory into your Xcode project.
Usage
The sample project provides an example of how to integrate Player, otherwise you can follow these steps.
Allocate and add the Player controller to your view hierarchy.
self.player = Player()
self.player.playerDelegate = self
self.player.playbackDelegate = self
self.player.view.frame = self.view.bounds
self.addChild(self.player)
self.view.addSubview(self.player.view)
self.player.didMove(toParent: self)
Provide the file path to the resource you would like to play locally or stream. Ensure you're including the file extension.
let videoUrl: URL = // file or http url
self.player.url = videoUrl
For HTTP streams with custom headers, use AVAsset:
let videoUrl: URL = // http url
let headers = ["Authorization": "Bearer token123"]
let asset = AVURLAsset(url: videoUrl, options: ["AVURLAssetHTTPHeaderFieldsKey": headers])
self.player.asset = asset
For iCloud Photos or PHAsset videos, use AVPlayerItem:
let playerItem: AVPlayerItem = // your player item
self.player.playerItem = playerItem
play/pause
self.player.playFromBeginning()
Adjust the fill mode for the video, if needed.
self.player.fillMode = .resizeAspectFit
Display video playback progress, if needed.
extension ViewController: PlayerPlaybackDelegate {
public func playerPlaybackWillStartFromBeginning(_ player: Player) {
}
public func playerPlaybackDidEnd(_ player: Player) {
}
public func playerCurrentTimeDidChange(_ player: Player) {
let fraction = Double(player.currentTime) / Double(player.maximumDuration)
self._playbackViewController?.setProgress(progress: CGFloat(fraction), animated: true)
}
public func playerPlaybackWillLoop(_ player: Player) {
self. _playbackViewController?.reset()
}
}
Documentation
You can find the docs here. Documentation is generated with jazzy and hosted on GitHub-Pages.
Community
- Need help? Use Stack Overflow with the tag 'player-swift'.
- Questions? Use Stack Overflow with the tag 'player-swift'.
- Found a bug? Open an issue.
- Feature idea? Open an issue.
- Want to contribute? Submit a pull request.
Resources
- Swift Evolution
- AV Foundation Programming Guide
- Next Level, rad media capture in Swift
- PBJVision, iOS camera engine, features touch-to-record video, slow motion video, and photo capture
- PBJVideoPlayer, a simple iOS video player library, written in obj-c
License
Player is available under the MIT license, see the LICENSE file for more information.