Git Product home page Git Product logo

videoplayer's Introduction

VideoPlayer

codebeat badge


Demo

Screenshot

  1. Clone or download the project.
  2. In the terminal, run swift package resolve.
  3. 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

  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

License

VideoPlayer is released under the MIT license. See LICENSE for details.

videoplayer's People

Contributors

wxxsw avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.