Skip to main content
Version: iOS 1.0.12

Join Low Latency Stream

This guide shows you how to use our low latency live streaming framework join a broadcasted stream.

Setup#

Make sure you followed the guide to use our live framework in your project.

Import our Live Framework in your ViewController.

import VideoKitLive

Join a Live Stream#

override func viewDidLoad() {
let streamView = UIView(frame: .zero)
view.addSubview(streamView)
streamView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
streamView.topAnchor.constraint(equalTo: view.topAnchor),
streamView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
streamView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
streamView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
])
let streamId = "your-stream-id-from-the-host-goes-here"
let vkLive = VKLiveStream()
DispatchQueue.main.async {
// Join your stream
vkLive.join(streamId: streamId, inView: self.streamView) { (stream, error) in
guard let stream = stream else { return }
// You should be able to see the stream in fullscreen now
print("Stream joined.")
}
}
}

Full Code Example#

LiveJoinViewController.swift
//
// LiveJoinViewController.swift
// TestApp
//
// Created by Dennis Stücken on 11/25/20.
// Copyright © 2020 V. All rights reserved.
//
import Foundation
import UIKit
import VideoKitLive
import VideoKitCore
class LiveJoinViewController: UIViewController {
public var vkLive: VKLiveStream = VKLiveStream()
public var streamId: String?
private var stream: VKStream?
private let streamView: UIView = {
let view = UIView(frame: .zero)
return view
}()
init(streamId id: String) {
self.streamId = id
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
override func viewDidLoad() {
super.viewDidLoad()
guard let streamId = streamId else {
print("Please set id of the stream you want to join.")
return
}
// Preparing live stream
view.addSubview(streamView)
streamView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
streamView.topAnchor.constraint(equalTo: view.topAnchor),
streamView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
streamView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
streamView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
])
DispatchQueue.main.async {
// Join your stream
self.vkLive.join(streamId: streamId, inView: self.streamView) { (stream, error) in
guard let stream = stream else { return }
self.stream = stream
// Todo: remove not implemented message after implementing web rtc
if stream.profile == .ultraLowLatency {
self.view.makeToast("Ultra-Low-Latency (Web-RTC) Player not implemented, yet.")
}
}
}
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}
}

Use the Example#

This is how you can use the example code. Just pass the stream id and the stream is going to show up in full screen.

let joinVC = LiveJoinViewController(streamId: "your-stream-id-to-join-goes-here")
self.navigationController?.pushViewController(joinVC, animated: true)
Last updated on by Nikita Gaer