api.video Swift Player
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.
Table of contents
Project description
Easily integrate a video player for videos from api.video in your iOS application.
Getting started
Installation
Swift Package Manager
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.3"),
],
Cocoapods
Add pod 'ApiVideoPlayer', '1.1.3'
in your Podfile
Run pod install
Retrieve your video Id
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:
- Log into your account or create one here.
- Copy your API key (sandbox or production if you are subscribed to one of our plan).
- Go to the official api.video documentation.
- Log into your account in the top right corner. If it's already done, be sure it's the account you want to use.
- Go to API Reference -> Videos -> List all videos
- On the right, be sure the "Authentication" section contains the API key you want to use.
- Generate your upload token by clicking the "Try It!" button in the right section
- Copy the "videoId" value of one of elements of the response in the right section.
Alternatively, you can find your video Id in the video details of your dashboard.
Code sample
- Imports the library
import ApiVideoPlayer
- Instantiates the player view
let playerView: ApiVideoPlayerView = ApiVideoPlayerView(frame: .zero, videoOptions: VideoOptions(videoId: , videoType: .vod)) // for private video VideoOptions(videoId: "YOUR_VIDEO_ID", videoType: .vod, token: "YOUR_PRIVATE_VIDEO_TOKEN")
- Adds the player view as a subview of your view controller
override
- Delegates the player events
To be able to use the player delegate, you must implement the PlayerDelegate protocol.
extension YourViewController: PlayerDelegate {
public
public
public
public
public
public
public
public
public
public
public
public
public
}
- Registers the delegate
override
- To use fullscreen, you must pass the view controller to the player view
override
Remote control
If you want to enable the remote control do the following:
override
When you have to remove it set enableRemoteControl
to false
By default the remote control is hidden.
Sample application
A demo application demonstrates how to use player.
See /example
folder.
On the first run, you will have to set your video Id:
- Replace "YOUR_VIDEO_ID" by your video Id
Documentation
Dependencies
We are using external library
Plugin | README |
---|---|
ApiVideoPlayerAnalytics | README.md |
FAQ
If you have any questions, ask us here: https://community.api.video or use Issues.
Was this page helpful?