Upload And Streaming Video In Azure Media Service with JAVA.

Upload And Streaming Video In Azure Media Service with JAVA.

Hi All,

This is the Second Article of the Azure Media Service. In the first article we discussed about how to upload and stream video manually. You can see the article from here.

What to Learn

In this article we will discuss about how we can streaming video by using java

Lets Start

  • Go to your Azure Media Service Portal.

  • From Side Nab select API Access.

  • Then Select your ADD app and Secret.

  • Select Media Services API version as V3

Then copy all your properties

{ "_comment": "For security reasons, please do not check in this file to source control.",

"AadClientId": "00000000-0000-0000-0000-000000000000",

"AadEndpoint": "https://login.microsoftonline.com",

"AadSecret": "00000000-0000-0000-0000-000000000000",

"AadTenantId": "00000000-0000-0000-0000-000000000000",

"AccountName": "amsaccount",

"ArmAadAudience": "https://management.core.windows.net/",

"ArmEndpoint": "https://management.azure.com/",

"Region": "West US 2",

"ResourceGroup": "amsResourceGroup",

"SubscriptionId": "00000000-0000-0000-0000-000000000000"

}

Then create a Streaming End Point,if you don't know how to create see this article

Now go to you Java Editor and create a Spring Boot Application. Here is the link of GitHub . Go there and Clone the project.

After clone go to Resources and Inside Config file add your properties which are you copied from Azure portal.

Then in main file set streaming end point which one you created.

private static final String STREAMING_ENDPOINT_NAME = "se";

if you want to keep your video streaming then comment the cleanup function. Then in pom file add this.

<dependency>
            <groupId>com.nimbusds</groupId>
            <artifactId>oauth2-oidc-sdk</artifactId>
            <version>5.64.4</version>
        </dependency>

After setup all this run the application.

This will give you three url of your video.

To check the url, you can visit azure portal demo site.

https://ampdemo.azureedge.net/

Upload Video From Api

You can see this article how to upload vide from angular to java api

Then we have to change some code.

Comment this

String fileToUpload = EncodingWithMESCustomPreset.class.getClassLoader().getResource(mediaFile).getPath(); // The file is a resource in CLASSPATH.
        File file = new File(fileToUpload);
        CloudBlockBlob blob = container.getBlockBlobReference(file.getName());

And add this

   CloudBlockBlob blob = container.getBlockBlobReference(assignFile.getOriginalFilename());