Skip to content

AudioTrack Write Examples

peter-majeed edited this page Jan 7, 2013 · 3 revisions

#AudioTrack Write calls All calls that are part of the Brightcove AudioTrack Write API are wrapped and available within the .NET-MAPI-Wrapper. It functions identically in most ways to the Brightcove Video Write API. 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 error 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 an AudioTrack ```c# // Instantiate an API object by using the provided factory BrightcoveApi api = BrightcoveApiFactory.CreateApi("my API read token", "my API write token");
BrightcoveAudioTrack audioTrack = new BrightcoveAudioTrack
{
    ReferenceId = "test-audio-reference-id",
    Name = "test-audio-reference-id",
    ShortDescription = "Test audio, created via the API.",
    LongDescription = "Test audio, created via the API. Audio is from ccMixter, a community remix site created by Creative Commons: http://ccmixter.org/files/rslane32/12510"
};

// The path to the audio file.
const string saxString = "..\\..\\Assets\\rslane32_-_SAX_STRING.mp3";

long newId = api.CreateAudioTrack(audioTrack, saxString);

// Do something with the new id...

<a name="update-audiotrack" />
## Update an AudioTrack
```c#
    // Instantiate an API object by using the provided factory
    BrightcoveApi api = BrightcoveApiFactory.CreateApi("my API read token", "my API write token");
    
    // Retrieve an audio track that has the Id property already populated. This is necessary
    // because the Id has a private setter.
    BrightcoveAudioTrack audioTrack = api.FindAudioTrackByReferenceId("test-audio-reference-id");

    // Update the ReferenceId, ShortDescription, and the Tags collection.
    audioTrack.ReferenceId = "new-test-reference-id";
    audioTrack.ShortDescription = "random-string";
    audioTrack.Tags = new string[] { "Music", "Saxophone", "Samples" };
    
    BrightcoveAudioTrack result = api.UpdateAudioTrack(audioTrack);

    // Do something with the returned and updated audio track...
## Delete an AudioTrack ```c# // Instantiate an API object by using the provided factory BrightcoveApi api = BrightcoveApiFactory.CreateApi("my API read token", "my API write token");
BrightcoveAudioTrack audioTrack = api.FindAudioTrackByReferenceId("test-audio-reference-id");

// Deletes the audio track with this specific id.
// Will delete the audio track from any playlists it's part of.
// Will delete the audio track if it's shared to any other accounts.
api.DeleteAudioTrack(audioTrack.Id, true, true);

## See also
More [[Examples]]