Using Delivery Rules with the Native SDKs

In this topic, you will learn how to use Brightcove's Delivery Rules with the Native SDKs.

Introduction

Brightcove's Delivery Rules allows you to leverage the just-in-time manifest generation capability to use custom rules to control how your content is delivered to the viewer.

For more details about Delivery Rules, see the following:

Android implementation

To use Delivery Rules with the Native SDK for Android, follow these steps:

  1. Define the parameter for your Delivery Rules ID.
  2. Create the HttpRequestConfig with the delivery rule that you want applied. Pass a String value for your config_id, using the HttpRequestConfig.KEY_DELIVERY_RULE_CONFIG_ID parameter.
  3. Pass the Delivery Rules ID as a parameter with the catalog call to the Playback API. You can use either the findVideoByID or findPlaylistByID methods. Here is the code:

    public class MainActivity extends BrightcovePlayer {
    
        private final String TAG = this.getClass().getSimpleName();
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // Assign the brightcoveVideoView before entering the superclass.
            // This allows for video player lifecycle management.
            setContentView(R.layout.activity_main);
            brightcoveVideoView = (BrightcoveExoPlayerVideoView) findViewById(R.id.brightcove_video_view);
            super.onCreate(savedInstanceState);
    
            // Get the event emitter from the SDK for notifications and logging
            EventEmitter eventEmitter = brightcoveVideoView.getEventEmitter();
    
            // Create a catalog request to retrieve a video from your Video Cloud library
            Catalog catalog = new Catalog(eventEmitter,
                    getString(R.string.account),
                    getString(R.string.policy));
    
            // Create HttpRequestConfig with the delivery rule you want to be applied.
            // Use the HttpRequestConfig.KEY_DELIVERY_RULE_CONFIG_ID with a String value for config_id
            HttpRequestConfig httpRequestConfig = new HttpRequestConfig.Builder()
                    .addQueryParameter(HttpRequestConfig.KEY_DELIVERY_RULE_CONFIG_ID, "your rules id")
                    .build();
    
            // Add the HttpRequestConfig to the catalog request.
            catalog.findVideoByID(getString(R.string.videoId), httpRequestConfig, 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();
                }
            });
        }
    }

iOS implementation

To use Delivery Rules with the Native SDK for iOS, follow these steps:

  1. Define the parameter for your Delivery Rules ID.
  2. Pass the Delivery Rules ID as a parameter with the catalog call to the Playback API. You can use either the findVideoWithVideoID or findPlaylistWithPlaylistID methods. Here is the code:

    - (void)requestContentFromPlaybackService
    {
        NSDictionary *playbackAPIParameters = @{@"config_id":@"your rules id"};
        [self.playbackService findVideoWithVideoID:kViewControllerVideoID
            parameters:playbackAPIParameters
            completion:^(BCOVVideo *video, NSDictionary *jsonResponse, NSError *error) {
    
            if (video)
            {
                [self.playbackController setVideos:@[ video ]];
            }
            else
            {
                NSLog(@"ViewController Debug - Error retrieving video playlist: `%@`", error);
            }
        }];
    }