FastPix Unity SDK

The FastPix Unity SDK enables seamless integration of the FastPix platform into your Unity projects. Designed with Unity developers in mind, it provides a type-safe and intuitive interface for secure and efficient interaction with the FastPix API. With this SDK, you can easily manage media uploads, live streams, on-demand content, playlists, video analytics, and signing keys for secure access and token management—all directly from your Unity environment.




Let’s talk features:

Media API

  • Upload Media: Easily upload media files from local devices or external URLs.
  • Manage Media: List, retrieve, update, and delete media assets with minimal effort.
  • Playback IDs: Create and manage playback IDs for flexible, secure access to your content.
  • Advanced Media Tools: Generate video summaries, chapters, named entities, subtitles, and run content moderation.
  • Playlist Management: Build and manage playlists, add or remove media, and control playback order.
  • DRM Support: Configure and manage Digital Rights Management for secure content protection.

Live API

  • Create & Manage Live Streams: Quickly create, update, list, and delete live streams.
  • Access Control: Use playback IDs to securely manage viewer access.
  • Stream Controls: Enable, disable, or end streams with precise control.
  • Simulcast Support: Stream to multiple platforms simultaneously for wider reach.

Signing Keys

  • Generate Signing Keys: Create keys to enable secure, token-based access.
  • Retrieve & Manage Keys: List, fetch details, and manage individual signing keys.
  • Access Control Maintenance: Delete or revoke keys to maintain security and control.

Video Data API

  • View & Analytics: Track video views, retrieve detailed view data, and identify top-performing content.
  • Concurrent Viewers: Access time-series insights for both live and on-demand streams.
  • Custom Reporting: Filter by dimensions, generate breakdowns, and compare datasets for deeper insights.
  • Error Diagnostics: Retrieve logs and monitor errors to ensure reliability and performance.

For complete usage instructions, see the FastPix API Reference.


Prerequisites

Before you start using the FastPix Node.js SDK, make sure you have the following:

  1. To authenticate with the FastPix APIs, you'll need an Access Token and a Secret Key. You can generate these credentials by following the steps in the Authentication with Access Tokens guide.

Installation:

The FastPix Unity SDK can be integrated into your project in two ways:

  1. Using a compiled DLL: Compile the SDK using dotnet build, then copy the resultant .dll file into your Unity project's Assets folder.
  2. Using source code: Copy the SDK source code directly into your Unity project.

Dependencies:

The SDK relies on Newtonsoft's JSON.NET package for JSON serialization and deserialization. To install it via the Unity Package Manager:

  1. Open the Package Manager via Window > Package Manager.
  2. Click the + button and select Add package from git URL...
  3. Enter the following URL: com.unity.nuget.newtonsoft-json
  4. Click Add to install the package.

Once installed, your Unity project is ready to use the FastPix Unity SDK.


Import and Initialize the SDK

using fastpix.io;
using fastpix.io.Models.Components;
using System.Collections.Generic;
using System.Threading.Tasks;

// Initialize FastPix Unity SDK with AccessToken and SecretKey
var sdk = new Fastpix(
    security: new Security
    {
        Username = "your-access-token",
        Password = "secret-key"
    }
);

Example Usage:

using fastpix.io;
using fastpix.io.Models.Components;
using System.Collections.Generic;

// Initialize FastPix Unity SDK with AccessToken and SecretKey
var sdk = new Fastpix(
    security: new Security
    {
        Username = "your-access-token",
        Password = "secret-key"
    }
);

var req = new CreateMediaRequest
{
    Inputs = new List<Input>
    {
        Input.CreateVideoInput(
            new VideoInput
            {
                Type = "video",
                Url = "https://static.fastpix.io/sample.mp4"
            }
        )
    },
    Metadata = new Dictionary<string, string>
    {
        { "key1", "value1" }
    },
    AccessPolicy = CreateMediaRequestAccessPolicy.Public,
    MaxResolution = CreateMediaRequestMaxResolution.OneThousandAndEightyp
};

using (var res = await sdk.InputVideo.CreateMediaAsync(req))
{
    // Handle response here
}

Available Resources and Operations

The FastPix SDK provides resources and methods to manage media workflows, live streaming, analytics, DRM, and secure access.

Below, resources are categorized by their primary use for easier navigation.


1.Video On-Demand

Resources for uploading, managing, and enhancing on-demand videos.


Input Video

Upload and create media assets from URLs or local files.

MethodDescriptionHTTP request
CreateMediaCreate media from a remote URLPOST /on-demand
DirectUploadVideoMediaUpload video directly from your devicePOST /on-demand/upload

In-Video AI Features

Enhance videos with AI-powered analysis.

MethodDescriptionHTTP request
UpdateMediaSummaryGenerate video summaryPATCH /on-demand/{mediaId}/summary
UpdateMediaChaptersGenerate video chaptersPATCH /on-demand/{mediaId}/chapters
UpdateMediaNamedEntitiesGenerate named entitiesPATCH /on-demand/{mediaId}/named-entities
UpdateMediaModerationEnable video moderationPATCH /on-demand/{mediaId}/moderation

