Android Media Remote Service

The Android Media Remote Service example shows how you can:

  • Use the Kanzi Connect Android bindings (AAR file) to access the Kanzi Connect Server and publish both content and service functionality from a non-Kanzi Android application. The example is created using Android Studio.

  • Listen to connection state change events from the KanziConnectContext adaptation layer.

  • Implement table-based content providers for the Android platform using Java.

  • Implement a remote service for the Android platform using Java.

You can find this example in the <KanziConnectInstallation>/SDK/bindings/android/AndroidMediaRemoteService directory.

Structure of the example

This diagram shows the main functional entities of the example application. The application implements two media-related content providers and a Media Service that can play music. Everything runs on the UI thread of the Android application.

../_images/android-media-remote-servic-diagram.png

The Android Studio project contains:

  • MainActivity.java is the entry point for the example application. It shows how to instantiate content providers and monitor the connection state changes.

  • ContentProviderBaseExample.java implements the base class for content providers.

  • SongContentProvider.java contains a Kanzi Connect content provider for publishing music content from an Android device to Kanzi Connect Server.

  • PlaylistContentProvider.java is a fake content provider for publishing all music content as a single playlist named “All tracks”.

  • MediaServiceRunner.java implements the Android Service specialization.

  • MediaServiceConcept.java contains generated Java code that implements the Media Service API and message processing.

  • MediaService.java implements Media Service functionality.

  • MusicPlayer.java implements the music playback functionality used by MediaService.java.

Running the example

Note that you cannot use this example with the default Kanzi Connect Server because the server already has the Media Service running locally.

This diagram shows an example of how you can use the Android Media Remote Service example application to provide media content and service for the BindingsDemo and In-vehicle infotainment example applications. See Android bindings example and In-vehicle infotainment example.

../_images/example-setup.png

When you run the example for the first time, allow the application to access the device SD card. This way you allow the application to read the connection.xml file on the device SD card.

../_images/first-time-on-device.png

The application UI shows:

  • IP address and port at which the application connects to Kanzi Connect Server.

    For example, 127.0.0.1:2002.

  • Status of the connection:

    • CONNECTING

      The application is trying to establish a connection.

    • CONNECTED

      The application is successfully connected to a server.

    • DISCONNECTED

      Functionality was explicitly stopped and the application is not trying to automatically reconnect.

    • NOT PREPARED

      Intermediate state that Kanzi Connect uses when the software is starting up.

    • REGISTERING SERVICE

      Registering the media remote service.

    • WAITING RECONNECT

      The application failed to connect to a server and functionality waits for a short period before trying to reconnect.

../_images/application-connected-to-localhost.png