Giter VIP home page Giter VIP logo

jellyfin-apiclient-java's Introduction

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.

jellyfin-apiclient-java's People

Contributors

andreasac avatar andreasgb avatar anthonylavado avatar bendardenne avatar dkanada avatar ebr11 avatar erayan avatar gradle-update-robot avatar h1dden-da3m0n avatar joshuaboniface avatar justaman avatar lukepulverenti avatar maxr1998 avatar nielsvanvelzen avatar redshirtmb avatar snazy2000 avatar thornbill avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.