The easiest way is through CocoaPods. Simply add the dependency to your Podfile
and then pod install
:
pod 'Clappr', '~> 0.6'
let options = [kSourceUrl : "http://clappr.io/highline.mp4"]
let player = Player(options: options)
player.attachTo(yourView, controller: self)
player.on(Event.playing) { userInfo in
print("on Play")
}
You can find public events on Events
enum and listed bellow:
- bufferUpdate
- positionUpdate
- ready
- stalled
- willUpdateAudioSource
- didUpdateAudioSource
- willUpdateSubtitleSource
- didUpdateSubtitleSource
- disableMediaControl
- enableMediaControl
- didComplete
- willPlay
- playing
- willPause
- didPause
- willStop
- didStop
- airPlayStatusUpdate
- requestFullscreen
- exitFullscreen
- error:
userInfo
can contain the error that caused the event.
To add plugins parameters use the options parameter on constructor. Example:
let options = [kSourceUrl : "http://clappr.io/highline.mp4", pluginParameter1: "value1", pluginParameter2: true]
let player = Player(options: options)
Set the video source url with kSourceUrl : "http://clappr.io/highline.mp4"
.
Define a poster by adding kPosterUrl: "http://url/img.png"
on your options. It will appear before the video starts, disappear on play and go back when video finishes.
Add kPlaybackNotSupportedMessage : 'Your custom message'
to define a custom message to be displayed for not supported videos.
Add kAutoPlay: true
if you want the video to play automatically.
Define a start position in seconds with kStartAt : x
. Default is 0
.
Define if video should start in fullscreen mode with kFullscreen: true
. Default is false
.
Add kFullscreenDisabled: true
to disable fullscreen button. Default is false
.
Add kMimeType: 'selected mimetype'
if you need to use a url without extension.
Adding a custom media control is possible by informing the Type
of your class via kMediaControl : YourCustomControl.self
To enable external playback while your app is in background, you should include the audio
value to your app's Background Modes capabilities.
Add the key UIBackgroundModes
. Just after adding it to your Info.plist file, Xcode will translate to a more readable value Required background modes
, which represents an array of values. Then, add a new item with value audio
, which will be translated to App plays audio or streams audio/video using Airplay
.
Click on the target that represents your app. Open the Capabilities tab, and there, you'll see the list of available capabilities. One of them is the Background Modes
. Change its toggle to on
and mark the Audio, Airplay, and Picture in Picture
checkbox.
You can find it here.