videos player.php_轻云/VideoPlayer

logo.png

language-Swift%205-f48041.svg?style=flat

framework-SwiftUI-blue.svg?style=flat

platform-iOS%2013%2b-blue.svg?style=flat

SPM-compatible-4BC51D.svg?style=flat

030d7cd9-f1ed-46b0-b6cc-90928ef7c941

license-MIT-lightgrey.svg?style=flat

Demo

screenshot.png

Clone or download the project.

In the terminal, run swift package resolve.

Open VideoPlayer.xcodeproj and run Demo target.

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值