/** * Constructs the {@link MediaCodecWrapper} wrapper object around the video codec. The codec is * created using the encapsulated information in the {@link MediaFormat} object. * * @param trackFormat The format of the media object to be decoded. * @param surface Surface to render the decoded frames. * @return */ public static MediaCodecWrapper fromVideoFormat(final MediaFormat trackFormat, Surface surface) { MediaCodecWrapper result = null; MediaCodec videoCodec = null; // BEGIN_INCLUDE(create_codec) final String mimeType = trackFormat.getString(MediaFormat.KEY_MIME); // Check to see if this is actually a video mime type. If it is, then create // a codec that can decode this mime type. if (mimeType.contains("video/")) { try { videoCodec = MediaCodec.createDecoderByType(mimeType); videoCodec.configure(trackFormat, surface, null, 0); } catch (Exception e) { } } // If codec creation was successful, then create a wrapper object around the // newly created codec. if (videoCodec != null) { result = new MediaCodecWrapper(videoCodec); } // END_INCLUDE(create_codec) return result; }