iOS SDK

The official iOS SDK for api.video

badgebadge   badgebadge   badgebadge

api.video is an API that encodes on the go to facilitate immediate playback, enhancing viewer streaming experiences across multiple devices and platforms. You can stream live or on-demand online videos within minutes.

DEPRECATED: Please use our iOS API client

IOS SDK API.VIDEO

LanguageLanguage

The api.video service helps you put video online without the hassle. This documentation helps you use the corresponding IOS client. This is an early version, feel free to report any issue.

Installation

Cocoapod

  1. Add the following entry to your Podfile:
pod ‘sdkApiVideo’
  1. Then run pod install
  2. Don’t forget to import sdkApiVideo in every file you’d like to use api.video sdk

Quick Start

1. In the AppDelegate.swift instantiate a new Client

let authClient = Client()

2. In the didFinishLaunchingWithOptions func add the following code

  • If you want to use the production environment, use createProduction method
  • If you want to use the sandbox environment , use createSandbox method
authClient.createSandbox(key: « YOUR_SANDBOX_API_KEY »){ (created, reponse) in
}

3. In your ViewController.swift file import the sdk

import sdkApiVideo

4. Create Variable

let appDelegate = UIApplication.shared.delegate as! AppDelegate

5. In viewDidLoad func

self.videoApi = appDelegate.authClient.videoApi

6. Create and upload a video file

self.videoApi.create(title: «title», description: «description», fileName: «filename», filePath: «filePath», url: «url»){ (video, resp) in
    if(resp != nil){
        print("error : \((resp?.statusCode)!) -> \((resp?.message)!)")
    }else{
        //Do whatever you want
    }
}

FULL API

Client

//Create production environnement
let client =  Client()
client.createProduction(key: YOUR_PRODUCTON_API_KEY){ (created, reponse) in
    if(reponse != nil && reponse?.statusCode != "200"){
        // Error
        // Do whatever you want
        // created == false & resp != nil
    }else{
        // Success
        // Do whatever you want
        // created == true uri & resp == nil
    }
}
//Create sandbox environnement
let client =  Client()
client.createSandbox(key: YOUR_SANDBOX_API_KEY){ (created, reponse) in
    if(reponse != nil && reponse?.statusCode != "200"){
        // Error
        // Do whatever you want
        // created == false & resp != nil
    }else{
        // Success
        // Do whatever you want
        // created == true uri & resp == nil
    }
}

Video

//Create video
let videoApi = client.videoApi
            
videoApi.initVideo(title: title, description: description){ (uri, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // uri == "" & resp != nil
    }else{
        // Success
        // Do whatever you want
        // uri == video uri & resp == nil
    }
}
//Upload small video <128Mb
let videoApi = client.videoApi
            
videoApi.uploadSmallVideoFile(videoUri: VIDEO_URI, fileName: FILE_NAME, filePath: FILE_PATH, url: URL){ (video, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // video == nil & resp != nil
    }else{
        // Success
        // Do whatever you want
        // video != nil & resp == nil
    }
}
// DEPRECATED
//Upload big video
let videoApi = client.videoApi
            
videoApi.uploadBigVideoFile(videoUri: VIDEOURI, fileName: FILENAME, filePath: FILEPATH, url: URL){ (uploaded, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // uploaded == false & resp != nil
    }else{
        // Success
        // Do whatever you want
        // uploaded == true & resp == nil
    }
}
//Create and auto upload video
let videoApi = client.videoApi
            
videoApi.create(title: title, description: description, fileName: filename, filePath: filepath, url: url){ (video, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // video == nil & resp != nil
    }else{
        // Success
        // Do whatever you want
        // video != nil & resp == nil
    }
}
//Update video
let videoApi = client.videoApi
            
videoApi.updateVideo(video: Video){ (updated, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // updated == false & resp != nil
    }else{
        // Success
        // Do whatever you want
        // updated == true & resp == nil
    }
}
//Get video with his id 
let videoApi = client.videoApi
            
videoApi.getVideoByID(videoId: VIDEO_ID){ (video, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // video == nil & resp != nil
    }else{
        // Success
        // Do whatever you want
        // video != nil & resp == nil
    }
}
//Get list of video
let videoApi = client.videoApi
            
videoApi.getAllVideos(){(videos, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // videos == nil & resp == nil
    }else{
        // Success
        // Do whatever you want
        // videos != nil & resp == nil
    }
}
//Delete video
let videoApi = client.videoApi
            
