android | ||
buildSrc | ||
gradle/wrapper | ||
library | ||
model | ||
samples/kotlin-console | ||
.editorconfig | ||
.gitignore | ||
azure-pipelines.yml | ||
build.gradle.kts | ||
detekt.yml | ||
gradle.properties | ||
gradlew | ||
gradlew.bat | ||
LICENSE.md | ||
README.md | ||
settings.gradle.kts |
Jellyfin
The Free Software Media System
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
}
});