Skip to main content

AVPlayer

AVPlayer is the native video player for iOS/iPadOS/tvOS, created and maintained by Apple.

Compatibility with AVPlayer and QUANTEEC plugin

The QUANTEEC plugin has been tested with AVPlayer from iOS/iPadOS/tvOS version 15.6 to iOS version 18.

Add QUANTEEC plugin as a package (using Swift Package Manager)

The QUANTEEC plugin is available as a package that can be added to your project using the Swift Package Manager. To add the QUANTEEC plugin to your project, follow these steps:

  1. Open your Xcode project.
  2. Select your project in the Project Navigator.
  3. Select the target you want to add the package to.
  4. Go to the "Package Dependencies" tab.
  5. Click the "+" button to add a new package.
  6. Enter the URL of the QUANTEEC plugin repository: https://github.com/quanteec/quanteec_ios_package. You need to have linked your github account to your Xcode account.
  7. The packages "quanteec_plugin_package" and the dependency "GDCWebServer" should appear on the left panel under "package dependencies".

Install QUANTEEC in your application for AVPlayer

3 steps:

1- Import the QUANTEEC plugin:

import QuanteecCore
import QuanteecPluginAVPlayer

2- Create a QuanteecPlugin plugin configuration (QuanteecConfig). The constructor of the QuanteecPlugin required the quanteecKey as a parameter:

QuanteecConfig.configure(quanteecKey: "<your-quanteec-key>")
QuanteecConfig.shared.videoID = "<your-custom-videoID>"
info

To create a new QUANTEEC configuration and/or retrieve your default QUANTEEC key, you must first go to the Config page of your panel.

warning

In your QUANTEEC configuration, remember to set a different videoID if you have different formats of the same stream (e.g., one DASH stream and one HLS stream) or two variants of the same stream (one stream with English audio and one stream with another language).

Click here to find more informations on videoID

3- Create a QuanteecPluginAVPlayer instance. The constructor of the QuanteecPlugin required the quanteecConfig and the AVPlayer instance as parameters:

let quanteecPlugin = QuanteecPlugin(player: player)

Here is a complete example of how to use the QUANTEEC plugin with AVPlayer inside a basic Swift View component:

import SwiftUI
import AVKit
import QuanteecCore
import QuanteecPluginAVPlayer

struct ContentView: View {
let player = AVPlayer()
let urlString: String = "https://example.com/your-video-url.m3u8"

@State private var quanteecPlugin: QuanteecPlugin?

var body: some View {
VStack {
VideoPlayer(player: player)
.frame(height: 300)
.onAppear {
setupPlayer()
}
.onDisappear {
player.pause()
}
}
.padding()
}

func setupPlayer() {
// Configure Quanteec first
QuanteecConfig.configure(quanteecKey: "your quanteec key")
QuanteecConfig.shared.videoID = "your video id"

quanteecPlugin = QuanteecPlugin(player: player)

// true if analytics is need as overlay
QLoggerConfig.shared.showAnalytics = true
QLoggerConfig.shared.activeLogLevel = .trace

// Only AFTER plugin is created, attach the item
guard let videoURL = URL(string: urlString) else { return }

let playerItem = AVPlayerItem(url: videoURL)
player.replaceCurrentItem(with: playerItem)

player.play()
}
}