Swiftpack.co - AbeWang/TrailerPlayer as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by AbeWang.
AbeWang/TrailerPlayer 1.4.8
iOS video player for trailer. (Like Netflix trailer UI)
⭐️ 13
🕓 2 years ago
iOS
.package(url: "https://github.com/AbeWang/TrailerPlayer.git", from: "1.4.8")

Trailer Player

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

https://user-images.githubusercontent.com/1064039/136514197-452bfecd-fe68-465d-9621-781056485286.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

GitHub

link
Stars: 13
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

TrailerPlayer v1.4.8
2 years ago
  • Fixes autoPlay issue. (#2)

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics