diff --git a/BasicMediaDecoder/.google/packaging.yaml b/BasicMediaDecoder/.google/packaging.yaml deleted file mode 100644 index fd4e2f9..0000000 --- a/BasicMediaDecoder/.google/packaging.yaml +++ /dev/null @@ -1,19 +0,0 @@ - -# GOOGLE SAMPLE PACKAGING DATA -# -# This file is used by Google as part of our samples packaging process. -# End users may safely ignore this file. It has no relevance to other systems. ---- -status: PUBLISHED -technologies: [Android] -categories: [Media] -languages: [Java] -solutions: [Mobile] -github: android/media -level: ADVANCED -icon: screenshots/icon-web.png -apiRefs: - - android:android.media.MediaCodec - - android:android.media.MediaExtractor - - android:android.animation.TimeAnimator -license: apache2 diff --git a/BasicMediaDecoder/Application/build.gradle b/BasicMediaDecoder/Application/build.gradle deleted file mode 100644 index 836362c..0000000 --- a/BasicMediaDecoder/Application/build.gradle +++ /dev/null @@ -1,68 +0,0 @@ - -buildscript { - repositories { - google() - jcenter() - } - - dependencies { - classpath 'com.android.tools.build:gradle:3.5.0' - } -} - -apply plugin: 'com.android.application' - -repositories { - google() - jcenter() -} - -dependencies { - - - implementation "com.android.support:support-v4:28.0.0" - implementation "com.android.support:support-v13:28.0.0" - implementation "com.android.support:cardview-v7:28.0.0" - implementation "com.android.support:appcompat-v7:28.0.0" - - - - - - -} - -// The sample build uses multiple directories to -// keep boilerplate and common code separate from -// the main sample code. -List dirs = [ - 'main', // main sample code; look here for the interesting stuff. - 'common', // components that are reused by multiple samples - 'template'] // boilerplate code that is generated by the sample template process - -android { - compileSdkVersion 28 - - defaultConfig { - minSdkVersion 17 - targetSdkVersion 28 - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_7 - targetCompatibility JavaVersion.VERSION_1_7 - } - - sourceSets { - main { - dirs.each { dir -> - java.srcDirs "src/${dir}/java" - res.srcDirs "src/${dir}/res" - } - } - androidTest.setRoot('tests') - androidTest.java.srcDirs = ['tests/src'] - - } - -} diff --git a/BasicMediaDecoder/Application/src/main/AndroidManifest.xml b/BasicMediaDecoder/Application/src/main/AndroidManifest.xml deleted file mode 100644 index 02a674e..0000000 --- a/BasicMediaDecoder/Application/src/main/AndroidManifest.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/BasicMediaDecoder/Application/src/main/java/com/example/android/basicmediadecoder/MainActivity.java b/BasicMediaDecoder/Application/src/main/java/com/example/android/basicmediadecoder/MainActivity.java deleted file mode 100644 index 2c43a1e..0000000 --- a/BasicMediaDecoder/Application/src/main/java/com/example/android/basicmediadecoder/MainActivity.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.android.basicmediadecoder; - - -import android.animation.TimeAnimator; -import android.app.Activity; -import android.media.MediaCodec; -import android.media.MediaExtractor; -import android.net.Uri; -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.Surface; -import android.view.TextureView; -import android.view.View; -import android.widget.TextView; - -import com.example.android.common.media.MediaCodecWrapper; - -import java.io.IOException; - -/** - * This activity uses a {@link android.view.TextureView} to render the frames of a video decoded using - * {@link android.media.MediaCodec} API. - */ -public class MainActivity extends Activity { - - private TextureView mPlaybackView; - private TimeAnimator mTimeAnimator = new TimeAnimator(); - - // A utility that wraps up the underlying input and output buffer processing operations - // into an east to use API. - private MediaCodecWrapper mCodecWrapper; - private MediaExtractor mExtractor = new MediaExtractor(); - TextView mAttribView = null; - - - /** - * Called when the activity is first created. - */ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.sample_main); - mPlaybackView = (TextureView) findViewById(R.id.PlaybackView); - mAttribView = (TextView)findViewById(R.id.AttribView); - - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.action_menu, menu); - return true; - } - - @Override - protected void onPause() { - super.onPause(); - if(mTimeAnimator != null && mTimeAnimator.isRunning()) { - mTimeAnimator.end(); - } - - if (mCodecWrapper != null ) { - mCodecWrapper.stopAndRelease(); - mExtractor.release(); - } - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == R.id.menu_play) { - mAttribView.setVisibility(View.VISIBLE); - startPlayback(); - item.setEnabled(false); - } - return true; - } - - - public void startPlayback() { - - // Construct a URI that points to the video resource that we want to play - Uri videoUri = Uri.parse("android.resource://" - + getPackageName() + "/" - + R.raw.vid_bigbuckbunny); - - try { - - // BEGIN_INCLUDE(initialize_extractor) - mExtractor.setDataSource(this, videoUri, null); - int nTracks = mExtractor.getTrackCount(); - - // Begin by unselecting all of the tracks in the extractor, so we won't see - // any tracks that we haven't explicitly selected. - for (int i = 0; i < nTracks; ++i) { - mExtractor.unselectTrack(i); - } - - - // Find the first video track in the stream. In a real-world application - // it's possible that the stream would contain multiple tracks, but this - // sample assumes that we just want to play the first one. - for (int i = 0; i < nTracks; ++i) { - // Try to create a video codec for this track. This call will return null if the - // track is not a video track, or not a recognized video format. Once it returns - // a valid MediaCodecWrapper, we can break out of the loop. - mCodecWrapper = MediaCodecWrapper.fromVideoFormat(mExtractor.getTrackFormat(i), - new Surface(mPlaybackView.getSurfaceTexture())); - if (mCodecWrapper != null) { - mExtractor.selectTrack(i); - break; - } - } - // END_INCLUDE(initialize_extractor) - - - - - // By using a {@link TimeAnimator}, we can sync our media rendering commands with - // the system display frame rendering. The animator ticks as the {@link Choreographer} - // receives VSYNC events. - mTimeAnimator.setTimeListener(new TimeAnimator.TimeListener() { - @Override - public void onTimeUpdate(final TimeAnimator animation, - final long totalTime, - final long deltaTime) { - - boolean isEos = ((mExtractor.getSampleFlags() & MediaCodec - .BUFFER_FLAG_END_OF_STREAM) == MediaCodec.BUFFER_FLAG_END_OF_STREAM); - - // BEGIN_INCLUDE(write_sample) - if (!isEos) { - // Try to submit the sample to the codec and if successful advance the - // extractor to the next available sample to read. - boolean result = mCodecWrapper.writeSample(mExtractor, false, - mExtractor.getSampleTime(), mExtractor.getSampleFlags()); - - if (result) { - // Advancing the extractor is a blocking operation and it MUST be - // executed outside the main thread in real applications. - mExtractor.advance(); - } - } - // END_INCLUDE(write_sample) - - // Examine the sample at the head of the queue to see if its ready to be - // rendered and is not zero sized End-of-Stream record. - MediaCodec.BufferInfo out_bufferInfo = new MediaCodec.BufferInfo(); - mCodecWrapper.peekSample(out_bufferInfo); - - // BEGIN_INCLUDE(render_sample) - if (out_bufferInfo.size <= 0 && isEos) { - mTimeAnimator.end(); - mCodecWrapper.stopAndRelease(); - mExtractor.release(); - } else if (out_bufferInfo.presentationTimeUs / 1000 < totalTime) { - // Pop the sample off the queue and send it to {@link Surface} - mCodecWrapper.popSample(true); - } - // END_INCLUDE(render_sample) - - } - }); - - // We're all set. Kick off the animator to process buffers and render video frames as - // they become available - mTimeAnimator.start(); - } catch (IOException e) { - e.printStackTrace(); - } - } -} diff --git a/BasicMediaDecoder/Application/src/main/java/com/example/android/common/media/CameraHelper.java b/BasicMediaDecoder/Application/src/main/java/com/example/android/common/media/CameraHelper.java deleted file mode 100644 index daf9fc5..0000000 --- a/BasicMediaDecoder/Application/src/main/java/com/example/android/common/media/CameraHelper.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.android.common.media; - -import android.annotation.TargetApi; -import android.hardware.Camera; -import android.os.Build; -import android.os.Environment; -import android.util.Log; - -import java.io.File; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; -import java.util.Locale; - -/** - * Camera related utilities. - */ -public class CameraHelper { - - public static final int MEDIA_TYPE_IMAGE = 1; - public static final int MEDIA_TYPE_VIDEO = 2; - - /** - * Iterate over supported camera video sizes to see which one best fits the - * dimensions of the given view while maintaining the aspect ratio. If none can, - * be lenient with the aspect ratio. - * - * @param supportedVideoSizes Supported camera video sizes. - * @param previewSizes Supported camera preview sizes. - * @param w The width of the view. - * @param h The height of the view. - * @return Best match camera video size to fit in the view. - */ - public static Camera.Size getOptimalVideoSize(List supportedVideoSizes, - List previewSizes, int w, int h) { - // Use a very small tolerance because we want an exact match. - final double ASPECT_TOLERANCE = 0.1; - double targetRatio = (double) w / h; - - // Supported video sizes list might be null, it means that we are allowed to use the preview - // sizes - List videoSizes; - if (supportedVideoSizes != null) { - videoSizes = supportedVideoSizes; - } else { - videoSizes = previewSizes; - } - Camera.Size optimalSize = null; - - // Start with max value and refine as we iterate over available video sizes. This is the - // minimum difference between view and camera height. - double minDiff = Double.MAX_VALUE; - - // Target view height - int targetHeight = h; - - // Try to find a video size that matches aspect ratio and the target view size. - // Iterate over all available sizes and pick the largest size that can fit in the view and - // still maintain the aspect ratio. - for (Camera.Size size : videoSizes) { - double ratio = (double) size.width / size.height; - if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) - continue; - if (Math.abs(size.height - targetHeight) < minDiff && previewSizes.contains(size)) { - optimalSize = size; - minDiff = Math.abs(size.height - targetHeight); - } - } - - // Cannot find video size that matches the aspect ratio, ignore the requirement - if (optimalSize == null) { - minDiff = Double.MAX_VALUE; - for (Camera.Size size : videoSizes) { - if (Math.abs(size.height - targetHeight) < minDiff && previewSizes.contains(size)) { - optimalSize = size; - minDiff = Math.abs(size.height - targetHeight); - } - } - } - return optimalSize; - } - - /** - * @return the default camera on the device. Return null if there is no camera on the device. - */ - public static Camera getDefaultCameraInstance() { - return Camera.open(); - } - - - /** - * @return the default rear/back facing camera on the device. Returns null if camera is not - * available. - */ - public static Camera getDefaultBackFacingCameraInstance() { - return getDefaultCamera(Camera.CameraInfo.CAMERA_FACING_BACK); - } - - /** - * @return the default front facing camera on the device. Returns null if camera is not - * available. - */ - public static Camera getDefaultFrontFacingCameraInstance() { - return getDefaultCamera(Camera.CameraInfo.CAMERA_FACING_FRONT); - } - - - /** - * - * @param position Physical position of the camera i.e Camera.CameraInfo.CAMERA_FACING_FRONT - * or Camera.CameraInfo.CAMERA_FACING_BACK. - * @return the default camera on the device. Returns null if camera is not available. - */ - @TargetApi(Build.VERSION_CODES.GINGERBREAD) - private static Camera getDefaultCamera(int position) { - // Find the total number of cameras available - int mNumberOfCameras = Camera.getNumberOfCameras(); - - // Find the ID of the back-facing ("default") camera - Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); - for (int i = 0; i < mNumberOfCameras; i++) { - Camera.getCameraInfo(i, cameraInfo); - if (cameraInfo.facing == position) { - return Camera.open(i); - - } - } - - return null; - } - - /** - * Creates a media file in the {@code Environment.DIRECTORY_PICTURES} directory. The directory - * is persistent and available to other applications like gallery. - * - * @param type Media type. Can be video or image. - * @return A file object pointing to the newly created file. - */ - public static File getOutputMediaFile(int type){ - // To be safe, you should check that the SDCard is mounted - // using Environment.getExternalStorageState() before doing this. - if (!Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { - return null; - } - - File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory( - Environment.DIRECTORY_PICTURES), "CameraSample"); - // This location works best if you want the created images to be shared - // between applications and persist after your app has been uninstalled. - - // Create the storage directory if it does not exist - if (! mediaStorageDir.exists()){ - if (! mediaStorageDir.mkdirs()) { - Log.d("CameraSample", "failed to create directory"); - return null; - } - } - - // Create a media file name - String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date()); - File mediaFile; - if (type == MEDIA_TYPE_IMAGE){ - mediaFile = new File(mediaStorageDir.getPath() + File.separator + - "IMG_"+ timeStamp + ".jpg"); - } else if(type == MEDIA_TYPE_VIDEO) { - mediaFile = new File(mediaStorageDir.getPath() + File.separator + - "VID_"+ timeStamp + ".mp4"); - } else { - return null; - } - - return mediaFile; - } - -} diff --git a/BasicMediaDecoder/Application/src/main/java/com/example/android/common/media/MediaCodecWrapper.java b/BasicMediaDecoder/Application/src/main/java/com/example/android/common/media/MediaCodecWrapper.java deleted file mode 100644 index 5b69079..0000000 --- a/BasicMediaDecoder/Application/src/main/java/com/example/android/common/media/MediaCodecWrapper.java +++ /dev/null @@ -1,377 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.android.common.media; - -import android.media.*; -import android.os.Handler; -import android.os.Looper; -import android.view.Surface; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.ArrayDeque; -import java.util.Locale; -import java.util.Queue; - -/** - * Simplifies the MediaCodec interface by wrapping around the buffer processing operations. - */ -public class MediaCodecWrapper { - - // Handler to use for {@code OutputSampleListener} and {code OutputFormatChangedListener} - // callbacks - private Handler mHandler; - - - // Callback when media output format changes. - public interface OutputFormatChangedListener { - void outputFormatChanged(MediaCodecWrapper sender, MediaFormat newFormat); - } - - private OutputFormatChangedListener mOutputFormatChangedListener = null; - - /** - * Callback for decodes frames. Observers can register a listener for optional stream - * of decoded data - */ - public interface OutputSampleListener { - void outputSample(MediaCodecWrapper sender, MediaCodec.BufferInfo info, ByteBuffer buffer); - } - - /** - * The {@link MediaCodec} that is managed by this class. - */ - private MediaCodec mDecoder; - - // References to the internal buffers managed by the codec. The codec - // refers to these buffers by index, never by reference so it's up to us - // to keep track of which buffer is which. - private ByteBuffer[] mInputBuffers; - private ByteBuffer[] mOutputBuffers; - - // Indices of the input buffers that are currently available for writing. We'll - // consume these in the order they were dequeued from the codec. - private Queue mAvailableInputBuffers; - - // Indices of the output buffers that currently hold valid data, in the order - // they were produced by the codec. - private Queue mAvailableOutputBuffers; - - // Information about each output buffer, by index. Each entry in this array - // is valid if and only if its index is currently contained in mAvailableOutputBuffers. - private MediaCodec.BufferInfo[] mOutputBufferInfo; - - private MediaCodecWrapper(MediaCodec codec) { - mDecoder = codec; - codec.start(); - mInputBuffers = codec.getInputBuffers(); - mOutputBuffers = codec.getOutputBuffers(); - mOutputBufferInfo = new MediaCodec.BufferInfo[mOutputBuffers.length]; - mAvailableInputBuffers = new ArrayDeque<>(mOutputBuffers.length); - mAvailableOutputBuffers = new ArrayDeque<>(mInputBuffers.length); - } - - /** - * Releases resources and ends the encoding/decoding session. - */ - public void stopAndRelease() { - mDecoder.stop(); - mDecoder.release(); - mDecoder = null; - mHandler = null; - } - - /** - * Getter for the registered {@link OutputFormatChangedListener} - */ - public OutputFormatChangedListener getOutputFormatChangedListener() { - return mOutputFormatChangedListener; - } - - /** - * - * @param outputFormatChangedListener the listener for callback. - * @param handler message handler for posting the callback. - */ - public void setOutputFormatChangedListener(final OutputFormatChangedListener - outputFormatChangedListener, Handler handler) { - mOutputFormatChangedListener = outputFormatChangedListener; - - // Making sure we don't block ourselves due to a bad implementation of the callback by - // using a handler provided by client. - mHandler = handler; - if (outputFormatChangedListener != null && mHandler == null) { - if (Looper.myLooper() != null) { - mHandler = new Handler(); - } else { - throw new IllegalArgumentException( - "Looper doesn't exist in the calling thread"); - } - } - } - - /** - * 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) throws IOException { - 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/")) { - videoCodec = MediaCodec.createDecoderByType(mimeType); - videoCodec.configure(trackFormat, surface, null, 0); - - } - - // 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; - } - - - /** - * Write a media sample to the decoder. - * - * A "sample" here refers to a single atomic access unit in the media stream. The definition - * of "access unit" is dependent on the type of encoding used, but it typically refers to - * a single frame of video or a few seconds of audio. {@link android.media.MediaExtractor} - * extracts data from a stream one sample at a time. - * - * @param input A ByteBuffer containing the input data for one sample. The buffer must be set - * up for reading, with its position set to the beginning of the sample data and its limit - * set to the end of the sample data. - * - * @param presentationTimeUs The time, relative to the beginning of the media stream, - * at which this buffer should be rendered. - * - * @param flags Flags to pass to the decoder. See {@link MediaCodec#queueInputBuffer(int, - * int, int, long, int)} - * - * @throws MediaCodec.CryptoException - */ - public boolean writeSample(final ByteBuffer input, - final MediaCodec.CryptoInfo crypto, - final long presentationTimeUs, - final int flags) throws MediaCodec.CryptoException, WriteException { - boolean result = false; - int size = input.remaining(); - - // check if we have dequed input buffers available from the codec - if (size > 0 && !mAvailableInputBuffers.isEmpty()) { - int index = mAvailableInputBuffers.remove(); - ByteBuffer buffer = mInputBuffers[index]; - - // we can't write our sample to a lesser capacity input buffer. - if (size > buffer.capacity()) { - throw new MediaCodecWrapper.WriteException(String.format(Locale.US, - "Insufficient capacity in MediaCodec buffer: " - + "tried to write %d, buffer capacity is %d.", - input.remaining(), - buffer.capacity())); - } - - buffer.clear(); - buffer.put(input); - - // Submit the buffer to the codec for decoding. The presentationTimeUs - // indicates the position (play time) for the current sample. - if (crypto == null) { - mDecoder.queueInputBuffer(index, 0, size, presentationTimeUs, flags); - } else { - mDecoder.queueSecureInputBuffer(index, 0, crypto, presentationTimeUs, flags); - } - result = true; - } - return result; - } - - private static MediaCodec.CryptoInfo sCryptoInfo = new MediaCodec.CryptoInfo(); - - /** - * Write a media sample to the decoder. - * - * A "sample" here refers to a single atomic access unit in the media stream. The definition - * of "access unit" is dependent on the type of encoding used, but it typically refers to - * a single frame of video or a few seconds of audio. {@link android.media.MediaExtractor} - * extracts data from a stream one sample at a time. - * - * @param extractor Instance of {@link android.media.MediaExtractor} wrapping the media. - * - * @param presentationTimeUs The time, relative to the beginning of the media stream, - * at which this buffer should be rendered. - * - * @param flags Flags to pass to the decoder. See {@link MediaCodec#queueInputBuffer(int, - * int, int, long, int)} - * - * @throws MediaCodec.CryptoException - */ - public boolean writeSample(final MediaExtractor extractor, - final boolean isSecure, - final long presentationTimeUs, - int flags) { - boolean result = false; - - if (!mAvailableInputBuffers.isEmpty()) { - int index = mAvailableInputBuffers.remove(); - ByteBuffer buffer = mInputBuffers[index]; - - // reads the sample from the file using extractor into the buffer - int size = extractor.readSampleData(buffer, 0); - if (size <= 0) { - flags |= MediaCodec.BUFFER_FLAG_END_OF_STREAM; - } - - // Submit the buffer to the codec for decoding. The presentationTimeUs - // indicates the position (play time) for the current sample. - if (!isSecure) { - mDecoder.queueInputBuffer(index, 0, size, presentationTimeUs, flags); - } else { - extractor.getSampleCryptoInfo(sCryptoInfo); - mDecoder.queueSecureInputBuffer(index, 0, sCryptoInfo, presentationTimeUs, flags); - } - - result = true; - } - return result; - } - - /** - * Performs a peek() operation in the queue to extract media info for the buffer ready to be - * released i.e. the head element of the queue. - * - * @param out_bufferInfo An output var to hold the buffer info. - * - * @return True, if the peek was successful. - */ - public boolean peekSample(MediaCodec.BufferInfo out_bufferInfo) { - // dequeue available buffers and synchronize our data structures with the codec. - update(); - boolean result = false; - if (!mAvailableOutputBuffers.isEmpty()) { - int index = mAvailableOutputBuffers.peek(); - MediaCodec.BufferInfo info = mOutputBufferInfo[index]; - // metadata of the sample - out_bufferInfo.set( - info.offset, - info.size, - info.presentationTimeUs, - info.flags); - result = true; - } - return result; - } - - /** - * Processes, releases and optionally renders the output buffer available at the head of the - * queue. All observers are notified with a callback. See {@link - * OutputSampleListener#outputSample(MediaCodecWrapper, android.media.MediaCodec.BufferInfo, - * java.nio.ByteBuffer)} - * - * @param render True, if the buffer is to be rendered on the {@link Surface} configured - * - */ - public void popSample(boolean render) { - // dequeue available buffers and synchronize our data structures with the codec. - update(); - if (!mAvailableOutputBuffers.isEmpty()) { - int index = mAvailableOutputBuffers.remove(); - - // releases the buffer back to the codec - mDecoder.releaseOutputBuffer(index, render); - } - } - - /** - * Synchronize this object's state with the internal state of the wrapped - * MediaCodec. - */ - private void update() { - // BEGIN_INCLUDE(update_codec_state) - int index; - - // Get valid input buffers from the codec to fill later in the same order they were - // made available by the codec. - while ((index = mDecoder.dequeueInputBuffer(0)) != MediaCodec.INFO_TRY_AGAIN_LATER) { - mAvailableInputBuffers.add(index); - } - - - // Likewise with output buffers. If the output buffers have changed, start using the - // new set of output buffers. If the output format has changed, notify listeners. - MediaCodec.BufferInfo info = new MediaCodec.BufferInfo(); - while ((index = mDecoder.dequeueOutputBuffer(info, 0)) != MediaCodec.INFO_TRY_AGAIN_LATER) { - switch (index) { - case MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED: - mOutputBuffers = mDecoder.getOutputBuffers(); - mOutputBufferInfo = new MediaCodec.BufferInfo[mOutputBuffers.length]; - mAvailableOutputBuffers.clear(); - break; - case MediaCodec.INFO_OUTPUT_FORMAT_CHANGED: - if (mOutputFormatChangedListener != null) { - mHandler.post(new Runnable() { - @Override - public void run() { - mOutputFormatChangedListener - .outputFormatChanged(MediaCodecWrapper.this, - mDecoder.getOutputFormat()); - - } - }); - } - break; - default: - // Making sure the index is valid before adding to output buffers. We've already - // handled INFO_TRY_AGAIN_LATER, INFO_OUTPUT_FORMAT_CHANGED & - // INFO_OUTPUT_BUFFERS_CHANGED i.e all the other possible return codes but - // asserting index value anyways for future-proofing the code. - if (index >= 0) { - mOutputBufferInfo[index] = info; - mAvailableOutputBuffers.add(index); - } else { - throw new IllegalStateException("Unknown status from dequeueOutputBuffer"); - } - break; - } - - } - // END_INCLUDE(update_codec_state) - - } - - private class WriteException extends Throwable { - private WriteException(final String detailMessage) { - super(detailMessage); - } - } -} diff --git a/BasicMediaDecoder/Application/src/main/res/drawable-hdpi/ic_action_play.png b/BasicMediaDecoder/Application/src/main/res/drawable-hdpi/ic_action_play.png deleted file mode 100755 index dbfd337..0000000 Binary files a/BasicMediaDecoder/Application/src/main/res/drawable-hdpi/ic_action_play.png and /dev/null differ diff --git a/BasicMediaDecoder/Application/src/main/res/drawable-hdpi/ic_action_play_disabled.png b/BasicMediaDecoder/Application/src/main/res/drawable-hdpi/ic_action_play_disabled.png deleted file mode 100755 index e4310ef..0000000 Binary files a/BasicMediaDecoder/Application/src/main/res/drawable-hdpi/ic_action_play_disabled.png and /dev/null differ diff --git a/BasicMediaDecoder/Application/src/main/res/drawable-hdpi/ic_launcher.png b/BasicMediaDecoder/Application/src/main/res/drawable-hdpi/ic_launcher.png deleted file mode 100644 index 9bc536b..0000000 Binary files a/BasicMediaDecoder/Application/src/main/res/drawable-hdpi/ic_launcher.png and /dev/null differ diff --git a/BasicMediaDecoder/Application/src/main/res/drawable-hdpi/tile.9.png b/BasicMediaDecoder/Application/src/main/res/drawable-hdpi/tile.9.png deleted file mode 100644 index 1358628..0000000 Binary files a/BasicMediaDecoder/Application/src/main/res/drawable-hdpi/tile.9.png and /dev/null differ diff --git a/BasicMediaDecoder/Application/src/main/res/drawable-mdpi/ic_action_play.png b/BasicMediaDecoder/Application/src/main/res/drawable-mdpi/ic_action_play.png deleted file mode 100755 index a2f198a..0000000 Binary files a/BasicMediaDecoder/Application/src/main/res/drawable-mdpi/ic_action_play.png and /dev/null differ diff --git a/BasicMediaDecoder/Application/src/main/res/drawable-mdpi/ic_action_play_disabled.png b/BasicMediaDecoder/Application/src/main/res/drawable-mdpi/ic_action_play_disabled.png deleted file mode 100755 index d69107b..0000000 Binary files a/BasicMediaDecoder/Application/src/main/res/drawable-mdpi/ic_action_play_disabled.png and /dev/null differ diff --git a/BasicMediaDecoder/Application/src/main/res/drawable-mdpi/ic_launcher.png b/BasicMediaDecoder/Application/src/main/res/drawable-mdpi/ic_launcher.png deleted file mode 100644 index d656b21..0000000 Binary files a/BasicMediaDecoder/Application/src/main/res/drawable-mdpi/ic_launcher.png and /dev/null differ diff --git a/BasicMediaDecoder/Application/src/main/res/drawable-xhdpi/ic_action_play.png b/BasicMediaDecoder/Application/src/main/res/drawable-xhdpi/ic_action_play.png deleted file mode 100755 index 9e63c90..0000000 Binary files a/BasicMediaDecoder/Application/src/main/res/drawable-xhdpi/ic_action_play.png and /dev/null differ diff --git a/BasicMediaDecoder/Application/src/main/res/drawable-xhdpi/ic_action_play_disabled.png b/BasicMediaDecoder/Application/src/main/res/drawable-xhdpi/ic_action_play_disabled.png deleted file mode 100755 index 2ff8c39..0000000 Binary files a/BasicMediaDecoder/Application/src/main/res/drawable-xhdpi/ic_action_play_disabled.png and /dev/null differ diff --git a/BasicMediaDecoder/Application/src/main/res/drawable-xhdpi/ic_launcher.png b/BasicMediaDecoder/Application/src/main/res/drawable-xhdpi/ic_launcher.png deleted file mode 100644 index bbb9b16..0000000 Binary files a/BasicMediaDecoder/Application/src/main/res/drawable-xhdpi/ic_launcher.png and /dev/null differ diff --git a/BasicMediaDecoder/Application/src/main/res/drawable-xxhdpi/ic_launcher.png b/BasicMediaDecoder/Application/src/main/res/drawable-xxhdpi/ic_launcher.png deleted file mode 100644 index 4a5c33f..0000000 Binary files a/BasicMediaDecoder/Application/src/main/res/drawable-xxhdpi/ic_launcher.png and /dev/null differ diff --git a/BasicMediaDecoder/Application/src/main/res/drawable/selector_play.xml b/BasicMediaDecoder/Application/src/main/res/drawable/selector_play.xml deleted file mode 100644 index 2307135..0000000 --- a/BasicMediaDecoder/Application/src/main/res/drawable/selector_play.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/BasicMediaDecoder/Application/src/main/res/layout/sample_main.xml b/BasicMediaDecoder/Application/src/main/res/layout/sample_main.xml deleted file mode 100644 index 7543120..0000000 --- a/BasicMediaDecoder/Application/src/main/res/layout/sample_main.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - diff --git a/BasicMediaDecoder/Application/src/main/res/menu/action_menu.xml b/BasicMediaDecoder/Application/src/main/res/menu/action_menu.xml deleted file mode 100644 index 1568983..0000000 --- a/BasicMediaDecoder/Application/src/main/res/menu/action_menu.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - \ No newline at end of file diff --git a/BasicMediaDecoder/Application/src/main/res/raw/vid_bigbuckbunny.mp4 b/BasicMediaDecoder/Application/src/main/res/raw/vid_bigbuckbunny.mp4 deleted file mode 100644 index 81d11df..0000000 Binary files a/BasicMediaDecoder/Application/src/main/res/raw/vid_bigbuckbunny.mp4 and /dev/null differ diff --git a/BasicMediaDecoder/Application/src/main/res/values-sw600dp/template-dimens.xml b/BasicMediaDecoder/Application/src/main/res/values-sw600dp/template-dimens.xml deleted file mode 100644 index 22074a2..0000000 --- a/BasicMediaDecoder/Application/src/main/res/values-sw600dp/template-dimens.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - @dimen/margin_huge - @dimen/margin_medium - - diff --git a/BasicMediaDecoder/Application/src/main/res/values-sw600dp/template-styles.xml b/BasicMediaDecoder/Application/src/main/res/values-sw600dp/template-styles.xml deleted file mode 100644 index 03d1974..0000000 --- a/BasicMediaDecoder/Application/src/main/res/values-sw600dp/template-styles.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - diff --git a/BasicMediaDecoder/Application/src/main/res/values-v11/template-styles.xml b/BasicMediaDecoder/Application/src/main/res/values-v11/template-styles.xml deleted file mode 100644 index 8c1ea66..0000000 --- a/BasicMediaDecoder/Application/src/main/res/values-v11/template-styles.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - diff --git a/BasicMediaDecoder/Application/src/main/res/values/base-strings.xml b/BasicMediaDecoder/Application/src/main/res/values/base-strings.xml deleted file mode 100644 index e7a5351..0000000 --- a/BasicMediaDecoder/Application/src/main/res/values/base-strings.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - BasicMediaDecoder - - - - diff --git a/BasicMediaDecoder/Application/src/main/res/values/strings.xml b/BasicMediaDecoder/Application/src/main/res/values/strings.xml deleted file mode 100644 index 739bfbc..0000000 --- a/BasicMediaDecoder/Application/src/main/res/values/strings.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - © copyright 2008, Blender Foundation / www.bigbuckbunny.org - - Play - diff --git a/BasicMediaDecoder/Application/src/main/res/values/template-dimens.xml b/BasicMediaDecoder/Application/src/main/res/values/template-dimens.xml deleted file mode 100644 index 39e710b..0000000 --- a/BasicMediaDecoder/Application/src/main/res/values/template-dimens.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - 4dp - 8dp - 16dp - 32dp - 64dp - - - - @dimen/margin_medium - @dimen/margin_medium - - diff --git a/BasicMediaDecoder/Application/src/main/res/values/template-styles.xml b/BasicMediaDecoder/Application/src/main/res/values/template-styles.xml deleted file mode 100644 index 6e7d593..0000000 --- a/BasicMediaDecoder/Application/src/main/res/values/template-styles.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - diff --git a/BasicMediaDecoder/CONTRIB.md b/BasicMediaDecoder/CONTRIB.md deleted file mode 100644 index 14a4fcf..0000000 --- a/BasicMediaDecoder/CONTRIB.md +++ /dev/null @@ -1,35 +0,0 @@ -# How to become a contributor and submit your own code - -## Contributor License Agreements - -We'd love to accept your sample apps and patches! Before we can take them, we -have to jump a couple of legal hurdles. - -Please fill out either the individual or corporate Contributor License Agreement (CLA). - - * If you are an individual writing original source code and you're sure you - own the intellectual property, then you'll need to sign an [individual CLA] - (https://developers.google.com/open-source/cla/individual). - * If you work for a company that wants to allow you to contribute your work, - then you'll need to sign a [corporate CLA] - (https://developers.google.com/open-source/cla/corporate). - -Follow either of the two links above to access the appropriate CLA and -instructions for how to sign and return it. Once we receive it, we'll be able to -accept your pull requests. - -## Contributing A Patch - -1. Submit an issue describing your proposed change to the repo in question. -1. The repo owner will respond to your issue promptly. -1. If your proposed change is accepted, and you haven't already done so, sign a - Contributor License Agreement (see details above). -1. Fork the desired repo, develop and test your code changes. -1. Ensure that your code adheres to the existing style in the sample to which - you are contributing. Refer to the - [Android Code Style Guide] - (https://source.android.com/source/code-style.html) for the - recommended coding standards for this organization. -1. Ensure that your code has an appropriate set of unit tests which all pass. -1. Submit a pull request. - diff --git a/BasicMediaDecoder/README.md b/BasicMediaDecoder/README.md deleted file mode 100644 index 88bb5cf..0000000 --- a/BasicMediaDecoder/README.md +++ /dev/null @@ -1,81 +0,0 @@ - -Android BasicMediaDecoder Sample -================================ - -This sample shows how to use the MediaCoder to decode a video, -use a TimeAnimator to sync the rendering commands with the system -display frame rendering and finally render it to a TextureView. - -Introduction ------------- - -[MediaCodec][1] was introduced in API 16, and can be used for low level (decoding/encoding) operations. -In the same API was also introduced [TimeAnimator][2], which can be used to synchronise animation frames. -Finally, [MediaExtractor][3] provides a simple way to extract demuxed media data from a data source. - -The main steps are described below: - -1. Create a layout with a [TextureView][4] for your activity. -2. Initialise a MediaExtractor instance with `new MediaExtractor()` and a TimeAnimator instance with -`new TimeAnimator()`. -3. To start video playback, call `setDataSource(this, videoUri, null)` on your MediaExtractor instance, -where `videoUri` is the URI of your video source. -4. On your MediaExtractor instance, call `getTrackCount()` to know how many tracks you have in your streams. -They may not all be video tracks. Deselect all tracks by calling `unselectTrack(i)` where `i` is -the index of the track. -5. Get the mime type of a track by calling `getTrackFormat(i).getString(MediaFormat.KEY_MIME)` -on your MediaExtractor instance, where `i` is the index of your selected track. -If the mime type contains "video/", then this is a video track so you can select it, using `selectTrack(i)` -on your MediaExtractor instance. -6. Create a MediaCodec instance by calling `MediaCodec.createDecoderByType(mimeType)`. -7. Configure your MediaCodec instance with `configure(trackFormat, textureView, null, 0)`, -where `trackFormat` is obtained by calling `getTrackFormat(i)` on your MediaExtractor instance. -8. Set a TimeListener on your TimeAnimation instance, and override its `onTimeUpdate(final TimeAnimator animation, -final long totalTime, final long deltaTime)` method. -9. In `onTimeUpdate`, check if the media track has reached the end of stream, using `getSampleFlags()` -on your MediaExtractor instance and looking for `MediaCodec.BUFFER_FLAG_END_OF_STREAM` flag. -10. Still in `onTimeUpdate`, assuming this isn't the end of the sample, write the media sample to your -MediaDecoder instance, using `queueInputBuffer(index, 0, size, presentationTimeUs, flags)` method. -You will need to set up your buffers, refer to [MediaCodec][1] documentation for details. -11. After writing the media sample, you need to advance the sample, calling `advance()` on your -TimeExtractor instance (this is a blocking operation and should be done outside the main thread). -12. Finally, you can release and render the media sample by calling -`dequeueOutputBuffer(info, timeout)` and `releaseOutputBuffer(i, true)`, refer to [MediaCodec][1] -documentation for details. -13. In `onPause()` or if you have reached the end of the stream, call `end()` on your TimeAnimation instance, -then call `stop()` and `release()` on your MediaCodec instance, and finally, call `release()` on your -MediaExtractor instance. - -[1]: http://developer.android.com/reference/android/media/MediaCodec.html -[2]: http://developer.android.com/reference/android/animation/TimeAnimator.html -[3]: http://developer.android.com/reference/android/media/MediaExtractor.html -[4]: http://developer.android.com/reference/android/view/TextureView.html - -Pre-requisites --------------- - -- Android SDK 28 -- Android Build Tools v28.0.3 -- Android Support Repository - -Screenshots -------------- - -Screenshot Screenshot - -Getting Started ---------------- - -This sample uses the Gradle build system. To build this project, use the -"gradlew build" command or use "Import Project" in Android Studio. - -Support -------- - -- Stack Overflow: http://stackoverflow.com/questions/tagged/android - -If you've found an error in this sample, please file an issue: -https://github.com/android/media - -Patches are encouraged, and may be submitted by forking this project and -submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details. diff --git a/BasicMediaDecoder/gradle.properties b/BasicMediaDecoder/gradle.properties deleted file mode 100644 index 0bc4294..0000000 --- a/BasicMediaDecoder/gradle.properties +++ /dev/null @@ -1,20 +0,0 @@ - -# Project-wide Gradle settings. - -# IDE (e.g. Android Studio) users: -# Settings specified in this file will override any Gradle settings -# configured through the IDE. - -# For more details on how to configure your build environment visit -# http://www.gradle.org/docs/current/userguide/build_environment.html - -# Specifies the JVM arguments used for the daemon process. -# The setting is particularly useful for tweaking memory settings. -# Default value: -Xmx10248m -XX:MaxPermSize=256m -# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 - -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true - diff --git a/BasicMediaDecoder/gradle/wrapper/gradle-wrapper.jar b/BasicMediaDecoder/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 94336fc..0000000 Binary files a/BasicMediaDecoder/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/BasicMediaDecoder/gradle/wrapper/gradle-wrapper.properties b/BasicMediaDecoder/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 25be26f..0000000 --- a/BasicMediaDecoder/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Mon Sep 30 11:01:02 BST 2019 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip diff --git a/BasicMediaDecoder/gradlew b/BasicMediaDecoder/gradlew deleted file mode 100755 index cccdd3d..0000000 --- a/BasicMediaDecoder/gradlew +++ /dev/null @@ -1,172 +0,0 @@ -#!/usr/bin/env sh - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn () { - echo "$*" -} - -die () { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi - -exec "$JAVACMD" "$@" diff --git a/BasicMediaDecoder/gradlew.bat b/BasicMediaDecoder/gradlew.bat deleted file mode 100644 index e95643d..0000000 --- a/BasicMediaDecoder/gradlew.bat +++ /dev/null @@ -1,84 +0,0 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/BasicMediaDecoder/screenshots/1-launch.png b/BasicMediaDecoder/screenshots/1-launch.png deleted file mode 100644 index 87c246f..0000000 Binary files a/BasicMediaDecoder/screenshots/1-launch.png and /dev/null differ diff --git a/BasicMediaDecoder/screenshots/2-play-video.png b/BasicMediaDecoder/screenshots/2-play-video.png deleted file mode 100644 index 17f61fa..0000000 Binary files a/BasicMediaDecoder/screenshots/2-play-video.png and /dev/null differ diff --git a/BasicMediaDecoder/screenshots/icon-web.png b/BasicMediaDecoder/screenshots/icon-web.png deleted file mode 100644 index c67722e..0000000 Binary files a/BasicMediaDecoder/screenshots/icon-web.png and /dev/null differ diff --git a/BasicMediaDecoder/settings.gradle b/BasicMediaDecoder/settings.gradle deleted file mode 100644 index 9464a35..0000000 --- a/BasicMediaDecoder/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -include 'Application' diff --git a/BasicMediaRouter/.google/packaging.yaml b/BasicMediaRouter/.google/packaging.yaml deleted file mode 100644 index 2ea346c..0000000 --- a/BasicMediaRouter/.google/packaging.yaml +++ /dev/null @@ -1,13 +0,0 @@ - -# GOOGLE SAMPLE PACKAGING DATA -# -# This file is used by Google as part of our samples packaging process. -# End users may safely ignore this file. It has no relevance to other systems. ---- -status: PUBLISHED -technologies: [Android] -categories: [Media] -languages: [Java] -solutions: [Mobile] -github: android/media -license: apache2 diff --git a/BasicMediaRouter/Application/build.gradle b/BasicMediaRouter/Application/build.gradle deleted file mode 100644 index e9165da..0000000 --- a/BasicMediaRouter/Application/build.gradle +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2019 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -apply plugin: 'com.android.application' - -android { - compileSdkVersion 29 - - defaultConfig { - minSdkVersion 17 - targetSdkVersion 29 - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_7 - targetCompatibility JavaVersion.VERSION_1_7 - } -} - -dependencies { - implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'androidx.mediarouter:mediarouter:1.1.0' -} diff --git a/BasicMediaRouter/Application/src/main/AndroidManifest.xml b/BasicMediaRouter/Application/src/main/AndroidManifest.xml deleted file mode 100644 index 1261d5c..0000000 --- a/BasicMediaRouter/Application/src/main/AndroidManifest.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/BasicMediaRouter/Application/src/main/java/com/example/android/basicmediarouter/MainActivity.java b/BasicMediaRouter/Application/src/main/java/com/example/android/basicmediarouter/MainActivity.java deleted file mode 100644 index 1244acc..0000000 --- a/BasicMediaRouter/Application/src/main/java/com/example/android/basicmediarouter/MainActivity.java +++ /dev/null @@ -1,305 +0,0 @@ -/* - * Copyright 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.android.basicmediarouter; - -import android.content.DialogInterface; -import android.os.Bundle; -import androidx.core.view.MenuItemCompat; -import androidx.appcompat.app.AppCompatActivity; -import androidx.mediarouter.app.MediaRouteActionProvider; -import androidx.mediarouter.media.MediaControlIntent; -import androidx.mediarouter.media.MediaRouteSelector; -import androidx.mediarouter.media.MediaRouter; -import android.view.Display; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.view.WindowManager; -import android.widget.Button; -import android.widget.TextView; - -/** - *

