Example usage for android.media MediaExtractor getPsshInfo

List of usage examples for android.media MediaExtractor getPsshInfo

Introduction

In this page you can find the example usage for android.media MediaExtractor getPsshInfo.

Prototype

@Nullable
public Map<UUID, byte[]> getPsshInfo() 

Source Link

Document

Get the PSSH info if present.

Usage

From source file:com.nagravision.mediaplayer.FullscreenActivity.java

/**
 *
 *///ww  w  .  j  a  v a 2 s  . co  m
@SuppressWarnings("unused")
private void ClickItem(int position, int msec) {
    Log.v(LOG_TAG, "FullscreenActivity::ClickItem - Enter\n");

    /* Close the drawer */
    mDrawer.closeDrawers();

    /* Build the notification we are going to display */
    mNotifBuilder.setContentText(getResources().getString(R.string.playing_notification));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    (new PrintWriter(baos)).format(getResources().getString(R.string.long_playing_notification),
            MOVIES_ARR[position]);
    mNotifBuilder.setContentInfo(baos.toString());
    mNotifBuilder.setContentTitle(getResources().getString(R.string.app_name));
    mNotifBuilder.setSubText(getResources().getString(R.string.app_copyright));
    mNotifBuilder.setSmallIcon(R.drawable.ic_action_play);
    mExplicitIntent.setData(Uri.parse(MOVIES_URLS[position]));
    mNotifBuilder.setContentIntent(mDefaultIntent);
    mNotifBuilder.addAction(R.drawable.ic_action_about,
            getResources().getString(R.string.infos_action_description), mInfosIntent);

    /* If a notif was already sent, cancel it */
    if (mLastNotif != null) {
        if (mLastPosition != -1) {
            mNotifMgr.cancel(getResources().getString(R.string.playing_notification), mLastPosition);
            mLastPosition = -1;
        } else
            mNotifMgr.cancelAll();
        mLastNotif = null;
    }
    mLastNotif = mNotifBuilder.build();
    mLastPosition = position;

    if (false && MOVIES_MDTA[position].contains("drm")) {
        Log.d(LOG_TAG, "Starting extraction of Media Metadata\n");
        MediaExtractor extractor = new MediaExtractor();
        try {
            Log.d(LOG_TAG, "URL: " + MOVIES_URLS[position]);
            extractor.setDataSource(MOVIES_URLS[position]);
            int numTracks = extractor.getTrackCount();
            Log.v(LOG_TAG, "Number of tracks: " + numTracks);
            for (int i = 0; i < numTracks; ++i) {
                MediaFormat format = extractor.getTrackFormat(i);
                String mime = format.getString(MediaFormat.KEY_MIME);
                Log.v(LOG_TAG, "Track[" + i + "].mime = " + mime);
                if (mime.equals("video/avc")) {
                    extractor.selectTrack(i);
                    //                        byte[] key = new byte[16];
                    //                        key[0] = (byte) 0x7f; key[1] = (byte) 0x99; key[2] = (byte) 0x06; key[3] = (byte) 0x95;
                    //                        key[4] = (byte) 0x78; key[5] = (byte) 0xab; key[6] = (byte) 0x4d; key[7] = (byte) 0xae;
                    //                        key[8] = (byte) 0x8d; key[9] = (byte) 0x6c; key[10] = (byte) 0xe2; key[11] = (byte) 0x4c;
                    //                        key[12] = (byte) 0xc3; key[13] = (byte) 0x21; key[14] = (byte) 0x02; key[15] = (byte) 0x32;
                    MediaCrypto mediaCrypto;
                    MediaCodec codec = MediaCodec.createDecoderByType("video/avc");
                    Map<UUID, byte[]> psshInfo = extractor.getPsshInfo();
                    for (Iterator<UUID> it = psshInfo.keySet().iterator(); it.hasNext();) {
                        UUID uuid = it.next();
                        String psshData = new String(psshInfo.get(uuid));
                        Log.v(LOG_TAG, "PSSH for UUID: " + uuid.toString() + " has data :" + psshData);
                        try {
                            mediaCrypto = new MediaCrypto(uuid, psshInfo.get(uuid));
                            codec.configure(format, mVideoHolder.getHolder().getSurface(), mediaCrypto, 0);
                            codec.start();
                            @SuppressWarnings("unused")
                            ByteBuffer[] inputBuffers = codec.getInputBuffers();
                            @SuppressWarnings("unused")
                            ByteBuffer[] outputBuffers = codec.getOutputBuffers();
                            for (;;) {
                                int inputBufferIndex = codec.dequeueInputBuffer(200000);
                                if (inputBufferIndex >= 0) {
                                    //extractor.readSampleData();
                                    Log.v(LOG_TAG,
                                            "Read data from extractor (and crypto) and provide to decoder\n");
                                }
                            }
                        } catch (MediaCryptoException mce) {
                            Log.e(LOG_TAG, "Could not instanciate MediaCrypto ! " + mce);
                        }
                    }
                }
            }
        } catch (IOException ioe) {
            Log.e(LOG_TAG, "Cannot access URL: " + ioe);
        }
    }

    /* Setup media player for playing the movie */
    mVideoHolder.setVideoURI(Uri.parse(MOVIES_URLS[position]));
    mVideoHolder.requestFocus();
    mVideoHolder.start();

    if (msec > 0) {
        if (mVideoHolder.canPause())
            mVideoHolder.pause();
        mVideoHolder.seekTo(msec);
        if (mVideoHolder.canPause())
            mVideoHolder.resume();
    }

    /* Player has started ... send notification */
    mNotifMgr.notify(getResources().getString(R.string.playing_notification), mLastPosition, mLastNotif);
}