Android: Working with Media Content

Product(s)
Video Cloud
Role(s)
Device SDK Developer
Task(s)
Manage Videos
Topic(s)
Geo Restriction
Player/Video Availability
API(s)
Playback API
SDK
Get Started
Android

In this topic, you will learn how to retrieve and play your videos using the Native SDK for Android.

Overview

Video Cloud customers have access to their media data and metadata from Video Cloud Studio. Brightcove Player customers will supply the URL for their media content.

Video Cloud customers

As a Video Cloud customer, you can access your media data stored in Video Cloud Studio. For more information, see the Player SDK for Android code samples.

Retrieving media data

You can retrieve your video and playlist data from your Video Cloud library by using the Playback API. For details about the API, see the Playback API Overview document.

  1. Use the com.brightcove.player.edge.Catalog class methods to retrieve your videos and playlists from Brightcove's Playback API. Your requests can supply the video/playlist ID or ReferenceID. This service will make the URL requests and parse the returned data.
  2. For this request, you will need a Policy Key. If you are not familiar with Policy Keys, see the Policy API Overview document.

    Here is an example of how to retrieve a video using the com.brightcove.player.edge.Catalog class:

    package com.brightcove.player.samples.exoplayer.basic;
    import android.os.Bundle;
    import android.util.Log;
    import com.brightcove.player.edge.Catalog;
    import com.brightcove.player.edge.VideoListener;
    import com.brightcove.player.event.EventEmitter;
    import com.brightcove.player.model.Video;
    import com.brightcove.player.view.BrightcoveExoPlayerVideoView;
    import com.brightcove.player.view.BrightcovePlayer;
    /**
    * This app illustrates how to use the ExoPlayer with the Brightcove
    * Native Player SDK for Android.
    */
    public class MainActivity extends BrightcovePlayer {
    	private final String TAG = this.getClass().getSimpleName();
    	@Override
    
    	protected void onCreate(Bundle savedInstanceState) {
    		setContentView(R.layout.activity_main);
    		brightcoveVideoView = (BrightcoveExoPlayerVideoView) findViewById(R.id.brightcove_video_view);
    		super.onCreate(savedInstanceState);
    
    		// Get the event emitter from the SDK and create a catalog request to fetch a video from the
    		// Brightcove Edge service, given a video id, an account id and a policy key.
    		EventEmitter eventEmitter = brightcoveVideoView.getEventEmitter();
    		Catalog catalog = new Catalog(eventEmitter, getString(R.string.account), getString(R.string.policy));
    
    		catalog.findVideoByID(getString(R.string.videoId), new VideoListener() {
    		  // Add the video found to the queue with add().
    		  // Start playback of the video with start().
    		  @Override
    		  public void onVideo(Video video) {
    		    Log.v(TAG, "onVideo: video = " + video);
    		    brightcoveVideoView.add(video);
    		    brightcoveVideoView.start();
    		  }
    		});
    	}
    }
  1. The Video object provides methods to retrieve media information as shown below:
    catalog.findVideoByID(getString(R.string.videoId), new VideoListener() {
      // Add the video found to the queue with add().
      // Start playback of the video with start().
      @
      Override
      public void onVideo(Video video) {
        Log.v(TAG, "onVideo: video = " + video);
        Log.v(TAG, "onVideo: videoID = " + video.getId());
        Log.v(TAG, "onVideo: videoName = " + video.getName());
        Log.v(TAG, "onVideo: videoDescription = " + video.getDescription());
        Log.v(TAG, "onVideo: videoImage = " + video.getStillImageUri());
        Log.v(TAG, "onVideo: sourceCollections = " + video.getSourceCollections());
        SourceCollection dashCollection = video.getSourceCollections().get(DeliveryType.DASH);
        if (dashCollection != null) {
          Set < Source > sources = dashCollection.getSources();
          for (Source source: sources) {
            if (!TextUtils.isEmpty(source.getUrl())) {
              Log.v(TAG, "onVideo: DASH source = " + source.getUrl());
            }
          }
        }
    
        brightcoveVideoView.add(video);
        brightcoveVideoView.start();
      }
    });

    The above Log() methods return the following media information:

    Video object
    Video object

Geo-filtered videos

The Brightcove Player SDK for Android supports geo-filtered videos.

There are two ways you can add geo-filtering to your videos to control which countries they can (or cannot) be viewed in:

In your Android app, when you retrieve a video using Brightcove's edge Catalog object (Playback API) in a country which is geo-filtered for that video, you should see this message:

error { message: Access to this resource is forbidden by access policy.
client_geo: us
error_subcode: CLIENT_GEO
error_code: ACCESS_DENIED }

Brightcove Player customers

As a Brightcove Player customer, you will supply the URL for your video assets.

Here is an example of adding a video to your video view and starting playback:

import com.brightcove.player.model.DeliveryType;
import com.brightcove.player.model.Video;
import com.brightcove.player.view.BrightcoveExoPlayerVideoView;
import com.brightcove.player.view.BrightcovePlayer;
import com.brightcove.player.analytics.Analytics;
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	BrightcoveVideoView brightcoveVideoView = (BrightcoveVideoView) findViewById(R.id.brightcove_video_view);

	Analytics analytics = brightcoveVideoView.getAnalytics();
	analytics.setAccount("123456789");

	MediaController controller = new MediaController(this);
	brightcoveVideoView.setMediaController(controller);
	brightcoveVideoView.add(Video.createVideo("http://solutions.brightcove.com/bcls/assets/videos/Bird_Titmouse.mp4", DeliveryType.MP4));
	brightcoveVideoView.start();
}
 

Next, let's take a look at how events work within the SDK architecture.