api.video is the video infrastructure for product builders. Lightning fast video APIs for integrating, scaling, and managing on-demand & low latency live streaming features in your app.
Easily integrate a video player for videos from api.video in your iOS application.
In the Project Navigator select your own project. Then select the project in the Project section and click on the Package Dependencies tab. Click on the "+" button at the bottom. Paste the below url on the search bar on the top right. Finaly click on "Add package" button.
https://github.com/apivideo/api.video-swift-player
Or add this in your Package.swift
dependencies: [
.package(url: "https://github.com/apivideo/api.video-swift-player.git", from: "1.1.0"),
],
Add pod 'ApiVideoPlayer', '1.1.0'
in your Podfile
Run pod install
At this point, you must have uploaded a least one video to your account. If you haven't see how to upload a video. You'll need a video Id to use this component and play a video from api.video. To get yours, follow these steps:
Alternatively, you can find your video Id in the video details of your dashboard.
import ApiVideoPlayer
let playerView: ApiVideoPlayerView = ApiVideoPlayerView(frame: .zero, videoOptions: VideoOptions(videoId: "YOUR_VIDEO_ID", videoType: .vod)) // for private video VideoOptions(videoId: "YOUR_VIDEO_ID", videoType: .vod, token: "YOUR_PRIVATE_VIDEO_TOKEN")
override func viewDidLoad() {
...
self.addSubview(playerView)
}
To be able to use the player delegate, you must implement the PlayerDelegate protocol.
extension YourViewController: PlayerDelegate {
public func didPrepare() {
// Do what you want when didPrepare is called
}
public func didReady() {
// Do what you want when didReady is called
}
public func didPause() {
// Do what you want when didPause is called
}
public func didPlay() {
// Do what you want when didPlay is called
}
public func didReplay() {
// Do what you want when didReplay is called
}
public func didMute() {
// Do what you want when didMute is called
}
public func didUnMute() {
// Do what you want when didUnMute is called
}
public func didLoop() {
// Do what you want when didLoop is called
}
public func didSetVolume(_: Float) {
// Do what you want when didSetVolume is called
}
public func didSeek(_: CMTime, _: CMTime) {
// Do what you want when didSeek is called
}
public func didEnd() {
// Do what you want when didEnd is called
}
public func didError(_: Error) {
// Do what you want when didError is called
}
public func didVideoSizeChanged(_: CGSize) {
// Do what you want when didVideoSizeChanged is called
}
}
override func viewDidLoad() {
...
self.playerView.addDelegate(self)
}
override func viewDidAppear(_ animated: Bool) {
...
playerView.viewController = self
}
A demo application demonstrates how to use player.
See /example
folder.
On the first run, you will have to set your video Id:
We are using external library
Plugin | README |
---|---|
ApiVideoPlayerAnalytics | README.md |
If you have any questions, ask us here: https://community.api.video or use Issues.
link |
Stars: 11 |
Last commit: 2 hours ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics