Page tree
Skip to end of metadata
Go to start of metadata

Download the Android SDK

 

 

Overview

The Android SDK provides easy access to the Frequency Services for an Android client. Services are provided to access videos using category and channel classifications along with direct search capabilities.

The Frequency data model is built on a Category containing one or more Channels, which contains one or more Videos. The Frequency data services are used to walk this data model.

The Android SDK includes the WebView based video player that is accessed as an Android Java class. The video player can be used independently if the client is using the REST API directly.

 

Adding the SDK to a project

In your project gradle file, add mavenCentral and the libs folder to the list of repositories.

Copy the Frequency's SDK .aar file in your libs folder

Add jackson-core and jackson-databind to the dependencies.

Authenticate
repositories {
    mavenCentral()
	flatDir{
    	dirs 'libs'
	}
}

dependencies {
	implementation(name:'frequency-android-sdk-3.1.4-release', ext:'aar')
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.8'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.8'
}

Samples

 

The following samples code snippets are used to show how to walk the Frequency data model from Categories down to the Videos to play.

 

Authenticate
new StartUpWebService().execute();

public class StartUpWebService extends AsyncTask<Void, Void, Boolean> {
    protected Boolean doInBackground(Void... void) {
        try {
            WebService webService = WebService.getInstance();
            webService.startUp(new Device("YOUR_SDK_KEY","YOUR_APP_NAME"));
        } catch (APIException e) {
            Log.e("WebService authentication failed", e.getMessage(), e);
            return false;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return true;
    }

    protected void onProgressUpdate(Void... voids) {
    }

    protected void onPostExecute(Boolean success) {
        super.onPostExecute(success);
        // AUTHENTICATION SUCCESSFULL
    }
}

The following samples code snippets are used to show how to walk the Frequency data model from Categories down to the Videos to play.


 

Get Categories
/**The Get Categories sample shows how to use the WebService to get a list of category objects. 
The category objects are received asynchronously in the onPostExecute method.
 **/
new FetchCategories().execute();

private class FetchCategories extends AsyncTask> {
    protected List doInBackground(Void... voids) {
        List categories;
        try{
            categories = Guide.getCategories(10, new Page(), null, null, Category.ImageSize._default);
        }catch (APIException e){
            Log.e("FetchCategories",e.getMessage(),e);
            return null;
        }
        return categories;
    }

    protected void onProgressUpdate(Void... voids) {
    }

    protected void onPostExecute(List categories) {
        super.onPostExecute(categories);
        // At this point you have been passed the list of Categories
    }
}

Get Channels

The Get Channels sample takes the next step, it uses a category from the Get Category sample to find the channels for the category. As in the categories sample the list of Channel objects are made available through the onPostExecute method. You can specify the maximum number of channels you want returned. If the maximum number of results is inferior to what is available the Page object is send withGuide.getChannelsNext(page) and it will return the next page of result.

 

 

Get Categories
new FetchChannels().execute(categories[0]);

private class FetchChannels extends AsyncTask> {
    protected List doInBackground(Category... category) {
        List channels;
        try{
            Page page = new Page();
            int maxResults = 30;
            channels = Guide.getChannels(category[0],maxResults,page);
        }catch (APIException e){
            Log.e("FetchChannels",e.getErrorMessage(),e);
            return null;
        }
        return channels;
    }

    protected void onProgressUpdate(Void... voids) {
    }

    protected void onPostExecute(List channels) {
        super.onPostExecute(channels);
        // At this point you have been passed the list of Channels
    }
}

 



Play a List of Videos

The final step in getting a list of videos is shown in the Play a List of Videos sample. In this sample a Channel object returned with the Get Channels sample is used to get the videos for the channel. The complete list of Video objects that is returned by the call is passed to the player for it to sequence through. If the developer wishes to have more fine grained control over the video play sequence they could pass the list of Video objects off to a UI list or other control where the Video objects would be passed one at a time when they are ready to be played.

The following example shows how to get the first and second page of videos for a given channel.

 

Get Categories
Page currentVideoPage = new Page();

new FetchVideos().execute(channels[0]);

new FetchMoreVideos().execute(currentVideoPage);

private class FetchVideos extends AsyncTask<Channel, Void, List<Video>> {
    protected List<Video> doInBackground(Channel... channel) {
        List<Video> videos;
        try{
            int maxResults = 30;
            videos = Guide.getVideos(channel[0],maxResults,currentVideoPage);
        }catch (APIException e){
            Log.e("FetchVideos",e.getErrorMessage(),e);
            return null;
        }
        return videos;
    }

    protected void onProgressUpdate(Void... voids) {
    }

    protected void onPostExecute(List<Video> videos) {
        super.onPostExecute(videos);
        // At this point you have been passed the list of Videos
    }
}

private class FetchMoreVideos extends AsyncTask<Page, Void, List<Video>> {
    protected List<Video> doInBackground(Page... page) {
        List<Video> videos;
        try{
            videos = Guide.getVideosNext(channel[0],page[0]);
        }catch (APIException e){
            Log.e("FetchVideos",e.getErrorMessage(),e);
            return null;
        }
        return videos;
    }

    protected void onProgressUpdate(Void... voids) {
    }

    protected void onPostExecute(List<Video> videos) {
        super.onPostExecute(videos);
// At this point you have been passed the list of Videos
    }
}

Android Player SDK

To play a video with the Android Player SDK.
Add the FrequencyPlayerView to your layout

 

playerLayout
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/fragment_holder"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <com.frequency.android.sdk.playback.FrequencyPlayerView
            android:id="@+id/player"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_gravity="center"
            android:background="#000000" />

</RelativeLayout>

Then in your Activity or Fragment

playing a video
FrequencyPlayerView frequencyPlayerView = (FrequencyPlayerView) findViewById(R.id.player);
Video video = videos[0]; // Fetch the videos using the snippet define in Play a List of Videos 

// in your Activity or Fragment implementing PlayerEventListener
frequencyPlayerView.initialize(this,
		"https://prd-freq.frequency.com", 					// the url of the API used
		"{YOUR_ACCESS_TOKEN}",								// token obtained by on /auth/device or /auth/session from the API specified above
		"{YOUR_DEVICE_ID}",									// device_id obtained by on /auth/device or /auth/session from the API specified above
		new ConvivaConfig("gateway_url","customer_key"), 	// optional
		new AdsConfig("https://prd-freq.frequency.com"), 	// optional but requiered for ads
		this); 												// optional PlayerEventListener

frequencyPlayerView.loadVideo(video.videoId, true);
  • No labels