C# SDK
The FastPix C# SDK (C Sharp) provides a powerful, developer-friendly way to integrate video capabilities into your .NET applications. With support for media upload, live streaming, simulcasting, and playback management, you can build sophisticated video-based applications with ease.
Features
Integration prerequisite
Step 1: Installation
Step 2: Importing the SDK
Step 3: Initialization
Perform media operations
Live stream operations
Error handling
Support & resource
Features
The FastPix C# SDK provides the following key features:
Media APIs
- Upload Media: Easily upload media files from URLs or devices to the FastPix platform
- Manage Media: Perform various media operations such as listing, fetching, updating, and deleting media assets
- Playback IDs: Create and manage playback IDs to access your media
Live Streaming APIs
- Create & Manage Live Streams: Stream live events by creating, listing, updating, and deleting live streams
- Control Stream Access: Generate playback IDs to control who can access your live streams
- Simulcast: Stream content to multiple platforms simultaneously with ease
Key Benefits
- Type Safety: Full type hints and strict typing for better development experience
- Developer-Friendly: Intuitive API design with comprehensive error handling
- Production Ready: Built for high-performance applications with retry mechanisms
- Comprehensive Coverage: Complete access to all FastPix platform features
For detailed usage, refer to the FastPix API Reference.
Integration Prerequisite
Before you start using the FastPix C# SDK, make sure you have the following:
- .NET 8.0 or later: This SDK is compatible with .NET 8.0 or higher
- Visual Studio 2022 or Visual Studio Code with C# extensions
- NuGet Package Manager: Required for dependency management
- FastPix API credentials: You’ll need an Access Token and a Secret Key. You can generate these credentials by following the steps in the Authentication guide
- Basic understanding of C# and REST APIs: Familiarity with C# development and API integration concepts
Step 1: Installation
The SDK is available through NuGet package manager.
Using NuGet Package Manager
- Open Package Manager Console in Visual Studio:
Install-Package Fastpix
- Or use the Package Manager UI:
- Right-click on your project in Solution Explorer
- Select “Manage NuGet Packages”
- Search for “Fastpix”
- Click “Install”
Using .NET CLI
dotnet add package Fastpix
Using PackageReference
Add this to your .csproj file:
<PackageReference Include="Fastpix" Version="0.1.2" />
Step 2: Importing the SDK
Add the necessary using statements to your C# files:
using Fastpix;
using Fastpix.Models.Components;
using Fastpix.Models.Requests;
using System.Threading.Tasks;
Step 3: Initialization
You can set the security parameters through the constructor when initializing the SDK client instance. The SDK uses different server URLs for different operations:
For Media Operations
Use the base FastPix server URL:
var security = new Security
{
Username = "your-access-token-id",
Password = "your-secret-key"
};
var fastPix = new FastPix(security, serverUrl: "https://api.fastpix.io/v1/on-demand");
For Live Stream Operations
Use the live streaming specific server URL:
var security = new Security
{
Username = "your-access-token-id",
Password = "your-secret-key"
};
var fastPix = new FastPix(security, serverUrl: "https://api.fastpix.io/v1/live");
Environment Variables (Recommended)
For production applications, use environment variables for security:
var security = new Security
{
Username = Environment.GetEnvironmentVariable("FASTPIX_ACCESS_TOKEN"),
Password = Environment.GetEnvironmentVariable("FASTPIX_SECRET_KEY")
};
var fastPix = new FastPix(security, serverUrl: "https://api.fastpix.io/v1"); // or 'https://api.fastpix.io/v1/live' for live streams
Perform Media Operations
1.1 Create Media from URL
This endpoint allows developers or users to create a new video or audio media in FastPix using a publicly accessible URL. FastPix will fetch the media from the provided URL, process it, and store it on the platform for use.
Use the CreateMediaAsync()
method to create media from a URL. This is useful when you want to import videos from external sources.
For more details refer to Create Media From URL API documentation.
// Initialize SDK for media operations
var security = new Security
{
Username = "your-access-token-id",
Password = "your-secret-key"
};
var fastPix = new FastPix(security, serverUrl: "https://api.fastpix.io/v1");
// Create media from URL
var request = new CreateMediaRequest
{
Inputs = new List<Models.Components.Input>
{
Models.Components.Input.CreateVideoInput(
new VideoInput
{
Type = "video",
Url = "https://example.com/video.mp4",
StartTime = 0D,
EndTime = 60D
}
)
},
Metadata = new CreateMediaRequestMetadata
{
Title = "My Video Title",
Description = "Video description here"
},
AccessPolicy = CreateMediaRequestAccessPolicy.Public,
Mp4Support = CreateMediaRequestMp4Support.Capped4k
};
var response = await fastPix.InputVideo.CreateMediaAsync(request);
if (response.Object != null)
{
Console.WriteLine("Media created successfully!");
Console.WriteLine($"Media ID: {response.Object.Id}");
Console.WriteLine($"Status: {response.Object.Status}");
}
1.2 Upload Media from Device
This endpoint enables you to upload a video file directly from your local device to FastPix for processing and storage. When you invoke this API with your preferred media settings, the response returns an uploadId and a pre-signed URL, providing a streamlined experience for uploading.
Use the DirectUploadVideoMediaAsync()
method to upload media directly from a device or file system.
For more details refer to Upload Media From Device API documentation.
// Upload media directly from device
var request = new DirectUploadVideoMediaRequest
{
CorsOrigin = "*",
PushMediaSettings = new PushMediaSettings
{
AccessPolicy = DirectUploadVideoMediaAccessPolicy.Public,
StartTime = 0D,
EndTime = 60D
}
};
var response = await fastPix.InputVideo.DirectUploadVideoMediaAsync(request);
if (response.Object != null)
{
Console.WriteLine("Media uploaded successfully!");
Console.WriteLine($"Upload ID: {response.Object.UploadId}");
Console.WriteLine($"Upload URL: {response.Object.UploadUrl}");
}
1.3 List All Media
This endpoint returns a list of all media files created from a URL or uploaded as file objects within your organization. Each media entry contains metadata such as the media ID, creation date, status, and type. It allows you to retrieve a comprehensive overview of your media assets, making it easier to manage and review them.
Use the ListMediaAsync()
method to retrieve a list of all media files in your account.
For more details refer to List All Media API documentation.
var response = await fastPix.ManageVideos.ListMediaAsync(
limit: 20,
offset: 1,
orderBy: ListMediaOrderBy.Desc
);
if (response.ListMediaResponse?.Data != null)
{
foreach (var media in response.ListMediaResponse.Data)
{
Console.WriteLine($"Media ID: {media.Id}");
Console.WriteLine($"Title: {media.Title}");
Console.WriteLine($"Status: {media.Status}");
Console.WriteLine($"Duration: {media.Duration}");
}
}
1.4 Get Media by ID
By calling this endpoint, you can retrieve detailed information about a specific media item, including its current status and a playbackId. This is particularly useful for retrieving specific media details when managing large content libraries.
Use the GetMediaAsync()
method to retrieve details of a specific media file using its media ID.
For more details refer to Get Media by ID API documentation.
string mediaId = "your-media-id";
var response = await fastPix.ManageVideos.GetMediaAsync(mediaId);
if (response.GetMediaResponse?.Data != null)
{
var media = response.GetMediaResponse.Data;
Console.WriteLine($"Title: {media.Title}");
Console.WriteLine($"Duration: {media.Duration}");
Console.WriteLine($"Status: {media.Status}");
Console.WriteLine($"Created At: {media.CreatedAt}");
}
1.5 Update Media
This endpoint allows you to update specific parameters of an existing media file. You can modify the key-value pairs of the metadata that were provided in the payload during the creation of media from a URL or when uploading the media as a file object.
Use the UpdatedMediaAsync()
method to update metadata or settings for a specific media file.
For more details refer to Update Media API documentation.
string mediaId = "your-media-id";
var request = new UpdatedMediaRequestBody
{
Metadata = new Dictionary<string, object>
{
["title"] = "Updated Title",
["description"] = "Updated description"
}
};
var response = await fastPix.ManageVideos.UpdatedMediaAsync(mediaId, request);
if (response.UpdatedMediaResponse?.Data != null)
{
Console.WriteLine("Media updated successfully!");
}
1.6 Delete Media
This endpoint allows you to permanently delete a specific video or audio media file along with all associated data. If you wish to remove a media file from FastPix storage, use this endpoint with the mediaId (either uploadId or id) received during the media’s creation or upload.
Use the DeleteMediaAsync()
method to remove a media file from your account.
For more details refer to Delete Media API documentation.
string mediaId = "your-media-id";
await fastPix.ManageVideos.DeleteMediaAsync(mediaId);
Console.WriteLine("Media deleted successfully!");
1.7 Create Media Playback ID
You can create a new playback ID for a specific media asset. If you have already retrieved an existing playbackId using the “Get Media by ID” endpoint for a media asset, you can use this endpoint to generate a new playback ID with a specified access policy.
Use the CreateMediaPlaybackIdAsync()
method to generate a playback ID for a media file.
For more details refer to Create Media Playback ID API documentation.
string mediaId = "your-media-id";
var request = new CreateMediaPlaybackIdRequestBody
{
AccessPolicy = CreateMediaPlaybackIdAccessPolicy.Public
};
var response = await fastPix.Playback.CreateMediaPlaybackIdAsync(mediaId, request);
if (response.CreateMediaPlaybackIdResponse?.Data != null)
{
Console.WriteLine($"Playback ID: {response.CreateMediaPlaybackIdResponse.Data.Id}");
Console.WriteLine($"Playback URL: https://stream.fastpix.io/{response.CreateMediaPlaybackIdResponse.Data.Id}.m3u8");
}
1.8 Delete Media Playback ID
This endpoint allows you to remove a specific playback ID associated with a media asset. Deleting a playbackId will revoke access to the media content linked to that ID.
Use the DeleteMediaPlaybackIdAsync()
method to remove a playback ID for a media file.
For more details refer to Delete Media Playback ID API documentation.
string mediaId = "your-media-id";
string playbackId = "your-playback-id";
await fastPix.Playback.DeleteMediaPlaybackIdAsync(mediaId, playbackId);
Console.WriteLine("Playback ID deleted successfully!");
Live Stream Operations
2.1 Create Live Stream
This endpoint allows you to create a new live stream with specified settings. You can configure various parameters such as the stream key, recording settings, and playback options to customize the live streaming experience according to your requirements.
Use the CreateNewStreamAsync()
method to create a new live stream with your desired configuration.
For more details refer to Create Live Stream API documentation.
// Initialize SDK for live stream operations
var security = new Security
{
Username = "your-access-token-id",
Password = "your-secret-key"
};
var fastPix = new FastPix(security, serverUrl: "https://api.fastpix.io/v1/live");
// Create a new live stream
var request = new CreateLiveStreamRequest
{
Metadata = new CreateLiveStreamRequestMetadata
{
Title = "My Live Stream",
Description = "This is my live stream description"
},
ReconnectWindow = 60, // 60 seconds
AccessPolicy = CreateLiveStreamRequestAccessPolicy.Public,
Dvr = true // Enable DVR mode
};
var response = await fastPix.StartLiveStream.CreateNewStreamAsync(request);
if (response.LiveStreamResponseDTO?.Data != null)
{
Console.WriteLine("Live stream created successfully!");
Console.WriteLine($"Stream ID: {response.LiveStreamResponseDTO.Data.StreamId}");
Console.WriteLine($"Stream Key: {response.LiveStreamResponseDTO.Data.StreamKey}");
Console.WriteLine($"RTMP URL: {response.LiveStreamResponseDTO.Data.RtmpUrl}");
}
2.2 List All Live Streams
This endpoint returns a comprehensive list of all live streams within your organization. It provides detailed information about each stream, including their current status, creation date, and configuration settings, making it easy to manage and monitor your live streaming activities.
Use the GetAllStreamsAsync()
method to retrieve a list of all live streams in your account.
For more details refer to List All Live Streams API documentation.
var response = await fastPix.ManageLiveStream.GetAllStreamsAsync(
limit: "20",
offset: "1",
orderBy: GetAllStreamsOrderBy.Desc
);
if (response.GetStreamsResponse?.Data != null)
{
foreach (var stream in response.GetStreamsResponse.Data)
{
Console.WriteLine($"Stream ID: {stream.StreamId}");
Console.WriteLine($"Title: {stream.Title}");
Console.WriteLine($"Status: {stream.Status}");
Console.WriteLine($"Created At: {stream.CreatedAt}");
}
}
2.3 Get Live Stream by ID
This endpoint allows you to retrieve detailed information about a specific live stream using its unique identifier. It returns comprehensive data including the stream’s current status, configuration settings, and associated metadata, providing you with complete visibility into the stream’s properties and state.
Use the GetLiveStreamByIdAsync()
method to retrieve details of a specific live stream using its stream ID.
For more details refer to Get Live Stream by ID API documentation.
string streamId = "your-stream-id";
var response = await fastPix.ManageLiveStream.GetLiveStreamByIdAsync(streamId);
if (response.LivestreamgetResponse?.Data != null)
{
var stream = response.LivestreamgetResponse.Data;
Console.WriteLine($"Title: {stream.Title}");
Console.WriteLine($"Status: {stream.Status}");
Console.WriteLine($"Stream Key: {stream.StreamKey}");
Console.WriteLine($"RTMP URL: {stream.RtmpUrl}");
}
2.4 Update Live Stream
This endpoint enables you to modify the configuration and settings of an existing live stream. You can update various parameters such as the stream name, recording preferences, and other configuration options to adapt the stream to changing requirements or preferences.
Use the UpdateLiveStreamAsync()
method to update settings for a specific live stream.
For more details refer to Update Live Stream API documentation.
string streamId = "your-stream-id";
var request = new PatchLiveStreamRequest
{
Metadata = new PatchLiveStreamRequestMetadata
{
Title = "Updated Stream Name",
Description = "Updated stream description"
}
};
var response = await fastPix.ManageLiveStream.UpdateLiveStreamAsync(streamId, request);
if (response.UpdateLiveStreamResponse?.Data != null)
{
Console.WriteLine("Live stream updated successfully!");
}
2.5 Delete Live Stream
This endpoint allows you to permanently remove a specific live stream and all its associated data from the FastPix platform. When you delete a live stream, it will be completely removed from your account, including any recordings or metadata associated with it.
Use the DeleteLiveStreamAsync()
method to remove a live stream from your account.
For more details refer to Delete Live Stream API documentation.
Use the DeleteLiveStreamAsync() method to remove a live stream from your account.
For more details refer to Delete Live Stream API documentation.
string streamId = "your-stream-id";
await fastPix.ManageLiveStream.DeleteLiveStreamAsync(streamId);
Console.WriteLine("Live stream deleted successfully!");
2.6 Create Live Stream Playback ID
This endpoint enables you to generate a new playback ID for a specific live stream. The playback ID provides a secure and controlled way to access the live stream content, allowing you to implement custom access policies and restrictions for your live streaming content.
Use the CreatePlaybackIdOfStreamAsync()
method to generate a playback ID for a live stream.
For more details refer to Create Live Stream Playback ID API documentation.
string streamId = "your-stream-id";
var request = new PlaybackIdRequest
{
AccessPolicy = PlaybackIdRequestAccessPolicy.Public
};
var response = await fastPix.Playback.CreatePlaybackIdOfStreamAsync(streamId, request);
if (response.PlaybackIdResponse?.Data != null)
{
Console.WriteLine($"Playback ID: {response.PlaybackIdResponse.Data.Id}");
Console.WriteLine($"Playback URL: https://stream.fastpix.io/{response.PlaybackIdResponse.Data.Id}.m3u8");
}
2.7 Delete Live Stream Playback ID
This endpoint allows you to remove a specific playback ID associated with a live stream. Deleting a playback ID will revoke access to the live stream content linked to that ID, providing you with control over who can access your live streaming content.
Use the DeletePlaybackIdOfStreamAsync()
method to remove a playback ID for a live stream.
For more details refer to Delete Live Stream Playback ID API documentation.
string streamId = "your-stream-id";
string playbackId = "your-playback-id";
await fastPix.Playback.DeletePlaybackIdOfStreamAsync(streamId, playbackId);
Console.WriteLine("Live stream playback ID deleted successfully!");
2.8 Get Live Stream Playback ID
Retrieves details about a previously created playback ID. If you provide the distinct playback ID that was given back to you in the previous stream or playbackId create request, FastPix will provide the relevant playback details such as the access policy.
Use the GetLiveStreamPlaybackIdAsync()
method to retrieve the playback policy for a specific live stream playback ID.
For more details refer to Get Live Stream Playback ID API documentation.
string streamId = "your-stream-id";
string playbackId = "your-playback-id";
var response = await fastPix.Playback.GetLiveStreamPlaybackIdAsync(streamId, playbackId);
if (response.PlaybackIdResponse?.Data != null)
{
Console.WriteLine($"Playback Policy: {response.PlaybackIdResponse.Data.AccessPolicy}");
}
2.9 Create Simulcast
Lets you to create a simulcast for a parent live stream. A simulcast enables you to broadcast the live stream to multiple platforms simultaneously (e.g., YouTube, Facebook, or Twitch). This feature is useful for expanding your audience reach across different platforms. However, a simulcast can only be created when the parent live stream is in an idle state (i.e., not currently live or disabled). Additionally, only one simulcast target can be created per API call.
Use the CreateSimulcastOfStreamAsync()
method to create a new simulcast for a live stream.
For more details refer to Create Simulcast API documentation.
string streamId = "your-stream-id";
var request = new SimulcastRequest
{
Platform = SimulcastRequestPlatform.Youtube,
Credentials = new SimulcastRequestCredentials
{
StreamKey = "your-youtube-stream-key"
}
};
var response = await fastPix.SimulcastStream.CreateSimulcastOfStreamAsync(streamId, request);
if (response.SimulcastResponse?.Data != null)
{
Console.WriteLine("Simulcast created successfully!");
Console.WriteLine($"Simulcast ID: {response.SimulcastResponse.Data.Id}");
}
2.10 Get Simulcast Details
Retrieves the details of a specific simulcast associated with a parent live stream. By providing both the streamId of the parent stream and the simulcastId, FastPix returns detailed information about the simulcast, such as the stream URL, the status of the simulcast (active or idle), and metadata.
Use the GetSpecificSimulcastOfStreamAsync()
method to retrieve details of a specific simulcast for a live stream.
For more details refer to Get Simulcast Details API documentation.
string streamId = "your-stream-id";
string simulcastId = "your-simulcast-id";
var response = await fastPix.SimulcastStream.GetSpecificSimulcastOfStreamAsync(streamId, simulcastId);
if (response.SimulcastResponse?.Data != null)
{
var simulcast = response.SimulcastResponse.Data;
Console.WriteLine($"Simulcast ID: {simulcast.Id}");
Console.WriteLine($"Platform: {simulcast.Platform}");
Console.WriteLine($"Status: {simulcast.Status}");
}
2.11 Update Simulcast
Allows you to enable or disable a specific simulcast associated with a parent live stream. The status of the simulcast can be updated at any point, whether the live stream is active or idle. However, once the live stream is disabled, the simulcast can no longer be modified.
Use the UpdateSpecificSimulcastOfStreamAsync()
method to modify the configuration of a simulcast stream.
For more details refer to Update Simulcast API documentation.
string streamId = "your-stream-id";
string simulcastId = "your-simulcast-id";
var request = new SimulcastUpdateRequest
{
Status = SimulcastUpdateRequestStatus.Idle
};
var response = await fastPix.SimulcastStream.UpdateSpecificSimulcastOfStreamAsync(streamId, simulcastId, request);
if (response.SimulcastResponse?.Data != null)
{
Console.WriteLine("Simulcast updated successfully!");
}
2.12 Delete Simulcast
Allows you to delete a simulcast using its unique simulcastId, which was returned during the simulcast creation process. Deleting a simulcast stops the broadcast to the associated platform, but the parent stream will continue to run if it is live. This action is irreversible, and a new simulcast would need to be created if you want to resume streaming to the same platform.
Use the DeleteSimulcastOfStreamAsync()
method to remove a specific simulcast from a live stream.
For more details refer to Delete Simulcast API documentation.
string streamId = "your-stream-id";
string simulcastId = "your-simulcast-id";
await fastPix.SimulcastStream.DeleteSimulcastOfStreamAsync(streamId, simulcastId);
Console.WriteLine("Simulcast deleted successfully!");
Error Handling
Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception.
By default an API error will raise a Models.Errors.APIException
exception, which has the following properties:
Property | Type | Description |
---|---|---|
Message | string | The error message |
StatusCode | int | The HTTP status code |
RawResponse | HttpResponseMessage | The raw HTTP response |
Body | string | The response content |
Example Error Handling
try
{
var response = await fastPix.StartLiveStream.CreateNewStreamAsync(request);
if (response.LiveStreamResponseDTO?.Data != null)
{
// Handle success
Console.WriteLine($"Stream created: {response.LiveStreamResponseDTO.Data.StreamId}");
}
}
catch (UnauthorizedException ex)
{
// Handle authentication errors
Console.WriteLine($"Authentication failed: {ex.Message}");
}
catch (ValidationErrorResponse ex)
{
// Handle validation errors
Console.WriteLine($"Validation error: {ex.Message}");
}
catch (APIException ex)
{
// Handle general API errors
Console.WriteLine($"API error: {ex.Message}");
}
Support & Resources
Getting Help
- Documentation: Visit the FastPix API Reference for detailed API documentation
- GitHub Issues: Report bugs or request features on the GitHub repository.
Additional Resources
- SDK Repository:
- API Documentation: https://docs.fastpix.io/reference
- FastPix Platform:
SDK Maturity
This SDK is currently in beta. While it’s production-ready, there may be breaking changes between versions without a major version update. We recommend:
- Pinning to specific versions for production applications
- Testing thoroughly before deploying updates
- Monitoring the changelog for any breaking changes
Updated 2 days ago