- * This sample demonstrates the use of the MediaRouter API to show content on a - * secondary display using a {@link android.app.Presentation}. - *

- *

- * The activity uses the {@link android.media.MediaRouter} API to automatically detect when a - * presentation display is available and to allow the user to control the media - * routes using a menu item provided by the {@link android.app.MediaRouteActionProvider}. - * When a presentation display is available a {@link android.app.Presentation} (implemented - * as a {@link SamplePresentation}) is shown on the preferred display. A button - * toggles the background color of the secondary screen to show the interaction - * between the primary and secondary screens. - *

- *

- * This sample requires an HDMI or Wifi display. Alternatively, the - * "Simulate secondary displays" feature in Development Settings can be enabled - * to simulate secondary displays. - *

- * - * @see android.app.Presentation - * @see android.media.MediaRouter - */ -public class MainActivity extends AppCompatActivity { - - private MediaRouter mMediaRouter; - - // Active Presentation, set to null if no secondary screen is enabled - private SamplePresentation mPresentation; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setContentView(R.layout.main_activity); - mTextStatus = findViewById(R.id.textStatus); - - // get the list of background colors - mColors = getResources().getIntArray(R.array.androidcolors); - - // Enable clicks on the 'change color' button - mButton = findViewById(R.id.button1); - mButton.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View v) { - showNextColor(); - } - }); - - // BEGIN_INCLUDE(getMediaRouter) - // Get the MediaRouter service - mMediaRouter = MediaRouter.getInstance(this); - // END_INCLUDE(getMediaRouter) - } - - /** - * Implementing a {@link android.media.MediaRouter.Callback} to update the displayed - * {@link android.app.Presentation} when a route is selected, unselected or the - * presentation display has changed. The provided stub implementation - * {@link android.media.MediaRouter.SimpleCallback} is extended and only - * {@link android.media.MediaRouter.SimpleCallback#onRouteSelected(android.media.MediaRouter, int, android.media.MediaRouter.RouteInfo)} - * , - * {@link android.media.MediaRouter.SimpleCallback#onRouteUnselected(android.media.MediaRouter, int, android.media.MediaRouter.RouteInfo)} - * and - * {@link android.media.MediaRouter.SimpleCallback#onRoutePresentationDisplayChanged(android.media.MediaRouter, android.media.MediaRouter.RouteInfo)} - * are overridden to update the displayed {@link android.app.Presentation} in - * {@link #updatePresentation()}. These callbacks enable or disable the - * second screen presentation based on the routing provided by the - * {@link android.media.MediaRouter} for {@link android.media.MediaRouter#ROUTE_TYPE_LIVE_VIDEO} - * streams. @ - */ - private final MediaRouter.Callback mMediaRouterCallback = - new MediaRouter.Callback() { - - // BEGIN_INCLUDE(SimpleCallback) - - /** - * A new route has been selected as active. Disable the current - * route and enable the new one. - */ - @Override - public void onRouteSelected(MediaRouter router, MediaRouter.RouteInfo route) { - updatePresentation(); - } - - /** - * The route has been unselected. - */ - @Override - public void onRouteUnselected(MediaRouter router, MediaRouter.RouteInfo info) { - updatePresentation(); - } - - /** - * The route's presentation display has changed. This callback - * is called when the presentation has been activated, removed - * or its properties have changed. - */ - @Override - public void onRoutePresentationDisplayChanged(MediaRouter router, MediaRouter.RouteInfo route) { - updatePresentation(); - } - // END_INCLUDE(SimpleCallback) - }; - - /** - * Updates the displayed presentation to enable a secondary screen if it has - * been selected in the {@link android.media.MediaRouter} for the - * {@link android.media.MediaRouter#ROUTE_TYPE_LIVE_VIDEO} type. If no screen has been - * selected by the {@link android.media.MediaRouter}, the current screen is disabled. - * Otherwise a new {@link SamplePresentation} is initialized and shown on - * the secondary screen. - */ - private void updatePresentation() { - - // BEGIN_INCLUDE(updatePresentationInit) - // Get the selected route for live video - MediaRouter.RouteInfo selectedRoute = mMediaRouter.getSelectedRoute(); - - // Get its Display if a valid route has been selected - Display selectedDisplay = selectedRoute.getPresentationDisplay(); - // END_INCLUDE(updatePresentationInit) - - // BEGIN_INCLUDE(updatePresentationDismiss) - /* - * Dismiss the current presentation if the display has changed or no new - * route has been selected - */ - if (mPresentation != null && mPresentation.getDisplay() != selectedDisplay) { - mPresentation.dismiss(); - mPresentation = null; - mButton.setEnabled(false); - mTextStatus.setText(R.string.secondary_notconnected); - } - // END_INCLUDE(updatePresentationDismiss) - - // BEGIN_INCLUDE(updatePresentationNew) - /* - * Show a new presentation if the previous one has been dismissed and a - * route has been selected. - */ - if (mPresentation == null && selectedDisplay != null) { - - // Initialise a new Presentation for the Display - mPresentation = new SamplePresentation(this, selectedDisplay); - mPresentation.setOnDismissListener(mOnDismissListener); - - // Try to show the presentation, this might fail if the display has - // gone away in the mean time - try { - mPresentation.show(); - mTextStatus.setText(getResources().getString(R.string.secondary_connected, - selectedRoute.getName())); - mButton.setEnabled(true); - showNextColor(); - } catch (WindowManager.InvalidDisplayException ex) { - // Couldn't show presentation - display was already removed - mPresentation = null; - } - } - // END_INCLUDE(updatePresentationNew) - - } - - @Override - protected void onResume() { - super.onResume(); - - // BEGIN_INCLUDE(addCallback) - // Register a callback for all events related to live video devices - mMediaRouter.addCallback( - new MediaRouteSelector.Builder() - .addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO) - .build(), - mMediaRouterCallback - ); - // END_INCLUDE(addCallback) - - // Show the 'Not connected' status message - mButton.setEnabled(false); - mTextStatus.setText(R.string.secondary_notconnected); - - // Update the displays based on the currently active routes - updatePresentation(); - } - - @Override - protected void onPause() { - super.onPause(); - - // BEGIN_INCLUDE(onPause) - // Stop listening for changes to media routes. - mMediaRouter.removeCallback(mMediaRouterCallback); - // END_INCLUDE(onPause) - } - - @Override - protected void onStop() { - super.onStop(); - - // BEGIN_INCLUDE(onStop) - // Dismiss the presentation when the activity is not visible. - if (mPresentation != null) { - mPresentation.dismiss(); - mPresentation = null; - } - // BEGIN_INCLUDE(onStop) - } - - /** - * Inflates the ActionBar or options menu. The menu file defines an item for - * the {@link android.app.MediaRouteActionProvider}, which is registered here for all - * live video devices using {@link android.media.MediaRouter#ROUTE_TYPE_LIVE_VIDEO}. - */ - @Override - public boolean onCreateOptionsMenu(Menu menu) { - super.onCreateOptionsMenu(menu); - - getMenuInflater().inflate(R.menu.main, menu); - - // BEGIN_INCLUDE(MediaRouteActionProvider) - // Configure the media router action provider - MenuItem mediaRouteMenuItem = menu.findItem(R.id.menu_media_route); - - MediaRouteActionProvider mediaRouteActionProvider = - (MediaRouteActionProvider) MenuItemCompat.getActionProvider(mediaRouteMenuItem); - mediaRouteActionProvider.setRouteSelector( - new MediaRouteSelector.Builder() - .addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO) - .build()); - // BEGIN_INCLUDE(MediaRouteActionProvider) - - return true; - } - - /** - * Listens for dismissal of the {@link SamplePresentation} and removes its - * reference. - */ - private final DialogInterface.OnDismissListener mOnDismissListener = - new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialog) { - if (dialog == mPresentation) { - mPresentation = null; - } - } - }; - - // Views used to display status information on the primary screen - private TextView mTextStatus; - private Button mButton; - - // selected color index - private int mColor = 0; - - // background colors - public int[] mColors; - - /** - * Displays the next color on the secondary screen if it is activate. - */ - private void showNextColor() { - if (mPresentation != null) { - // a second screen is active and initialized, show the next color - mPresentation.setColor(mColors[mColor]); - mColor = (mColor + 1) % mColors.length; - } - } -} diff --git a/BasicMediaRouter/Application/src/main/java/com/example/android/basicmediarouter/SamplePresentation.java b/BasicMediaRouter/Application/src/main/java/com/example/android/basicmediarouter/SamplePresentation.java deleted file mode 100644 index a8b2a06..0000000 --- a/BasicMediaRouter/Application/src/main/java/com/example/android/basicmediarouter/SamplePresentation.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.android.basicmediarouter; - -import android.app.Presentation; -import android.content.Context; -import android.os.Bundle; -import android.view.Display; -import android.widget.LinearLayout; -import android.widget.TextView; - -/** - *

- * A {@link android.app.Presentation} used to demonstrate interaction between primary and - * secondary screens. - *

- *

- * It displays the name of the display in which it has been embedded (see - * {@link android.app.Presentation#getDisplay()}) and exposes a facility to change its - * background color and display its text. - *

- */ -public class SamplePresentation extends Presentation { - - private LinearLayout mLayout; - private TextView mText; - - public SamplePresentation(Context outerContext, Display display) { - super(outerContext, display); - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - // Set the content view to the custom layout - setContentView(R.layout.sample_presentation); - - // Get the Views - mLayout = findViewById(R.id.display_layout); - mText = findViewById(R.id.display_text); - - /* - * Show the name of the display this presentation was embedded in. - */ - TextView smallText = findViewById(R.id.display_smalltext); - final String name = getDisplay().getName(); - smallText.setText(getResources().getString(R.string.display_name, name)); - } - - /** - * Set the background color of the layout and display the color as a String. - * - * @param color The background color - */ - public void setColor(int color) { - mLayout.setBackgroundColor(color); - - // Display the color as a string on screen - String s = getResources().getString(R.string.display_color, color); - mText.setText(s); - } - -} diff --git a/BasicMediaRouter/Application/src/main/res/drawable-hdpi/ic_launcher.png b/BasicMediaRouter/Application/src/main/res/drawable-hdpi/ic_launcher.png deleted file mode 100644 index b1efaf4..0000000 Binary files a/BasicMediaRouter/Application/src/main/res/drawable-hdpi/ic_launcher.png and /dev/null differ diff --git a/BasicMediaRouter/Application/src/main/res/drawable-hdpi/tile.9.png b/BasicMediaRouter/Application/src/main/res/drawable-hdpi/tile.9.png deleted file mode 100644 index 1358628..0000000 Binary files a/BasicMediaRouter/Application/src/main/res/drawable-hdpi/tile.9.png and /dev/null differ diff --git a/BasicMediaRouter/Application/src/main/res/drawable-mdpi/ic_launcher.png b/BasicMediaRouter/Application/src/main/res/drawable-mdpi/ic_launcher.png deleted file mode 100644 index f5f9244..0000000 Binary files a/BasicMediaRouter/Application/src/main/res/drawable-mdpi/ic_launcher.png and /dev/null differ diff --git a/BasicMediaRouter/Application/src/main/res/drawable-xhdpi/ic_launcher.png b/BasicMediaRouter/Application/src/main/res/drawable-xhdpi/ic_launcher.png deleted file mode 100644 index 5d07b3f..0000000 Binary files a/BasicMediaRouter/Application/src/main/res/drawable-xhdpi/ic_launcher.png and /dev/null differ diff --git a/BasicMediaRouter/Application/src/main/res/drawable-xxhdpi/ic_launcher.png b/BasicMediaRouter/Application/src/main/res/drawable-xxhdpi/ic_launcher.png deleted file mode 100644 index 6ef21e1..0000000 Binary files a/BasicMediaRouter/Application/src/main/res/drawable-xxhdpi/ic_launcher.png and /dev/null differ diff --git a/BasicMediaRouter/Application/src/main/res/layout/main_activity.xml b/BasicMediaRouter/Application/src/main/res/layout/main_activity.xml deleted file mode 100644 index e4a70e7..0000000 --- a/BasicMediaRouter/Application/src/main/res/layout/main_activity.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - -