Skip to content

Video write examples

dmillz edited this page Feb 17, 2011 · 3 revisions

#Video Write calls All calls that are part of the Brightcove Video Write API are wrapped and available within the .NET-MAPI-Wrapper. You will find examples of some of the more common use cases below.

Important Note

API calls are subject to the whims of internet connectivity, and may throw an exception for any number of reasons:

  • The Brightcove API may be down or not functioning correctly.
  • Network connectivity may be lost between your application and Brightcove.
  • Invalid parameters passed to the API may result in an error message in the response JSON. The message will be wrapped in a BrightcoveApiException and thrown so that it may be handled via normal .NET error handling mechanisms.

Although the examples shown here do not include try/catch blocks, in order to ensure that your app is as robust as possible make sure to try/catch all API calls.

See Also

See how to work with the BrightcoveApi object on the Getting Started page.

Examples

## Create a new video by uploading a file ```c# // Instantiate an API object with write permission by using the provided factory BrightcoveApi api = BrightcoveApiFactory.CreateApi("my API read token", "my API write token");
// Increase the connection timeout 
// (optional, depending on your network connection and the size of the file)
api.Configuration.RequestTimeout = 600000; // allow 10 minutes for the upload to complete

// Create a new BrightcoveVideo object in order to specify information about the video
BrightcoveVideo video = new BrightcoveVideo();
video.Name = "My Video Name";
video.ReferenceId = "my-video-ref-id";
video.ShortDescription = "My video's short description";

// Specify the full path of the local video file to upload
string pathToFile = @"C:\full\path\to\video.mp4";

// Perform the API call
long newVideoId = api.CreateVideo(video, pathToFile);

The `api.Configuration.RequestTimeout` setting allows one to easily adjust the [`HttpWebRequest.Timeout`](http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.timeout.aspx) property used when making requests to the API. If you have a need to customize other request properties, you may swap-in your own [[custom IRequestBuilder|Customizing Request Properties]].

<a name="create-new" />
## Update an existing video's information
```c#
    // Instantiate an API object with write permission by using the provided factory
    BrightcoveApi api = BrightcoveApiFactory.CreateApi("my API read token", "my API write token");

    // Retrieve the video to be updated
    BrightcoveVideo video = api.FindVideoByReferenceId("my-ref-id");

    // Update the video's information
    video.ShortDescription = "My NEW short description";

    // Perform the API call to update the video. It will return an instance of the updated video
    BrightcoveVideo updatedVideo = api.UpdateVideo(video);
## Delete a video ```c# // Instantiate an API object with write permission by using the provided factory BrightcoveApi api = BrightcoveApiFactory.CreateApi("my API read token", "my API write token");
// Perform the API call (video Id, cascade deletions, and delete video from shares)
api.DeleteVideo(600000000000, true, true);

// The method is overloaded so that you may alternatively specify a reference ID
api.DeleteVideo("my-ref-id", true, true);

## See also
More [[Examples]]