videoApi.deleteVideo(videoId: VIDEO_ID){ (deleted, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // isDeleted == false & resp != nil
    }else{
        // Success
        // Do whatever you want
        // isDeleted == true & resp == nil
    }
}
//Get video status
let videoApi = client.videoApi
            
videoApi.getStatus(videoId: VIDEO_ID){(stat, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // isDeleted == false & resp != nil
    }else{
        // Success
        // Do whatever you want
        // isDeleted == true & resp == nil
    }
}
//Pick thumbnail
let videoApi = client.videoApi
            
videoApi.pickThumbnail(videoId: VIDEO_ID, timecode: "00:01:00.00"){(changed, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // changed == false & resp != nil
    }else{
        // Success
        // Do whatever you want
        // changed == true & resp == nil
    }
}
//Upload image as thumbnail
let videoApi = client.videoApi
            
videoApi.uploadImageThumbnail(videoId: VIDEO_ID, url: IMAGE_URL, filePath: FILEPATH, fileName: FILENAME, imageData: DATA){(uploaded, resp) in
    if uploaded{
        // Error
        // Do whatever you want
        // uploaded == false & resp != nil
    }else{
        // Success
        // Do whatever you want
        // uploaded == true & resp == nil
    }
}

Player

//Create player
let playerApi = client.playerApi

playerApi.createPlayer(player: PLAYER){ (created, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // created == false & resp != nil
    }else{
        // Success
        // Do whatever you want
        // created == true & resp == nil
    }
}
//Get player with id 
let playerApi = client.playerApi

playerApi.getPlayerById(playerId: PLAYER_ID){(player, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // created == false & resp != nil
    }else{
        // Success
        // Do whatever you want
        // created == true & resp == nil
    }
}
//Get player with id
let playerApi = client.playerApi

playerApi.getPlayerById(playerId: PLAYER_ID){(player, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // player == nil & resp != nil
    }else{
        // Success
        // Do whatever you want
        // player != nil & resp == nil
    }
}
//Get list of players
let playerApi = client.playerApi

playerApi.getAllPlayers(){(players, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // players == nil & resp != nil
    }else{
        // Success
        // Do whatever you want
        // players != nil & resp == nil
    }
}
//Update player
let playerApi = client.playerApi

playerApi.updatePlayer(player: PLAYER){(updated, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // updated == false & resp != nil
    }else{
        // Success
        // Do whatever you want
        // updated == true & resp == nil
    }
}
//Upload logo
let playerApi = client.playerApi

playerApi.uploadLogo(playerId: PLAYER_ID, url: URL, filePath: FILEPATH, fileName: FILENAME, imageData: DATA){ (uploaded, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // uploaded == false & resp != nil
    }else{
        // Success
        // Do whatever you want
        // uploaded == true & resp == nil
    }
}
//Delete player
let playerApi = client.playerApi

playerApi.deletePlayer(playerId: PLAYER_ID){ (deleted, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // deleted == false & resp != nil
    }else{
        // Success
        // Do whatever you want
        // deleted == true & resp == nil
    }
}

LiveStream

//Create live stream
let liveStreamApi = client.liveStreamApi

liveStreamApi.create(name: NAME, record: RECORD, playerId: PLAYER_ID){(created, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // created == false & resp != nil
    }else{
        // Success
        // Do whatever you want
        // created == true & resp == nil
    }
}
//Get live stream with id
let liveStreamApi = client.liveStreamApi

liveStreamApi.getLiveStreamById(liveStreamId: LIVE_STREAM_ID){(live, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // live == nil & resp != nil
    }else{
        // Success
        // Do whatever you want
        // live != nil & resp == nil
    }
}
//Get list of livestreams
let liveStreamApi = client.liveStreamApi

liveStreamApi.getAllLiveStreams(){(lives, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // lives == nil & resp != nil
    }else{
        // Success
        // Do whatever you want
        // lives != nil & resp == nil
    }
}
//Delete livestream
let liveStreamApi = client.liveStreamApi

liveStreamApi.deleteLiveStream(liveStreamId: LIVE_STREAM_ID){(deleted, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // deleted == false & resp != nil
    }else{
        // Success
        // Do whatever you want
        // deleted == true & resp == nil
    }
}
//Upload thumbnail livestream
let liveStreamApi = client.liveStreamApi

