Kotlin SDK for Jellyfin, supporting Android and JVM targets
Go to file
Niels van Velzen 57d51cb2cf Remove device name normalization
Required for Android WebView app only
2020-11-11 20:32:48 +01:00
.ci change to simplify version variable definition 2020-10-13 19:38:44 +02:00
buildSrc Miscellaneous fixes 2020-10-30 22:11:52 +01:00
gradle/wrapper Upgrade gradle wrapper to 6.3 2020-04-30 17:03:44 +02:00
jellyfin-api Merge pull request #134 from nielsvanvelzen/recommended-servers 2020-10-31 00:52:13 -04:00
jellyfin-core Miscellaneous fixes 2020-10-30 22:11:52 +01:00
jellyfin-model Miscellaneous fixes 2020-10-30 22:11:52 +01:00
jellyfin-platform-android Remove device name normalization 2020-11-11 20:32:48 +01:00
openapi-generator Add default values to API operations 2020-10-23 15:52:45 +02:00
samples/kotlin-console Miscellaneous fixes 2020-10-30 22:11:52 +01:00
.editorconfig Use tabs for XML files 2020-05-01 11:12:37 +02:00
.gitattributes Add openapi.json to git lfs 2020-10-14 21:40:58 +02:00
.gitignore Update gitignore 2020-09-13 13:05:34 +02:00
build.gradle.kts Enable core library desugaring for Android 2020-10-09 13:07:07 +02:00
detekt.yml Add Detekt plugin 2020-06-01 16:48:57 +02:00
gradle.properties Fix issue with Bintray using the wrong versions 2020-05-13 12:18:03 +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 Update license to LGPL 3.0 2020-09-13 17:08:50 +02:00
openapi.json Update OpenAPI spec 2020-10-16 09:10:13 +02:00
README.md Update title of license badge 2020-09-13 19:38:04 +02:00
settings.gradle.kts Add "jellyfin-" prefix to Gradle modules and rename "library" to "core" 2020-10-07 21:00:04 +02:00

Jellyfin

The Free Software Media System


Logo Banner

LGPL 3.0 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.

Setup

The apiclient 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"
}

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