sfuhrm / radiobrowser4j

RadioBrowser Java API library
Other
50 stars 8 forks source link
android api api-client api-wrapper internet-radio-player internet-radio-stations java java-api jdk library radio-station radiobrowser rest rest-client

RadioBrowser4j

Java CI Java Integration [Coverage]() Maven Central ReleaseDate javadoc License

A Java API for the RadioBrowser internet radio station online repository.

The library is useful for applications wanting to retrieve internet radio station URLs, streams and meta information.

How to use

Maven for JDK targets

First step is to include the dependency in your Maven or Gradle project. For Maven, you need this dependency:

<dependency>
    <groupId>de.sfuhrm</groupId>
    <artifactId>radiobrowser4j</artifactId>
    <version>3.1.0</version>
</dependency>

Use within Android projects

The library works well with Android projects simply by referencing the library within the build.gradle

    implementation 'de.sfuhrm:radiobrowser4j:3.1.0'

If Proguard or R8 code shrinking and obfuscation is being used, then the following entries should be added to the Proguard configuration file (usually proguard-rules.pro):

-dontwarn lombok**
-keep class de.sfuhrm.radiobrowser4j.** { *; }
-keepattributes Signature
-keep class com.google.gson.reflect.TypeToken { *; }
-keep class * extends com.google.gson.reflect.TypeToken

Java use

After adding the dependency, you can start by creating one instance and using it

// discover endpoint
Optional<String> endpoint = new EndpointDiscovery(myAgent).discover();

// build instance
RadioBrowser radioBrowser = new RadioBrowser(
    ConnectionParams.builder().apiUrl(endpoint.get()).userAgent("Demo agent/1.0").timeout(5000).build());

// list stations
radioBrowser.listStations(ListParameter.create().order(FieldName.name))
    .limit(64)
    .forEach(s -> System.out.printf("%s: %s%n",
        s.getName(),
        s.getUrl()
));

You can take a look at the javadoc documentation to get the full concepts of the API.

More examples

The library was extracted from an internet radio player and recorder program in Java, radiorecorder. You can take a look at real-life usage patterns there.

How it is tested

The API is tested using the WireMock REST testing framework. Mocked web requests/responses are located in the test resources.

Version history

License

Copyright 2017-2024 Stephan Fuhrmann

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and