Giter Site home page Giter Site logo

pawansharmazee5 / trailerplayer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from abewang/trailerplayer

0.0 0.0 0.0 236 KB

iOS video player for trailer. (Like Netflix trailer UI)

License: MIT License

Swift 96.93% Ruby 1.85% Objective-C 1.21%

trailerplayer's Introduction

Trailer Player

iOS video player for trailer. You can customize layout for the control panel. Support PiP and DRM.

custom_control_panel.mov

Icons by Icons8 (https://icons8.com)

Features

  • For the content without trailers :
  • Show thumbnail directly
  • For the content with trailers :
  • In the beginning, the thumbnail will be displayed directly. After the trailer is loading completed, the trailer will be auto-played from the beginning, and at this moment, the thumbnail will be hidden. After the trailer completes playback, the thumbnail image will display (Or show the replay panel if you provided it).
  • Customize layout for the control panel and replay panel
  • Basic functions - Play / Pause / Stop / Seek / Replay
  • Audio on/off - Default is OFF (muted)
  • Fullscreen on/off
  • Support PiP (Picture-in-Picture)
  • Support FairPlay DRM
  • Debug view - Bitrate / Framerate / Resolution / TrailerUrl / PlaybackItemUrl

Requirements

  • iOS 10 or above
  • Xcode 12 or above

Installation

Swift Package Manager

Add a package dependency to your Xcode project, select File > Swift Packages > Add Package Dependency and enter repository URL https://github.com/AbeWang/TrailerPlayer. Then import import TrailerPlayer.

CocoaPods

Add a pod entry to your Podfile :

target 'YourApp' do
    pod 'TrailerPlayer', '~> 1.4.8'
    ...

Install pods

$ pod install

And then import import TrailerPlayer.

Carthage

Add TrailerPlayer to your Cartfile :

github "AbeWang/TrailerPlayer" ~> 1.4.8

Run carthage update

$ carthage update --use-xcframeworks

Add the TrailerPlayer xcframework to your project. (XCFramework will not require the usage of the carthage copy-frameworks script anymore.)

How to use

let playerView = TrailerPlayerView()
let item = TrailerPlayerItem(
            url: URL(string: "..."),
            thumbnailUrl: URL(string: "..."))
playerView.playbackDelegate = self
playerView.set(item: item)

TrailerPlayerItem settings

required public init(url: URL? = nil,                
                     thumbnailUrl: URL? = nil,       
                     thumbnailImage: UIImage? = nil, 
                     autoPlay: Bool = true,          
                     autoReplay: Bool = false,       
                     mute: Bool = true,              
                     isDRMContent: Bool = false)     

TrailerPlayerPlaybackDelegate

func trailerPlayer(_ player: TrailerPlayer, didUpdatePlaybackTime time: TimeInterval)
func trailerPlayer(_ player: TrailerPlayer, didChangePlaybackStatus status: TrailerPlayerPlaybackStatus)
func trailerPlayerPlaybackReady(_ player: TrailerPlayer)
func trailerPlayer(_ player: TrailerPlayer, playbackDidFailed error: TrailerPlayerPlaybackError)

[Optional] Manual Play

let item = TrailerPlayerItem(
            url: URL(string: "..."),
            thumbnailUrl: URL(string: "..."),
            autoPlay: false)
playerView.set(item: item)
playerView.manualPlayButton = ... // your custom button

[Optional] Support PiP

playerView.enablePictureInPicture = true

[Optional] Panel settings

let controlPanel: UIView = ... // your custom control panel
playerView.addControlPanel(controlPanel)

let replayPanel: UIView = ... // your custom replay panel
playerView.addReplayPanel(replayPanel)

[Optional] Debug view

IMG_0012

let playerView = TrailerPlayerView()
playerView.enableDebugView = true

[Optional] Support DRM

let playerView = TrailerPlayerView()
let item = TrailerPlayerItem(
            url: URL(string: "..."),
            thumbnailUrl: URL(string: "..."),
            isDRMContent: true)
playerView.playbackDelegate = self
playerView.DRMDelegate = self
playerView.set(item: item)

// DRM Delegate
extension ViewController: TrailerPlayerDRMDelegate {
    
    func certUrl(for player: TrailerPlayer) -> URL {
        return URL(string: ...) // your certificate url
    }
    
    func ckcUrl(for player: TrailerPlayer) -> URL {
        return URL(string: ...) // your ckc url
    }
}

TrailerPlayerDRMDelegate

// CKC(Content Key Context) URL
func ckcUrl(for player: TrailerPlayer) -> URL
// Certificate URL
func certUrl(for player: TrailerPlayer) -> URL
// Optional: content Id for SPC(Server Playback Context) message
func contentId(for player: TrailerPlayer) -> String?
// Optional: HTTP header fields for CKC request
func ckcRequestHeaderFields(for player: TrailerPlayer) -> [(headerField: String, value: String)]?

Detailed Example

A more detailed example can be found here https://github.com/AbeWang/TrailerPlayer/tree/main/Example, or open TrailerPlayer.xcodeproj

trailerplayer's People

Contributors

abewang 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.