Skip to content

apivideo/api.video-swift-player-analytics

Repository files navigation

badge   badge   badge

api.video Swift player analytics

api.video is the video infrastructure for product builders. Lightning fast video APIs for integrating, scaling, and managing on-demand & low latency live streaming features in your app.

Table of contents

Project description

This library send player events from the player to api.video.

Getting started

Installation

Swift Package Manager

Add the following dependency to your Package.swift file:

  dependencies: [
        .package(url: "https://github.com/apivideo/api.video-swift-player-analytics.git", from: "2.0.0"),
    ],

CocoaPods

Add the following line to your Podfile:

pod 'ApiVideoPlayerAnalytics', '~> 2.0.0

Then, run pod install.

Code sample

Create a ApiVideoAnalyticsAVPlayer instance.

import ApiVideoPlayerAnalytics

let player = ApiVideoAnalyticsAVPlayer(url: "URL of the HLS manifest") // HLS manifest from api.video. Example: https://vod.api.video/vod/YOUR_VIDEO_ID/hls/manifest.m3u8

Then, use it like a regular AVPlayer.

player.play()

For a custom domain collector, use:

let player = ApiVideoAnalyticsAVPlayer(url: "URL of the HLS manifest", collectorUrl: "https://collector.mycustomdomain.com") // Register the player analytics listener so it sends player events to api.video.

Sample application

Open ApiVideoPlayerAnalytics.xcodeproj.

Replace the default media ID in Examples/iOS/ViewController.swift with your own.

let url = Utils.inferManifestURL(mediaId: "vi77Dgk0F8eLwaFOtC5870yn") // replace `vi77Dgk0F8eLwaFOtC5870yn` with your own media ID

Then, run the Example iOS target.

Documentation

FAQ

If you have any questions, ask us in the community or use issues.