Manage Videos

Full lifecycle management of uploaded media.

Media Management APIs

MethodDescriptionHTTP request
ListMediaGet list of all mediaGET /on-demand
ListLiveClipsGet all clips of a live streamGET /on-demand/{livestreamId}/live-clips
GetMediaGet a media by IDGET /on-demand/{mediaId}
UpdatedMediaUpdate a media by IDPATCH /on-demand/{mediaId}
DeleteMediaDelete a media by IDDELETE /on-demand/{mediaId}
AddMediaTrackAdd audio / subtitle trackPOST /on-demand/{mediaId}/tracks
CancelUploadCancel ongoing uploadPOST /on-demand/{mediaId}/cancel
UpdateMediaTrackUpdate audio / subtitle trackPATCH /on-demand/{mediaId}/tracks/{trackId}
DeleteMediaTrackDelete audio / subtitle trackDELETE /on-demand/{mediaId}/tracks/{trackId}
GenerateSubtitleTrackGenerate track subtitlePOST /on-demand/{mediaId}/tracks/generate-subtitle
UpdatedSourceAccessUpdate the source access of a mediaPATCH /on-demand/{mediaId}/source-access
UpdatedMp4SupportUpdate the mp4Support of a mediaPATCH /on-demand/{mediaId}/update-mp4Support
RetrieveMediaInputInfoGet info of media inputsGET /on-demand/{mediaId}/input-info
ListUploadsGet all unused upload URLsGET /on-demand/uploads
GetMediaClipsGet all clips of a mediaGET /on-demand/{mediaId}/media-clips

Playback

Manage secure playback access.

MethodDescriptionHTTP request
CreateMediaPlaybackIdCreate a playback IDPOST /on-demand/{mediaId}/playback-ids
DeleteMediaPlaybackIdDelete a playback IDDELETE /on-demand/{mediaId}/playback-ids/{playbackId}
GetPlaybackIdGet a playback IDGET /on-demand/{mediaId}/playback-ids/{playbackId}

playlist

Organize videos into playlists.

MethodDescriptionHTTP request
CreateAPlaylistCreate a new playlistPOST /on-demand/playlists
GetAllPlaylistsGet all playlistsGET /on-demand/playlists
GetPlaylistByIdGet a playlist by IDGET /on-demand/playlists/{playlistId}
UpdateAPlaylistUpdate a playlist by IDPATCH /on-demand/playlists/{playlistId}
DeleteAPlaylistDelete a playlist by IDDELETE /on-demand/playlists/{playlistId}
AddMediaToPlaylistAdd media to a playlist by IDPOST /on-demand/playlists/{playlistId}/media
ChangeMediaOrderInPlaylistChange media order in a playlist by IDPATCH /on-demand/playlists/{playlistId}/media
DeleteMediaFromPlaylistDelete media in a playlist by IDDELETE /on-demand/playlists/{playlistId}/media

DRM Configurations

Manage DRM for protected content.

MethodDescriptionHTTP request
GetDrmConfigurationGet list of DRM configuration IDsGET /on-demand/drm-configurations
GetDrmConfigurationByIdGet DRM configuration by IDGET /on-demand/drm-configurations/{drmId}

2.Live Stream

Resources for live streaming, simulcasting, and playback.


Start Live Stream

MethodDescriptionHTTP Request
CreateNewStreamCreate a new streamPOST /live/streams

Simulcast Stream

MethodDescriptionHTTP Request
CreateSimulcastOfStreamCreate a simulcastPOST /live/streams/{streamId}/simulcast
DeleteSimulcastOfStreamDelete a simulcastDELETE /live/streams/{streamId}/simulcast/{simulcastId}
GetSpecificSimulcastOfStreamGet a specific simulcastGET /live/streams/{streamId}/simulcast/{simulcastId}
UpdateSpecificSimulcastOfStreamUpdate a simulcastPATCH /live/streams/{streamId}/simulcast/{simulcastId}

Manage Live Stream

MethodDescriptionHTTP Request
GetAllStreamsGet all live streamsGET /live/streams
GetLiveStreamViewerCountByIdGet stream views by IDGET /live/streams/{streamId}/viewer-count
GetLiveStreamByIdGet stream by IDGET /live/streams/{streamId}
DeleteLiveStreamDelete a streamDELETE /live/streams/{streamId}
UpdateLiveStreamUpdate a streamPATCH /live/streams/{streamId}
DisableLiveStreamDisable a streamPUT /live/streams/{streamId}/live-disable
CompleteLiveStreamComplete a streamPUT /live/streams/{streamId}/finish

Live Playback

MethodDescriptionHTTP Request
CreatePlaybackIdOfStreamCreate a playbackIdPOST /live/streams/{streamId}/playback-ids
DeletePlaybackIdOfStreamDelete a playbackIdDELETE /live/streams/{streamId}/playback-ids/{playbackId}
GetLiveStreamPlaybackIdGet playbackId detailsGET /live/streams/{streamId}/playback-ids/{playbackId}

3. Systems

Signing Keys

