The Livepeer Java SDK provides convenient access to the Livepeer Studio API from applications written in Java.
For full documentation and examples, please visit docs.livepeer.org.
JDK 11 or later is required.
The samples below show how a published SDK artifact is used:
Gradle:
implementation 'studio.livepeer:livepeer:0.5.0'
Maven:
<dependency>
<groupId>studio.livepeer</groupId>
<artifactId>livepeer</artifactId>
<version>0.5.0</version>
</dependency>
After cloning the git repository to your file system you can build the SDK artifact from source to the build
directory by running ./gradlew build
on *nix systems or gradlew.bat
on Windows systems.
If you wish to build from source and publish the SDK artifact to your local Maven repository (on your filesystem) then use the following command (after cloning the git repo locally):
On *nix:
./gradlew publishToMavenLocal -Pskip.signing
On Windows:
gradlew.bat publishToMavenLocal -Pskip.signing
package hello.world;
import java.lang.Exception;
import java.util.List;
import java.util.Map;
import studio.livepeer.livepeer.Livepeer;
import studio.livepeer.livepeer.models.components.FfmpegProfile;
import studio.livepeer.livepeer.models.components.Location;
import studio.livepeer.livepeer.models.components.Multistream;
import studio.livepeer.livepeer.models.components.NewStreamPayload;
import studio.livepeer.livepeer.models.components.NewStreamPayloadRecordingSpec;
import studio.livepeer.livepeer.models.components.PlaybackPolicy;
import studio.livepeer.livepeer.models.components.Profile;
import studio.livepeer.livepeer.models.components.Pull;
import studio.livepeer.livepeer.models.components.Target;
import studio.livepeer.livepeer.models.components.TargetSpec;
import studio.livepeer.livepeer.models.components.TranscodeProfile;
import studio.livepeer.livepeer.models.components.TranscodeProfileEncoder;
import studio.livepeer.livepeer.models.components.TranscodeProfileProfile;
import studio.livepeer.livepeer.models.components.Type;
import studio.livepeer.livepeer.models.errors.SDKError;
import studio.livepeer.livepeer.models.operations.CreateStreamResponse;
public class Application {
public static void main(String[] args) throws Exception {
try {
Livepeer sdk = Livepeer.builder()
.apiKey("<YOUR_BEARER_TOKEN_HERE>")
.build();
NewStreamPayload req = NewStreamPayload.builder()
.name("test_stream")
.pull(Pull.builder()
.source("https://myservice.com/live/stream.flv")
.headers(Map.ofEntries(
Map.entry("Authorization", "Bearer 123")))
.location(Location.builder()
.lat(39.739d)
.lon(-104.988d)
.build())
.build())
.playbackPolicy(PlaybackPolicy.builder()
.type(Type.WEBHOOK)
.webhookId("1bde4o2i6xycudoy")
.webhookContext(Map.ofEntries(
Map.entry("streamerId", "my-custom-id")))
.refreshInterval(600d)
.build())
.profiles(List.of(
FfmpegProfile.builder()
.width(1280L)
.name("720p")
.height(720L)
.bitrate(3000000L)
.fps(30L)
.fpsDen(1L)
.quality(23L)
.gop("2")
.profile(Profile.H264_BASELINE)
.build()))
.record(false)
.recordingSpec(NewStreamPayloadRecordingSpec.builder()
.profiles(List.of(
TranscodeProfile.builder()
.bitrate(3000000L)
.width(1280L)
.name("720p")
.height(720L)
.quality(23L)
.fps(30L)
.fpsDen(1L)
.gop("2")
.profile(TranscodeProfileProfile.H264_BASELINE)
.encoder(TranscodeProfileEncoder.H264)
.build()))
.build())
.multistream(Multistream.builder()
.targets(List.of(
Target.builder()
.profile("720p0")
.videoOnly(false)
.id("PUSH123")
.spec(TargetSpec.builder()
.url("rtmps://live.my-service.tv/channel/secretKey")
.name("My target")
.build())
.build()))
.build())
.build();
CreateStreamResponse res = sdk.stream().create()
.request(req)
.call();
if (res.stream().isPresent()) {
// handle response
}
} catch (SDKError e) {
// handle exception
throw e;
} catch (Exception e) {
// handle exception
throw e;
}
}
}
- create - Create a stream
- getAll - Retrieve streams
- get - Retrieve a stream
- update - Update a stream
- delete - Delete a stream
- terminate - Terminates a live stream
- startPull - Start ingest for a pull stream
- createClip - Create a clip
- getClips - Retrieve clips of a livestream
- addMultistreamTarget - Add a multistream target
- removeMultistreamTarget - Remove a multistream target
- getAll - Retrieve Multistream Targets
- create - Create a multistream target
- get - Retrieve a multistream target
- update - Update Multistream Target
- delete - Delete a multistream target
- getAll - Retrieve a Webhook
- create - Create a webhook
- get - Retrieve a webhook
- update - Update a webhook
- delete - Delete a webhook
- getLogs - Retrieve webhook logs
- getLog - Retrieve a webhook log
- resendLog - Resend a webhook
- getAll - Retrieve assets
- create - Upload an asset
- createViaUrl - Upload asset via URL
- get - Retrieves an asset
- update - Patch an asset
- delete - Delete an asset
- getClips - Retrieve clips of a session
- getAll - Retrieve sessions
- get - Retrieve a session
- getRecorded - Retrieve Recorded Sessions
create- Create a room⚠️ Deprecatedget- Retrieve a room⚠️ Deprecateddelete- Delete a room⚠️ DeprecatedstartEgress- Start room RTMP egress⚠️ DeprecatedstopEgress- Stop room RTMP egress⚠️ DeprecatedcreateUser- Create a room user⚠️ DeprecatedgetUser- Get user details⚠️ DeprecatedupdateUser- Update a room user⚠️ DeprecateddeleteUser- Remove a user from the room⚠️ Deprecated
- getRealtimeViewership - Query realtime viewership
- getViewership - Query viewership metrics
- getCreatorViewership - Query creator viewership metrics
- getPublicViewership - Query public total views metrics
- getUsage - Query usage metrics
- create - Create a signing key
- getAll - Retrieves signing keys
- delete - Delete Signing Key
- get - Retrieves a signing key
- update - Update a signing key
- create - Transcode a video
- get - Retrieve Playback Info
Handling errors in this SDK should largely match your expectations. All operations return a response object or raise an error. If Error objects are specified in your OpenAPI Spec, the SDK will throw the appropriate Exception type.
Error Object | Status Code | Content Type |
---|---|---|
models/errors/Error | 404 | application/json |
models/errors/SDKError | 4xx-5xx | */* |
package hello.world;
import java.lang.Exception;
import studio.livepeer.livepeer.Livepeer;
import studio.livepeer.livepeer.models.errors.SDKError;
import studio.livepeer.livepeer.models.operations.GetPlaybackInfoResponse;
public class Application {
public static void main(String[] args) throws Exception {
try {
Livepeer sdk = Livepeer.builder()
.apiKey("<YOUR_BEARER_TOKEN_HERE>")
.build();
GetPlaybackInfoResponse res = sdk.playback().get()
.id("<value>")
.call();
if (res.playbackInfo().isPresent()) {
// handle response
}
} catch (studio.livepeer.livepeer.models.errors.Error e) {
// handle exception
throw e;
} catch (SDKError e) {
// handle exception
throw e;
} catch (Exception e) {
// handle exception
throw e;
}
}
}
You can override the default server globally by passing a server index to the serverIndex
builder method when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
# | Server | Variables |
---|---|---|
0 | https://livepeer.studio/api |
None |
package hello.world;
import java.lang.Exception;
import java.util.List;
import java.util.Map;
import studio.livepeer.livepeer.Livepeer;
import studio.livepeer.livepeer.models.components.FfmpegProfile;
import studio.livepeer.livepeer.models.components.Location;
import studio.livepeer.livepeer.models.components.Multistream;
import studio.livepeer.livepeer.models.components.NewStreamPayload;
import studio.livepeer.livepeer.models.components.NewStreamPayloadRecordingSpec;
import studio.livepeer.livepeer.models.components.PlaybackPolicy;
import studio.livepeer.livepeer.models.components.Profile;
import studio.livepeer.livepeer.models.components.Pull;
import studio.livepeer.livepeer.models.components.Target;
import studio.livepeer.livepeer.models.components.TargetSpec;
import studio.livepeer.livepeer.models.components.TranscodeProfile;
import studio.livepeer.livepeer.models.components.TranscodeProfileEncoder;
import studio.livepeer.livepeer.models.components.TranscodeProfileProfile;
import studio.livepeer.livepeer.models.components.Type;
import studio.livepeer.livepeer.models.errors.SDKError;
import studio.livepeer.livepeer.models.operations.CreateStreamResponse;
public class Application {
public static void main(String[] args) throws Exception {
try {
Livepeer sdk = Livepeer.builder()
.serverIndex(0)
.apiKey("<YOUR_BEARER_TOKEN_HERE>")
.build();
NewStreamPayload req = NewStreamPayload.builder()
.name("test_stream")
.pull(Pull.builder()
.source("https://myservice.com/live/stream.flv")
.headers(Map.ofEntries(
Map.entry("Authorization", "Bearer 123")))
.location(Location.builder()
.lat(39.739d)
.lon(-104.988d)
.build())
.build())
.playbackPolicy(PlaybackPolicy.builder()
.type(Type.WEBHOOK)
.webhookId("1bde4o2i6xycudoy")
.webhookContext(Map.ofEntries(
Map.entry("streamerId", "my-custom-id")))
.refreshInterval(600d)
.build())
.profiles(List.of(
FfmpegProfile.builder()
.width(1280L)
.name("720p")
.height(720L)
.bitrate(3000000L)
.fps(30L)
.fpsDen(1L)
.quality(23L)
.gop("2")
.profile(Profile.H264_BASELINE)
.build()))
.record(false)
.recordingSpec(NewStreamPayloadRecordingSpec.builder()
.profiles(List.of(
TranscodeProfile.builder()
.bitrate(3000000L)
.width(1280L)
.name("720p")
.height(720L)
.quality(23L)
.fps(30L)
.fpsDen(1L)
.gop("2")
.profile(TranscodeProfileProfile.H264_BASELINE)
.encoder(TranscodeProfileEncoder.H264)
.build()))
.build())
.multistream(Multistream.builder()
.targets(List.of(
Target.builder()
.profile("720p0")
.videoOnly(false)
.id("PUSH123")
.spec(TargetSpec.builder()
.url("rtmps://live.my-service.tv/channel/secretKey")
.name("My target")
.build())
.build()))
.build())
.build();
CreateStreamResponse res = sdk.stream().create()
.request(req)
.call();
if (res.stream().isPresent()) {
// handle response
}
} catch (SDKError e) {
// handle exception
throw e;
} catch (Exception e) {
// handle exception
throw e;
}
}
}
The default server can also be overridden globally by passing a URL to the serverURL
builder method when initializing the SDK client instance. For example:
package hello.world;
import java.lang.Exception;
import java.util.List;
import java.util.Map;
import studio.livepeer.livepeer.Livepeer;
import studio.livepeer.livepeer.models.components.FfmpegProfile;
import studio.livepeer.livepeer.models.components.Location;
import studio.livepeer.livepeer.models.components.Multistream;
import studio.livepeer.livepeer.models.components.NewStreamPayload;
import studio.livepeer.livepeer.models.components.NewStreamPayloadRecordingSpec;
import studio.livepeer.livepeer.models.components.PlaybackPolicy;
import studio.livepeer.livepeer.models.components.Profile;
import studio.livepeer.livepeer.models.components.Pull;
import studio.livepeer.livepeer.models.components.Target;
import studio.livepeer.livepeer.models.components.TargetSpec;
import studio.livepeer.livepeer.models.components.TranscodeProfile;
import studio.livepeer.livepeer.models.components.TranscodeProfileEncoder;
import studio.livepeer.livepeer.models.components.TranscodeProfileProfile;
import studio.livepeer.livepeer.models.components.Type;
import studio.livepeer.livepeer.models.errors.SDKError;
import studio.livepeer.livepeer.models.operations.CreateStreamResponse;
public class Application {
public static void main(String[] args) throws Exception {
try {
Livepeer sdk = Livepeer.builder()
.serverURL("https://livepeer.studio/api")
.apiKey("<YOUR_BEARER_TOKEN_HERE>")
.build();
NewStreamPayload req = NewStreamPayload.builder()
.name("test_stream")
.pull(Pull.builder()
.source("https://myservice.com/live/stream.flv")
.headers(Map.ofEntries(
Map.entry("Authorization", "Bearer 123")))
.location(Location.builder()
.lat(39.739d)
.lon(-104.988d)
.build())
.build())
.playbackPolicy(PlaybackPolicy.builder()
.type(Type.WEBHOOK)
.webhookId("1bde4o2i6xycudoy")
.webhookContext(Map.ofEntries(
Map.entry("streamerId", "my-custom-id")))
.refreshInterval(600d)
.build())
.profiles(List.of(
FfmpegProfile.builder()
.width(1280L)
.name("720p")
.height(720L)
.bitrate(3000000L)
.fps(30L)
.fpsDen(1L)
.quality(23L)
.gop("2")
.profile(Profile.H264_BASELINE)
.build()))
.record(false)
.recordingSpec(NewStreamPayloadRecordingSpec.builder()
.profiles(List.of(
TranscodeProfile.builder()
.bitrate(3000000L)
.width(1280L)
.name("720p")
.height(720L)
.quality(23L)
.fps(30L)
.fpsDen(1L)
.gop("2")
.profile(TranscodeProfileProfile.H264_BASELINE)
.encoder(TranscodeProfileEncoder.H264)
.build()))
.build())
.multistream(Multistream.builder()
.targets(List.of(
Target.builder()
.profile("720p0")
.videoOnly(false)
.id("PUSH123")
.spec(TargetSpec.builder()
.url("rtmps://live.my-service.tv/channel/secretKey")
.name("My target")
.build())
.build()))
.build())
.build();
CreateStreamResponse res = sdk.stream().create()
.request(req)
.call();
if (res.stream().isPresent()) {
// handle response
}
} catch (SDKError e) {
// handle exception
throw e;
} catch (Exception e) {
// handle exception
throw e;
}
}
}
This SDK supports the following security scheme globally:
Name | Type | Scheme |
---|---|---|
apiKey |
http | HTTP Bearer |
To authenticate with the API the apiKey
parameter must be set when initializing the SDK client instance. For example:
package hello.world;
import java.lang.Exception;
import java.util.List;
import java.util.Map;
import studio.livepeer.livepeer.Livepeer;
import studio.livepeer.livepeer.models.components.FfmpegProfile;
import studio.livepeer.livepeer.models.components.Location;
import studio.livepeer.livepeer.models.components.Multistream;
import studio.livepeer.livepeer.models.components.NewStreamPayload;
import studio.livepeer.livepeer.models.components.NewStreamPayloadRecordingSpec;
import studio.livepeer.livepeer.models.components.PlaybackPolicy;
import studio.livepeer.livepeer.models.components.Profile;
import studio.livepeer.livepeer.models.components.Pull;
import studio.livepeer.livepeer.models.components.Target;
import studio.livepeer.livepeer.models.components.TargetSpec;
import studio.livepeer.livepeer.models.components.TranscodeProfile;
import studio.livepeer.livepeer.models.components.TranscodeProfileEncoder;
import studio.livepeer.livepeer.models.components.TranscodeProfileProfile;
import studio.livepeer.livepeer.models.components.Type;
import studio.livepeer.livepeer.models.errors.SDKError;
import studio.livepeer.livepeer.models.operations.CreateStreamResponse;
public class Application {
public static void main(String[] args) throws Exception {
try {
Livepeer sdk = Livepeer.builder()
.apiKey("<YOUR_BEARER_TOKEN_HERE>")
.build();
NewStreamPayload req = NewStreamPayload.builder()
.name("test_stream")
.pull(Pull.builder()
.source("https://myservice.com/live/stream.flv")
.headers(Map.ofEntries(
Map.entry("Authorization", "Bearer 123")))
.location(Location.builder()
.lat(39.739d)
.lon(-104.988d)
.build())
.build())
.playbackPolicy(PlaybackPolicy.builder()
.type(Type.WEBHOOK)
.webhookId("1bde4o2i6xycudoy")
.webhookContext(Map.ofEntries(
Map.entry("streamerId", "my-custom-id")))
.refreshInterval(600d)
.build())
.profiles(List.of(
FfmpegProfile.builder()
.width(1280L)
.name("720p")
.height(720L)
.bitrate(3000000L)
.fps(30L)
.fpsDen(1L)
.quality(23L)
.gop("2")
.profile(Profile.H264_BASELINE)
.build()))
.record(false)
.recordingSpec(NewStreamPayloadRecordingSpec.builder()
.profiles(List.of(
TranscodeProfile.builder()
.bitrate(3000000L)
.width(1280L)
.name("720p")
.height(720L)
.quality(23L)
.fps(30L)
.fpsDen(1L)
.gop("2")
.profile(TranscodeProfileProfile.H264_BASELINE)
.encoder(TranscodeProfileEncoder.H264)
.build()))
.build())
.multistream(Multistream.builder()
.targets(List.of(
Target.builder()
.profile("720p0")
.videoOnly(false)
.id("PUSH123")
.spec(TargetSpec.builder()
.url("rtmps://live.my-service.tv/channel/secretKey")
.name("My target")
.build())
.build()))
.build())
.build();
CreateStreamResponse res = sdk.stream().create()
.request(req)
.call();
if (res.stream().isPresent()) {
// handle response
}
} catch (SDKError e) {
// handle exception
throw e;
} catch (Exception e) {
// handle exception
throw e;
}
}
}
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
While we value open-source contributions to this SDK, this library is generated programmatically. Feel free to open a PR or a Github issue as a proof of concept and we'll do our best to include it in a future release!