Video SDK for iOS
Initial requirements
The Eagle Eye Networks Video iOS SDK allows you to integrate video streaming into your iOS project. The SDK supports the playback of both video and audio.
Installation
Below are required for working with the Video SDK for iOS.
The integration can be done with CocoaPods:
- Add the following to your podfile:
pod 'EEN-Video-iOS-SDK'
Warning
construction: iOS simulator might fail to properly display the video stream.
In order to use the Video SDK the account should already have the following:
- For any API call you should already be logged in and have an access token available to authenticate the API calls.
- The bridge version should be 3.8.0 or higher as well as current camera support drivers.
Steps to implement 2-Way Audio
Step 1: Get feed/media url
Get the WebRTC URL, device esn and media type using the feeds API.
curl --location --request GET '<baseUrl>/api/v3.0/feeds?deviceId=1002c1f6&type=main&include=flvUrl' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer <access token>'
{
"nextPageToken": "",
"prevPageToken": "",
"results": [
{
"id": "1002c1f6",
"type": "main",
"flvUrl": "https://media.c13.eagleyenetworks.com/10058b7a/main.flv"
}
]
}
Step 2: Initialize the SDK
Initialize the "Player" and add it to a view, set delegate:
let player = Player()
view.addSubview(player)
player.frame = view.frame
player.delegate = self
Step 3: Implement delegate
extension ViewController: PlayerDelegate {
func playerDelegate(_ player: Player, onStatusUpdate status: StreamStatus, for esn: String) {
switch status {
case .initial:
break
case .connecting:
break
case .connected:
break
case .playing:
break
case .buffering:
break
case .paused:
break
case .disconnected(reason: let reason):
break
}
}
func playerDelegate(_ player: Player, onStreamUpdate update: StreamUpdate, for esn: String) {
switch update {
case .timestamp(timestamp: let timestamp):
break
case .duration(duration: let duration):
break
case .progress(progress: let progress):
break
case .size(size: let size):
break
}
}
}
Step 4: Playing
To start playing an item, create a PlayerItem
then call start function:
let accessToken: String = "abcd1234abcd1234"
let deviceId: String = "abcd1234"
let flvUrl = "https://media.c13.eagleyenetworks.com/10058b7a/main.flv"
if let flvURL = URL(string: flvUrl) {
let playerItem = PlayerItem(url: flvUrl,
esn: deviceId,
streamingType: .flv)
player.start(item: playerItem, accessToken: accessToken)
}
Step 5: Disconnect
When finished playing, and the player is not needed anymore, call cleanUp()
.
player.cleanUp()
Methods and Models
Models
To initialize the SDK you need to provide the following PlayerItem
model:
public struct PlayerItem {
public var isLiveItem: Bool
public init(url: URL,
esn: String,
startDate: Date = .init(),
endDate: Date? = nil,
streamingType: StreamingType)
public enum StreamingType: String {
case flv
case rtsp
}
Once a stream is initiated, the player can provide the following self explaining states:
enum StreamStatus: Equatable {
case initial
case connecting
case connected
case playing
case buffering
case paused
case disconnected(reason: StreamEndReason)
}
public enum StreamEndReason: Error, Equatable {
case closed
case streamError(StreamError)
case error(Error)
}
public enum StreamError: Error {
case suppliedObjectIsInvalid(String?)
case notAuthenticated(String?)
case noPermission(String?)
case resourceNotFound(String?)
case internalError(String?)
case unknownError
public var defaultMessage: String
}
Methods
The Player provides the following methods:
public func start(item: PlayerItem, accessToken: String)
This method will start a stream session and play automatically.
public func play()
This method starts playing if it was paused before.
public func pause()
Pauses playing.
public func getStreamStatus()
Get current stream status.
public var audioMuted: Bool
Mute or unmute audio.
public var audioVolume: Float
Get and set playback audio volume.
Delegates
The SDK provides the following delegate methods:
func playerDelegate(_ player: Player, onStatusUpdate status: StreamStatus, for esn: String)
This method allows the developer to keep track of all the status updates.
func playerDelegate(_ player: Player, onStreamUpdate update: StreamUpdate, for esn: String) {
This method allows the developer to keep track of all the stream updates such as timestamp, duration, and progress when available.
Updated about 1 year ago