Skip to content

Create a 3rd Party Plugin

Nick edited this page Aug 25, 2015 · 3 revisions

CumulusTV allows developers to create plugins that give them the ability to provide streams to the Live Channels app without the trouble of writing a custom adapter. Developers can customize their interface to suit their individual needs and then return with a JSONChannel containing all the pertinent information for a channel. These custom channels then get instantly integrated into the Live Channels app and the Google Drive sync file.

A plugin can do the following things:

  • Create a new channel
  • Update an existing channel
  • Delete an existing channel
  • Read all user channels (from the Plugin picker in the app)
  • Get notified when a channel is about to play and change the stream URL on the fly

The integrated channel creator/editor interface is itself a plugin, which can be a good starting point for a developer.

Initialize

First, you must create your class and extend CumulusTvPlugin. This is a class you can find in the source code. It extends AppCompatActivity along with adding helper methods for channel and intent support.

public class MainPicker extends CumulusTvPlugin {

}

Note: Your plugin is an activity; keep that in mind when developing capabilities

In your manifest, make sure that you include this class as a new activity and that it supports a custom intent action com.felkertech.cumulustv.ADD_CHANNEL

<activity
        android:name="com.felkertech.n.plugins.MainPicker"
        android:exported="true"
        android:enabled="true"
        android:label="Create a Channel"
        android:theme="@style/CompatTheme" >
        <intent-filter>
            <action android:name="com.felkertech.cumulustv.ADD_CHANNEL"/>
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
    </activity>

This makes your activity visible to the main application, but not necessarily to the launcher.

onCreate

Your onCreate method should be like creating any other activity. Create your layout, set up any services you might need. There is an initialization method you might want to change.

By default, every channel you create will by default have an additional option: source, which contains the package and activity name of where it was created. When the channel is then to be edited, CumulusTV automatically detects the original app and launches that. If you don't want this, call this method:

setProprietaryEditing(false);

This will prevent the source attribute from populating and preventing edit access from other apps.

Creating a new Channel

First, check whether you should be creating a new channel. areEditing() should be false. Your layout and workflow can be designed any way you want. However, at the end, you should be left with a JSONChannel. The constructor is as follows:

public JSONChannel(String number, String name, String url, String logo, String splash, String genres)

To save the channel, and then close the activity, call

saveChannel(JSONChannel);

Editing a Channel

When areEditing() is true, you are to update an already existing channel. To get the channel in question, call getChannel(), which returns a JSONChannel.

To save the channel and then close the activity, call

saveChannel(JSONChannel);

It's the same method as above.

Delete a Channel

To delete a channel, call

deleteChannel(JSONChannel);

Reading Channels

Currently you can only read channels when the user selects your plugin from the list of plugins in the CumulusTV app. You can check for this by calling areReadingAll() in your plugin.

You can receive a String of your JSON file by calling getAllChannels(). You'll want to turn it into either a JSONObject or a ChannelDatabase to make sense of it.

Channel Playing Notifier

When the stream is being edited through your interface, you may set the service attribute of the JSONChannel to specify a package name and a service name to run when the channel is about to be played. This service must launch, detect and change any issues in the channel, and sync those back to the main app in less than 5 seconds. Then the player app will refresh the stream and play it.