Working with Media Content

The page you are looking for doesn't live here anymore -- redirecting you to in 3 seconds.

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. Perform 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

The Playback API is the latest and recommended API to use to retrieve your video and playlist data from your Video Cloud library. For details, see the Playback API Documentation.

  1. Use the com.brightcove.player.edge.Catalog class to retrieve your videos and playlists from Brightcove's Playback API. This component's methods allow retrieval of videos and playlists by ID and/or ReferenceID. This service will make the URL requests and parse the returned data.
  2. For this option, you will need Policy Key. If you are not familiar with Policy Keys, see Policy API Overview.

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.
 *
 * @author Billy Hnath (bhnath@brightcove.com)
 */
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();
            }
        });
    }
}

Geo-restricted videos

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

There are two ways you can add geo-restrictions 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-restricted 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 }

Perform customers

As a Perform 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.media.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.