Use the official Mux SDK for Java to call the Mux API from your server. The SDK handles authentication and wraps each API endpoint in native Java code.
The Mux SDK for Java wraps the Mux REST API in native Java code. Use this SDK when you write your server application in Java. You can create assets, manage live streams, and query Mux Data without manual HTTP requests.
There are several ways to add the Mux Java SDK to your project:
Add this dependency to your project's POM:
<dependency>
<groupId>com.mux</groupId>
<artifactId>mux-sdk-java</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>Add this dependency to your project's build file:
compile "com.mux:mux-sdk-java:1.0.0"To start, you'll need a Mux access token. Once you've got that, you're off to the races!
// Import classes:
import com.mux.ApiClient;
import com.mux.ApiException;
import com.mux.Configuration;
import com.mux.auth.*;
import com.mux.models.*;
import com.mux.sdk.AssetsApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("https://api.mux.com");
// Configure HTTP basic authorization: accessToken
HttpBasicAuth accessToken = (HttpBasicAuth) defaultClient.getAuthentication("accessToken");
accessToken.setUsername("YOUR USERNAME");
accessToken.setPassword("YOUR PASSWORD");
AssetsApi apiInstance = new AssetsApi(defaultClient);
CreateAssetRequest createAssetRequest = {"input":[{"url":"https://muxed.s3.amazonaws.com/leds.mp4"}],"playback_policy":["public"],"video_quality":"basic"}; // CreateAssetRequest |
try {
AssetResponse result = apiInstance.createAsset(createAssetRequest)
.execute();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling AssetsApi#createAsset");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}Check out the Mux Java SDK docs for more information.