Kotlin SDK for Jellyfin, supporting Android and JVM targets
Go to file
Niels van Velzen 0ecdb48f2b
Merge pull request #271 from jellyfin/fix-release-0.7.x
Bare minimum changes to allow JitPack build of final apiclient version without JCenter dependencies.
2021-06-12 12:08:42 +02:00
android Normalize the Android device name 2020-10-24 22:09:04 +02:00
buildSrc Bare minimum changes to allow JitPack build of final apiclient version without JCenter dependencies. 2021-06-12 12:05:24 +02:00
gradle/wrapper Upgrade gradle wrapper to 6.3 2020-04-30 17:03:44 +02:00
library Add setDevice method to BaseApiClient 2021-01-30 22:10:00 +01:00
model add method to get image blurhashes 2020-08-30 13:33:15 +09:00
samples/kotlin-console Bare minimum changes to allow JitPack build of final apiclient version without JCenter dependencies. 2021-06-12 12:05:24 +02:00
.editorconfig Use tabs for XML files 2020-05-01 11:12:37 +02:00
.gitignore Add buildSrc gradle project which contains build logic and dependencies 2020-08-15 11:57:34 +02:00
azure-pipelines.yml Fix GitHub release assets again 2020-09-12 09:54:45 +02:00
build.gradle.kts Bare minimum changes to allow JitPack build of final apiclient version without JCenter dependencies. 2021-06-12 12:05:24 +02:00
detekt.yml Add Detekt plugin 2020-06-01 16:48:57 +02:00
gradle.properties Bare minimum changes to allow JitPack build of final apiclient version without JCenter dependencies. 2021-06-12 12:05:24 +02:00
gradlew Upgrade gradle wrapper to 6.3 2020-04-30 17:03:44 +02:00
gradlew.bat Upgrade gradle wrapper to 6.3 2020-04-30 17:03:44 +02:00
LICENSE.md Update readme and copyright 2019-09-12 00:38:25 -04:00
README.md Various small fixes and code cleaning 2020-07-31 20:21:56 +02:00
settings.gradle.kts Add kotlin-console example using kotlinx.cli and the library 2020-07-20 21:48:52 +02:00

Jellyfin

The Free Software Media System


Logo Banner

MIT license Current Release
Donate Submit Feature Requests Discuss on our Forum 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.

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

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) {
}

Using Java

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
	}
});