> ## Documentation Index
> Fetch the complete documentation index at: https://cloudinary.com/documentation/llms.txt
> Use this file to discover all available pages before exploring further.

# iOS video player


The iOS SDK includes a Cloudinary native video player based on [AVPlayer](https://developer.apple.com/documentation/avfoundation/avplayer/). This makes it easy to use the various Cloudinary video capabilities and deliver your videos as well as capturing [video analytics](video_analytics) by default.

To create a player, use the `CLDVideoPlayer` function to initialize it, providing either the public ID for the video or the full Cloudinary URL:

```swift
//Public ID
let player = CLDVideoPlayer(publicId: "dog", cloudinary: cloudinary)

//URL string
let player = CLDVideoPlayer(url: "https://res.cloudinary.com/demo/video/upload/sp_auto/dog.m3u8")

//URL
let player = CLDVideoPlayer(url: URL(string: "https://res.cloudinary.com/demo/video/upload/sp_auto/dog.m3u8"))

```

Once you have the player instance, you can embed that into an `AVPlayerViewController` to use in your view.

Here's an example:

```swift
    let player = CLDVideoPlayer(publicId: "dog", cloudinary: cloudinary)
    let playerController = AVPlayerViewController()

    playerController.player = player
    addChild(playerController)
    playerController.videoGravity = .resizeAspectFill
    videoView.addSubview(playerController.view)
    playerController.view.frame = videoView.bounds
    playerController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    playerController.didMove(toParent: self)
    player.play()
```

## Transformations

You can include video transformations as part of your `CLDVideoPlayer` instance in the same way as when using the [createUrl](ios_video_manipulation#deliver_videos) method. The transformations are defined when initializing the player. For example:

```swift
let player = CLDVideoPlayer(publicId: "dog", cloudinary: cloudinary, transformation: CLDTransformation().setEffect("reverse"))
```

> **NOTE**: [Automatic streaming profile selection](adaptive_bitrate_streaming#automatic_streaming_profile_selection) is disabled by default. To enable it, set the `automaticStreamingProfile` parameter to `true` when initializing the player. For example:
  
  
  ```swift
  let player = CLDVideoPlayer(publicId: "dog", cloudinary: cloudinary, automaticStreamingProfile: true)

  ```

This feature currently has a [limited set of transformations](adaptive_bitrate_streaming#combining_transformations_with_automatic_streaming_profile_selection) that you can combine with it, therefore when using any transformations ensure that they are compatible before including with automatic streaming profile selection enabled.

## Analytics

By default, Cloudinary [video analytics](video_analytics) are enabled when using the Cloudinary native video player. This automatically sends a variety of metrics to Cloudinary to allow you to assess the performance of your video assets. Use the `setAnalytics` function of your player instance to switch to manual collection or disable the analytics entirely. Manual collection allows you to specify a cloud name or public ID instead of the player automatically detecting this.

For example:

```swift
player.setAnalytics(.manual, cloudName: cloudinary.config.cloudName, publicId: "sea_turtle")
```

or to disable:

```swift
player.setAnalytics(.disabled, cloudName: nil, publicId: nil)
```

> **INFO**: :title=Help us improve our SDK

We'd love to hear your thoughts on using our iOS SDK. Please take a moment to complete this [short survey](https://forms.gle/YyUh1gGfuWbBwaKF9). Thanks for your time!
