Kotlin SDK for Jellyfin, supporting Android and JVM targets
Go to file
2021-03-18 22:08:46 +01:00
.ci Only upload artifacts to GitHub releases in Azure pipeline 2021-03-13 12:09:41 +01:00
.github/workflows Move publishing CI to GitHub actions 2021-03-13 12:05:03 +01:00
buildSrc Move publishing CI to GitHub actions 2021-03-13 12:05:03 +01:00
gradle/wrapper Update Gradle Wrapper from 6.8.2 to 6.8.3. 2021-02-23 04:18:15 +00:00
jellyfin-api Update generated sources (10.7.0 stable) 2021-03-09 17:12:53 +01:00
jellyfin-core Use ApiConstants in Jellyfin.apiVersion 2021-02-20 16:05:52 +01:00
jellyfin-model Update generated sources (10.7.0 stable) 2021-03-09 17:12:53 +01:00
jellyfin-platform-android Remove versionName and versionCode from android module (#179) 2021-02-20 15:12:36 +01:00
openapi-generator Use OperationBuilder as parent class in OperationUrlBuilder and remove duplicate code 2021-03-03 17:30:01 +01:00
samples/kotlin-cli Add "observe" command to CLI sample to listen for WebSocket messages (#177) 2021-02-20 15:20:00 +01:00
.editorconfig Set default value for requireAuthentication (#155) 2020-12-08 20:26:48 +01:00
.gitattributes Mark openapi.json as vendored 2020-11-15 13:05:02 +01:00
.gitignore Update gitignore 2020-09-13 13:05:34 +02:00
build.gradle.kts Move publishing CI to GitHub actions 2021-03-13 12:05:03 +01:00
CODEOWNERS Add CODEOWNERS file 2021-03-18 22:08:46 +01:00
detekt.yml Add Detekt plugin 2020-06-01 16:48:57 +02:00
gradle.properties Publish to Sonatype OSS 2021-03-10 22:49:37 +01:00
gradlew Update Gradle Wrapper from 6.7 to 6.8.2. 2021-02-22 04:19:49 +00:00
gradlew.bat Update Gradle Wrapper from 6.7 to 6.8.2. 2021-02-22 04:19:49 +00:00
LICENSE Update license to LGPL 3.0 2020-09-13 17:08:50 +02:00
openapi.json Update generated sources (10.7.0 stable) 2021-03-09 17:12:53 +01:00
README.md add bintray badge 2020-12-07 19:48:13 +01:00
settings.gradle.kts Rename kotlin-console to kotlin-cli 2020-10-31 11:11:30 +01:00

Jellyfin Java API Client

Part of the Jellyfin Project


Logo Banner

Azure DevOps builds LGPL 3.0 license Current Release Bintray Release
Donate Chat on Matrix Join our Subreddit Release RSS Feed Master Commits RSS Feed


This library allows Java and Android applications to easily access Jellyfin servers. The dependencies are modular and can easily be swapped out with alternate implementations when desired.

Setup

The API client is available through JCenter, and thus can be installed via Gradle like any other dependency:

// build.gradle.kts
repositories {
	jcenter()
}

dependencies {
	val apiclientVersion = "…"

	// For non-Android projects
	implementation("org.jellyfin.apiclient:library:$apiclientVersion")

	// For Android apps (automatically includes the library and models)
	implementation("org.jellyfin.apiclient:android:$apiclientVersion")
}
// build.gradle
repositories {
	jcenter()
}

dependencies {
	def apiclientVersion = "…"

	// For non-Android projects
	implementation "org.jellyfin.apiclient:library:$apiclientVersion"

	// For Android apps (automatically includes the library and models)
	implementation "org.jellyfin.apiclient:android:$apiclientVersion"
}

Basic Examples

Here you can find some basic examples on how to use the API client library.

Android Example

This Kotlin example creates a new instance of the Jellyfin class with Android support enabled. It will then try to authenticate to a server with a username and password combination.

// Create a Jellyfin instance
val jellyfin = Jellyfin {
	// It is recommended to create an own logger implementation
	logger = NullLogger()
	android(context)
}

// Create a new api client
val apiClient = jellyfin.createApi(
	serverAddress = "http://localhost:8096",
	device = AndroidDevice.fromContext(context)
)

// Call authenticate function
apiClient.AuthenticateUserAsync("username", "password", object : Response<AuthenticationResult>() {
	override fun onResponse(result: AuthenticationResult) {
		// Authentication succeeded
	}

	override fun onError(error: Exception) {
		// Authentication failed
	}
})

Websockets Example

Once you have an ApiClient instance you can easily connect to the server's websocket using the following command.

apiClient.OpenWebSocket()

This will open a connection in a background thread, and periodically check to ensure it's still connected. The web socket provides various events that can be used to receive notifications from the server. Simply override the methods in the ApiEventListener class which can be passed to the "createApi" function.

override fun onSetVolumeCommand(value: Int) {
}

Java Example

The Jellyfin library supports both Java and Kotlin out of the box. The basic Android example in Java looks like this:

// Create the options using the options builder
JellyfinOptions.Builder options = new JellyfinOptions.Builder();
options.setLogger(new NullLogger());
JellyfinAndroidKt.android(options, context);

// Create a Jellyfin instance
Jellyfin jellyfin = new Jellyfin(options.build());

// Create a new api client
ApiClient apiClient = jellyfin.createApi(
		"http://localhost:8096",
		null,
		AndroidDevice.fromContext(context),
		new ApiEventListener()
);

// Call authenticate function
apiClient.AuthenticateUserAsync("username", "password", new Response<AuthenticationResult>() {
	@Override
	public void onResponse(AuthenticationResult response) {
		// Authentication succeeded
	}

	@Override
	public void onError(Exception exception) {
		// Authentication failed
	}
});

Projects using the API client

This library can be utilized in any JVM or Android based application and serves as an abstraction layer to interact with the API endpoints provided by a current version of Jellyfin server. We already use this library within our own official clients and is is used by other third-party clients as well.

Jellyfin for Android

Jellyfin for Android is our official Kotlin based Android client for phones and tablets.

Jellyfin for Android TV

Jellyfin for Android TV is the official Android TV client for devices running Android TV, Fire TV or Google TV.

Gelli

Gelli is a music-focused third-party Android client.