Azure Media Services v3 Node.js Typescript Samples
To make sure you are using the latest package, check @azure/arm-mediaservices.
The projects in this repository were created using Visual Studio Code.
|Project name||Use Case|
|HelloWorld-ListAssets/index.ts||Basic example on how to connect and list assets|
|Live/index.ts||Basic live streaming example. WARNING, make sure to check that all resources are cleaned up and no longer billing in portal when using live|
|StreamFilesSample/index.ts||Basic example for uploading a local file or encoding from a source URL. Sample shows how to use storage SDK to download content, and shows how to stream to a player|
|StreamFilesWithDRMSample/index.ts||Demonstrates how to encode and stream using Widevine and PlayReady DRM|
|VideoIndexerSample/index.ts||Example of using the Video and Audio Analyzer presets to generate metadata and insights from a video or audio file|
Download and install Visual Studio Code
Download and install Typescript
Install Typescript via npm
You can use npm to install TypeScript globally, this means you can use the tsc command anywhere in your terminal.
To do this,
run npm install -g typescript. This will install the latest version.
Clone the repository
git clone https://github.com/Azure-Samples/media-services-v3-node-tutorials.git
Navigate into the AMSv3Samples folder
Open Visual Studio Code
Rename the 'sample.env' file to '.env' and fill out the details from your Azure Media Services account portal API Access page. If you have not yet created an AMS account, first go into the Azure portal and search for Media Services and create a new account in the region of your choice. After creating the account, navigate to the API Access page and create an Azure Active Directory(AAD) Service Principal to generate the connection details required for the .env file. Copy the settings from the API Access blade that are required in the .env file. If you plan to use the DRM sample, you will need to generate a random base64 "DRM_SYMMETRIC_KEY" to use in the .env file as well. To get the exact values, follow Access APIs.
Open Terminal in VS Code (Ctrl+Shift+`), make sure you are in the "AMSV3Samples" folder and execute the following command to download all the required npm packages.
Next, in the Explorer view, open the "HelloWorld-ListAssets" folder, open the list-assets.ts file and press F5 to begin compiling the Typescript and launch the Debugger. Each project in this sample collection contains a single typescript file that can be launched by opening it and pressing the F5 key to enter the debugger. You can now set breakpoints, and walk through the code to learn how to implement basic Media Services scenarios in Node.js
The output from the HelloWorld-ListAssets may be empty if this is a new Media Services account with no new assets. Just make sure that the script executes cleanly through on the first run without any errors, and you can then upload some content into the portal to see the results again on the second run. If you have no errors and are ready to move on, move next to the StreamFilesSample for tutorial on how to upload a local file, encode it with "content aware encoding" and stream it with the Azure Media Player.
Common Issues and Troubleshooting
- Assets in Media Services have naming conventions that must be adhered to in order to avoid errors. For example the client.Assets.CreateOrUpdateAsync can fail with message "The resource type is invalid" if the name does not match the naming conventions listed in this article