liveStreamApi.uploadImageThumbnail(liveStreamId: LIVE_STREAM_ID, url: URL, filePath: FILEPATH, fileName: FILENAME, imageData: DATA){(uploaded, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // uploaded == false & resp != nil
    }else{
        // Success
        // Do whatever you want
        // uploaded == true & resp == nil
    }
}
//Delete thumbnail livestream
let liveStreamApi = client.liveStreamApi

liveStreamApi.deleteThumbnail(liveStreamId: LIVE_STREAM_ID){ (deleted, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // deleted == false & resp != nil
    }else{
        // Success
        // Do whatever you want
        // deleted == true & resp == nil
    }
}

Caption

//Upload caption
let captionApi = client.captionApi
            
captionApi.upload(videoId: VIDEO_ID, url: URL, filePath: FILEPATH, fileName: FILENAME, language: LANGUAGE){ (uploaded, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // uploaded == false & resp != nil
    }else{
        // Success
        // Do whatever you want
        // uploaded == true & resp == nil
    } 
}
//Get caption with id
let captionApi = client.captionApi
            
captionApi.getCaption(videoId: VIDEO_ID, language: LANGUAGE){ (caption, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // caption == nil & resp != nil
    }else{
        // Success
        // Do whatever you want
        // caption != nil & resp == nil
    } 
}
//Get list of captions
let captionApi = client.captionApi
            
captionApi.getAllCaptions(videoId: VIDEO_ID){ (captions, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // captions == nil & resp != nil
    }else{
        // Success
        // Do whatever you want
        // captions != nil & resp == nil
    } 
}
//Update default caption
let captionApi = client.captionApi
            
captionApi.updateDefaultValue(videoId: VIDEO_ID, language: LANGUAGE, isDefault: BOOL){ (updated, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // updated == false & resp != nil
    }else{
        // Success
        // Do whatever you want
        // updated == true & resp == nil
    } 
}
//Delete caption
let captionApi = client.captionApi
            
captionApi.(videoId: VIDEO_ID, language: LANGUAGE){ (deleted, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // deleted == false & resp != nil
    }else{
        // Success
        // Do whatever you want
        // deleted == true & resp == nil
    } 
}

Chapter

//Upload chapter
let chapterApi = client.chapterApi
            
chapterApi.uploadChapter(videoId: VIDEO_ID, url: URL, filePath: FILEPATH, fileName: FILENAME, language: LANGUAGE){ (uploaded, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // uploaded == false & resp != nil
    }else{
        // Success
        // Do whatever you want
        // uploaded == true & resp == nil
    } 
}
//Get chapter with id
let chapterApi = client.chapterApi
            
chapterApi.getChapter(videoId: VIDEO_ID, language: LANGUAGE){ (chapter, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // chapter == nil & resp != nil
    }else{
        // Success
        // Do whatever you want
        // chapter != nil & resp == nil
    } 
}
//Get list of chapters
let chapterApi = client.chapterApi
            
chapterApi.getAllChapters(videoId: VIDEO_ID){ (chapters, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // chapters == nil & resp != nil
    }else{
        // Success
        // Do whatever you want
        // chapters != nil & resp == nil
    } 
}
//Delete chapter
let chapterApi = client.chapterApi
            
chapterApi.deleteChapter(videoId: VIDEO_ID, language: LANGUAGE){ (deleted, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // deleted == false & resp != nil
    }else{
        // Success
        // Do whatever you want
        // deleted == true & resp == nil
    } 
}

Analytics Video

//Get analytics of video
let analyticsVideoApi = client.analyticsVideoApi
            
analyticsVideoApi.searchVideoAnalyticsById(idVideo: VIDEO_ID, period : PERIOD){ (analytics, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // analytics == nil & resp != nil
    }else{
        // Success
        // Do whatever you want
        // analytics != nil & resp == nil
    } 
}

Analytics Live Stream

//Get analytics of live stream
let analyticsLiveApi = client.analyticsLiveApi
            
analyticsLiveApi.searchLiveAnalyticsById(idLiveStream: LIVE_STREAM_ID, period: PERIOD){ (analytics, resp) in
    if(resp != nil && resp?.statusCode != "200" && resp?.statusCode != "201" && resp?.statusCode != "202"){
        // Error
        // Do whatever you want
        // analytics == nil & resp != nil
    }else{
        // Success
        // Do whatever you want
        // analytics != nil & resp == nil
    } 
}

Plugins

API.Video sdk is using external library

FAQ

If you have any questions, ask us here: https://community.api.video .
Or use Issues.

License

Apache-2.0


Did this page help you?