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)
- 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
- iOS 10 or above
- Xcode 12 or above
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
.
Add a pod entry to your Podfile :
target 'YourApp' do
pod 'TrailerPlayer', '~> 1.4.8'
...
Install pods
$ pod install
And then import import TrailerPlayer
.
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.)
let playerView = TrailerPlayerView()
let item = TrailerPlayerItem(
url: URL(string: "..."),
thumbnailUrl: URL(string: "..."))
playerView.playbackDelegate = self
playerView.set(item: item)
required public init(url: URL? = nil,
thumbnailUrl: URL? = nil,
thumbnailImage: UIImage? = nil,
autoPlay: Bool = true,
autoReplay: Bool = false,
mute: Bool = true,
isDRMContent: Bool = false)
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)
let item = TrailerPlayerItem(
url: URL(string: "..."),
thumbnailUrl: URL(string: "..."),
autoPlay: false)
playerView.set(item: item)
playerView.manualPlayButton = ... // your custom button
playerView.enablePictureInPicture = true
let controlPanel: UIView = ... // your custom control panel
playerView.addControlPanel(controlPanel)
let replayPanel: UIView = ... // your custom replay panel
playerView.addReplayPanel(replayPanel)
let playerView = TrailerPlayerView()
playerView.enableDebugView = true
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
}
}
// 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)]?
A more detailed example can be found here https://github.com/AbeWang/TrailerPlayer/tree/main/Example, or open TrailerPlayer.xcodeproj