项目
在 GitHub 查看
wxxsw/VideoPlayer
关于
📽 SwiftUI 视频播放器,支持缓存、边下边播、预加载和自定义控制层。
设计与媒体可以做什么
- 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.
实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- +1
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文
Demo

- Clone or download the project.
- In the terminal, run
swift package resolve. - Open
VideoPlayer.xcodeprojand runDemotarget.
Features
- 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)
}
}
Advances
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)
.autoReplay(autoReplay)
.mute(mute)
.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...
}
}
}
}
Preload
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
Cache
Get the total size of the video cache.
let size = VideoPlayer.calculateCachedSize()
Clean up all caches.
VideoPlayer.cleanAllCache()
Installation
Swift Package Manager
- Select
Xcode -> File -> Swift Packages -> Add Package Dependency... - Enter
https://github.com/wxxsw/VideoPlayer. - Click
Next, then select the version, complete.
Requirements
- iOS 13+
- Xcode 11+
- Swift 5+
Thanks
Banner Design by @aduqin
License
VideoPlayer is released under the MIT license. See LICENSE for details.
探索相关项目
加载中…