Example usage for android.media MediaDrm KEY_TYPE_STREAMING

List of usage examples for android.media MediaDrm KEY_TYPE_STREAMING

Introduction

In this page you can find the example usage for android.media MediaDrm KEY_TYPE_STREAMING.

Prototype

int KEY_TYPE_STREAMING

To view the source code for android.media MediaDrm KEY_TYPE_STREAMING.

Click Source Link

Document

This key request type species that the keys will be for online use, they will not be saved to the device for subsequent use when the device is not connected to a network.

Usage

From source file:org.chromium.media.MediaDrmBridge.java

/**
 * Generate a key request and post an asynchronous task to the native side
 * with the response message./*from w w  w  .j  a  va2s .com*/
 *
 * @param initData Data needed to generate the key request.
 * @param mime Mime type.
 */
@CalledByNative
private void generateKeyRequest(byte[] initData, String mime) {
    Log.d(TAG, "generateKeyRequest().");

    if (mMimeType == null) {
        mMimeType = mime;
    } else if (!mMimeType.equals(mime)) {
        onKeyError();
        return;
    }

    if (mSessionId == null) {
        if (!openSession()) {
            onKeyError();
            return;
        }

        // NotProvisionedException happened during openSession().
        if (mSessionId == null) {
            if (mPendingInitData != null) {
                Log.e(TAG, "generateKeyRequest called when another call is pending.");
                onKeyError();
                return;
            }

            // We assume MediaDrm.EVENT_PROVISION_REQUIRED is always fired if
            // NotProvisionedException is throwed in openSession().
            // generateKeyRequest() will be resumed after provisioning is finished.
            // TODO(xhwang): Double check if this assumption is true. Otherwise we need
            // to handle the exception in openSession more carefully.
            mPendingInitData = initData;
            return;
        }
    }

    try {
        final byte[] session = mSessionId.getBytes("UTF-8");
        HashMap<String, String> optionalParameters = new HashMap<String, String>();
        final MediaDrm.KeyRequest request = mMediaDrm.getKeyRequest(session, initData, mime,
                MediaDrm.KEY_TYPE_STREAMING, optionalParameters);
        mHandler.post(new Runnable() {
            public void run() {
                nativeOnKeyMessage(mNativeMediaDrmBridge, mSessionId, request.getData(),
                        request.getDefaultUrl());
            }
        });
        return;
    } catch (android.media.NotProvisionedException e) {
        // MediaDrm.EVENT_PROVISION_REQUIRED is also fired in this case.
        // Provisioning is handled in the handler of that event.
        Log.e(TAG, "Cannot get key request: " + e.toString());
        return;
    } catch (java.io.UnsupportedEncodingException e) {
        Log.e(TAG, "Cannot get key request: " + e.toString());
    }
    onKeyError();
}