Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wxxsw/VideoPlayer
📽 A video player for SwiftUI, support for caching, preload and custom control view. SwiftUI 视频播放器,支持边下边播、预加载、自定义控制层
https://github.com/wxxsw/VideoPlayer
avplayer player swift swiftui videoplayer
Last synced: about 1 month ago
JSON representation
📽 A video player for SwiftUI, support for caching, preload and custom control view. SwiftUI 视频播放器,支持边下边播、预加载、自定义控制层
- Host: GitHub
- URL: https://github.com/wxxsw/VideoPlayer
- Owner: wxxsw
- License: mit
- Created: 2019-07-14T00:18:25.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-08-16T12:25:45.000Z (over 1 year ago)
- Last Synced: 2024-11-14T02:02:22.936Z (about 1 month ago)
- Topics: avplayer, player, swift, swiftui, videoplayer
- Language: Swift
- Homepage: https://github.com/wxxsw/VideoPlayer
- Size: 4.59 MB
- Stars: 671
- Watchers: 8
- Forks: 105
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-swiftui-libraries - VideoPlayer - A video player for SwiftUI, support for caching, preload and custom control view (Video / Content)
- fucking-about-SwiftUI - VideoPlayer
README
![VideoPlayer](https://github.com/wxxsw/VideoPlayer/blob/master/Images/logo.png)
- [Features](#features)
- [QuickStart](#quick-start)
- [Advances](#advances)
- [Installation](#installation)
- [Requirements](#requirements)
- [License](#license)## Demo
![Screenshot](https://github.com/wxxsw/VideoPlayer/blob/master/Images/screenshot.png)
1. Clone or download the project.
2. In the terminal, run `swift package resolve`.
3. Open `VideoPlayer.xcodeproj` and run `Demo` target.## Features
- [x] Fully customizable UI.
- [x] Plays local media or streams remote media over HTTP.
- [x] Built-in caching mechanism to support playback while downloading.
- [x] Can preload multiple videos at any time.
- [x] Support seek to duration.
- [x] Simple API.## Quick Start
```swift
struct ContentView : View {
@State private var play: Bool = true
var body: some View {
VideoPlayer(url: someVideoURL, play: $play)
}
}
```## Advances
```swift
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.
```swift
VideoPlayer.preload(urls: [URL])
```Set the preload size, the default value is 1024 * 1024, unit is byte.
```swift
VideoPlayer.preloadByteCount = 1024 * 1024 // = 1M
```### Cache
Get the total size of the video cache.
```swift
let size = VideoPlayer.calculateCachedSize()
```Clean up all caches.
```swift
VideoPlayer.cleanAllCache()
```## Installation
### 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.## Requirements
- iOS 13+
- Xcode 11+
- Swift 5+## Thanks
Banner Design by [@aduqin](https://dribbble.com/aduqin)
## License
VideoPlayer is released under the MIT license. [See LICENSE](https://github.com/wxxsw/VideoPlayer/blob/master/LICENSE) for details.