Securely manage token-based access.

MethodDescriptionHTTP Request
CreateSigningKeyCreate a signing keyPOST /iam/signing-keys
ListSigningKeysGet list of signing keysGET /iam/signing-keys
DeleteSigningKeyDelete a signing keyDELETE /iam/signing-keys/{signingKeyId}
GetSigningKeyByIdGet signing key by IDGET /iam/signing-keys/{signingKeyId}

4.Video Data

Resources for analytics, insights, and system monitoring.


Views

Viewer analytics for on-demand and live content.

MethodDescriptionHTTP Request
ListVideoViewsList video viewsGET /data/viewlist
GetVideoViewDetailsGet details of a video viewGET /data/viewlist/{viewId}
ListByTopContentList by top contentGET /data/viewlist/top-content
GetDataViewlistCurrentViewsGetTimeseriesViewsGet concurrent viewers timeseriesGET /data/viewlist/current-views/getTimeseriesViews
GetDataViewlistCurrentViewsFilterGet concurrent viewers breakdown by dimensionGET /data/viewlist/current-views/filter

Dimensions

Categorize and filter video data for analytics.

MethodDescriptionHTTP Request
ListDimensionsList the dimensionsGET /data/dimensions
ListFilterValuesForDimensionList the filter values for a dimensionGET /data/dimensions/{dimensionId}

Errors

Monitor and troubleshoot system errors.

MethodDescriptionHTTP Request
ListErrorsList errorsGET /data/errors

Metrics

Access analytics and performance metrics.

MethodDescriptionHTTP Request
ListBreakdownValuesList breakdown valuesGET /data/metrics/{metricId}/breakdown
ListOverallValuesList overall valuesGET /data/metrics/{metricId}/overall
GetTimeseriesDataGet timeseries dataGET /data/metrics/{metricId}/timeseries
ListComparisonValuesList comparison valuesGET /data/metrics/comparison


Error Handling

Handling errors in the FastPix Unity SDK follows standard .NET/Unity conventions. Most operations return a response object or throw an exception if the request fails.

By default, an API error will raise a fastpix.io.Models.Errors.APIException exception with the following properties:

PropertyTypeDescription
MessagestringThe error message
StatusCodeintThe raw HTTP response status code
RawResponseHttpResponseMessageThe full raw HTTP response
BodystringThe response content

When custom error responses are specified for an operation, the SDK may throw their associated exception. For example, the CreateMediaAsync method can throw the following exceptions:

Error TypeStatus CodeContent Type
BadRequestException400application/json
InvalidPermissionException401application/json
ForbiddenException403application/json
ValidationErrorResponse422application/json
APIException4XX, 5XX/

Example:

using fastpix.io;
using fastpix.io.Models.Components;
using fastpix.io.Models.Errors;
using System;
using System.Collections.Generic;

// Initialize FastPix Unity SDK with AccessToken and SecretKey
var sdk = new Fastpix(
    security: new Security
    {
        Username = "your-access-token",
        Password = "secret-key"
    }
);

var req = new CreateMediaRequest
{
    Inputs = new List<Input>
    {
        Input.CreateVideoInput(
            new VideoInput
            {
                Type = "video",
                Url = "https://static.fastpix.io/sample.mp4"
            }
        )
    },
    Metadata = new Dictionary<string, string>
    {
        { "key1", "value1" }
    },
    AccessPolicy = CreateMediaRequestAccessPolicy.Public,
    MaxResolution = CreateMediaRequestMaxResolution.OneThousandAndEightyp
};

try
{
    using (var res = await sdk.InputVideo.CreateMediaAsync(req))
    {
        // Handle response
    }
}
catch (Exception ex)
{
    if (ex is BadRequestException)
    {
        // Handle BadRequest
    }
    else if (ex is InvalidPermissionException)
    {
        // Handle InvalidPermission
    }
    else if (ex is ForbiddenException)
    {
        // Handle Forbidden
    }
    else if (ex is ValidationErrorResponse)
    {
        // Handle ValidationError
    }
    else if (ex is APIException)
    {
        // Handle APIException
    }
}

Server Selection

Override Server URL Per-Client

using fastpix.io;
using fastpix.io.Models.Components;
using System.Collections.Generic;

// Initialize FastPix SDK with custom server URL and security
var sdk = new Fastpix(
    serverUrl: "https://api.fastpix.io/v1/",
    security: new Security
    {
        Username = "your-access-token",
        Password = "secret-key"
    }
);

var req = new CreateMediaRequest
{
    Inputs = new List<Input>
    {
        Input.CreateVideoInput(
            new VideoInput
            {
                Type = "video",
                Url = "https://static.fastpix.io/sample.mp4"
            }
        )
    },
    Metadata = new Dictionary<string, string>
    {
        { "key1", "value1" }
    },
    AccessPolicy = CreateMediaRequestAccessPolicy.Public,
    MaxResolution = CreateMediaRequestMaxResolution.OneThousandAndEightyp
};

using (var res = await sdk.InputVideo.CreateMediaAsync(req))
{
    // Handle response
}