Skip to content

Commit

Permalink
Merge pull request #139 from apivideo/documentation-swift-player
Browse files Browse the repository at this point in the history
[SDK README - api.video-swift-player] README to documentation synchro
  • Loading branch information
bot-api-video authored Nov 13, 2023
2 parents 4068474 + d06749f commit 200ccb5
Showing 1 changed file with 68 additions and 14 deletions.
82 changes: 68 additions & 14 deletions sdks/player/apivideo-swift-player.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ title: api.video Swift Player
meta:
description: The official api.video Swift Player component for api.video. [api.video](https://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.
---
<!--
THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT!
IF YOU NEED TO CHANGE THIS FILE, CREATE A PR IN THE SOURCE REPOSITORY.
-->

# api.video Swift Player

[api.video](https://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.
[api.video](https://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.

## Project description

Easily integrate a video player for videos from [api.video](https://api.video/) in your Swift
Easily integrate a video player for videos from [api.video](https://api.video) in your Swift
application.

![](https://github.com/apivideo/api.video-swift-player/blob/main/Assets/player-preview.png)
Expand All @@ -35,13 +37,13 @@ Or add this in your Package.swift

```
dependencies: [
.package(url: "https://github.com/apivideo/api.video-swift-player.git", from: "1.1.3"),
.package(url: "https://github.com/apivideo/api.video-swift-player.git", from: "1.1.4"),
],
```

#### Cocoapods

Add `pod 'ApiVideoPlayer', '1.1.3'` in your `Podfile`
Add `pod 'ApiVideoPlayer', '1.1.4'` in your `Podfile`

Run `pod install`

Expand All @@ -63,8 +65,7 @@ a video Id to use this component and play a video from api.video. To get yours,
Alternatively, you can find your video Id in the video details of
your [dashboard](https://dashboard.api.video).


### Code sample
### Usage

1. Imports the library

Expand Down Expand Up @@ -167,17 +168,70 @@ override func viewDidAppear(_ animated: Bool) {

#### Remote control

If you want to enable the remote control do the following:
If you want to enable the remote control do the following:

```swift
override func viewDidLoad() {
...
self.playerView.enableRemoteControl = true
}
```

When you have to remove it set `enableRemoteControl` to false

By default the remote control is hidden.

#### Supported player views

The api.video Swift player comes with a specific view `ApiVideoPlayerView` to display the video
and its controller. If you require a customization of this view such as changing a button color,...,
you can contact [us](https://github.com/apivideo/api.video-swift-player/issues).

Otherwise, in the `ApiVideoPlayerController`, you can also use the following views:

- [`AVPlayerViewController`](https://developer.apple.com/documentation/avkit/avplayerviewcontroller): AVKit view

```swift
// Create the api.video controller
let controller = ApiVideoPlayerController(
videoOptions: VideoOptions(videoId: "vi77Dgk0F8eLwaFOtC5870yn", videoType: .vod),
delegates: [],
autoplay: false
)
// Create the AVKit AVPlayerViewController
let viewController = AVPlayerViewController()

/// Pass the api.video controller to the AVKit AVPlayerViewController
viewController.setApiVideoPlayerController(controller)
// Prepare the view
self.addChild(viewController)
view.addSubview(viewController.view)
// Set the AVKit AVPlayerViewController frame size according to your needs (here it's the whole screen)
viewController.view.frame = self.view.frame
// Do what you want with the video controller (play, pause, seek,...)
controller.play()
```

- [`AVPlayerLayer`](https://developer.apple.com/documentation/avfoundation/avplayerlayer). A view that only display the video. It requires more work to be used.

### Play an api.video video in your AVPlayer

If you are using AVPlayer directly, you can use the api.video Swift extensions:

1. Create a video

```swift
let videoOptions = VideoOptions(videoId: "YOUR_VIDEO_ID", videoType: .vod))
// for private video VideoOptions(videoId: "YOUR_VIDEO_ID", videoType: .vod, token: "YOUR_PRIVATE_VIDEO_TOKEN")
```

2. Pass it to your AVPlayer

```swift
val player = AVPlayer() // You already have that in your code
avPlayer.replaceCurrentItem(withHls: videoOptions)
```

## Sample application

A demo application demonstrates how to use player.
Expand All @@ -190,18 +244,18 @@ On the first run, you will have to set your video Id:

## Documentation

* [Player documentation](https://apivideo.github.io/api.video-swift-player/documentation/apivideoplayer/)
* [api.video documentation](https://docs.api.video/)
- [Player documentation](https://apivideo.github.io/api.video-swift-player/documentation/apivideoplayer/)
- [api.video documentation](https://docs.api.video)

## Dependencies

We are using external library

| Plugin | README |
|---------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
| Plugin | README |
| --------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
| [ApiVideoPlayerAnalytics](https://github.com/apivideo/api.video-swift-player-analytics) | [README.md](https://github.com/apivideo/api.video-swift-player-analytics#readme) |

## FAQ

If you have any questions, ask us here: [https://community.api.video](https://community.api.video) or
use [Issues](https://github.com/apivideo/api.video-swift-player/issues).
use [Issues](https://github.com/apivideo/api.video-swift-player/issues).

0 comments on commit 200ccb5

Please sign in to comment.