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:
- Open your Xcode project.
- Select your project in the Project Navigator.
- Select the target you want to add the package to.
- Go to the "Package Dependencies" tab.
- Click the "+" button to add a new package.
- 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. - 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>"
To create a new QUANTEEC configuration and/or retrieve your default QUANTEEC key, you must first go to the Config page of your panel.
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).
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:
- SwiftUI
- UIKit
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()
}
}
import UIKit
import AVFoundation
import QuanteecCore
import QuanteecPluginAVPlayer
class ViewController: UIViewController {
@IBOutlet weak var videoView: UIView!
// AVPlayer instance
let player = AVPlayer();
// Quanteec plugin
var quanteecPlugin: QuanteecPlugin?
let urlString = "stream url here"
override func viewDidAppear(_ animated: Bool) {
// configure quanteec plugin
QuanteecConfig.configure(quanteecKey: "key here")
QuanteecConfig.shared.videoID = "video id here"
// init QuanteecPlugin plugin and pass player
quanteecPlugin = QuanteecPlugin(player: player)
// enable logs if needed for debug
QLoggerConfig.shared.showAnalytics = true
QLoggerConfig.shared.activeLogLevel = .trace
self.loadVideo()
}
func loadVideo() {
let videoURL = URL(string: urlString)!
// Create an AVPlayerItem
let playerItem = AVPlayerItem(url: videoURL)
// add new item to player
player.replaceCurrentItem(with: playerItem)
// Create an AVPlayerLayer
let playerLayer = AVPlayerLayer(player: player)
// Set the frame for the player layer
playerLayer.frame = videoView.bounds
// Add the player layer to your existing view's layer
videoView.layer.addSublayer(playerLayer)
// Start video playback
player.play()
}
}