Home | History | Annotate | only in /developers/build/prebuilts/gradle/BasicMediaDecoder
Up to higher level directory
NameDateSize
.google/10-Mar-2015
Application/10-Mar-2015
build.gradle16-Dec-201410
CONTRIB.md16-Dec-20141.6K
CONTRIBUTING.md10-Mar-20151.5K
gradle/16-Dec-2014
gradlew16-Dec-20145K
gradlew.bat16-Dec-20142.3K
LICENSE16-Dec-201411.1K
NOTICE10-Mar-2015613
packaging.yaml16-Dec-2014493
README.md10-Mar-20155K
screenshots/10-Mar-2015
settings.gradle16-Dec-201422

README.md

      1 Android BasicMediaDecoder Sample
      2 ===================================
      3 
      4 This sample shows how to use the MediaCoder to decode a video,
      5 use a TimeAnimator to sync the rendering commands with the system
      6 display frame rendering and finally render it to a TextureView.
      7 
      8 Introduction
      9 ------------
     10 
     11 [MediaCodec][1] was introduced in API 16, and can be used for low level (decoding/encoding) operations.
     12 In the same API was also introduced [TimeAnimator][2], which can be used to synchronise animation frames.
     13 Finally, [MediaExtractor][3] provides a simple way to extract demuxed media data from a data source.
     14 
     15 The main steps are described below:
     16 
     17 1. Create a layout with a [TextureView][4] for your activity.
     18 2. Initialise a MediaExtractor instance with `new MediaExtractor()` and a TimeAnimator instance with
     19 `new TimeAnimator()`.
     20 3. To start video playback, call `setDataSource(this, videoUri, null)` on your MediaExtractor instance,
     21 where `videoUri` is the URI of your video source.
     22 4. On your MediaExtractor instance, call `getTrackCount()` to know how many tracks you have in your streams.
     23 They may not all be video tracks. Deselect all tracks by calling `unselectTrack(i)` where `i` is
     24 the index of the track.
     25 5. Get the mime type of a track by calling `getTrackFormat(i).getString(MediaFormat.KEY_MIME)`
     26 on your MediaExtractor instance, where `i` is the index of your selected track.
     27 If the mime type contains "video/", then this is a video track so you can select it, using `selectTrack(i)`
     28 on your MediaExtractor instance.
     29 6. Create a MediaCodec instance by calling `MediaCodec.createDecoderByType(mimeType)`.
     30 7. Configure your MediaCodec instance with `configure(trackFormat, textureView, null,  0)`,
     31 where `trackFormat` is obtained by calling `getTrackFormat(i)` on your MediaExtractor instance.
     32 8. Set a TimeListener on your TimeAnimation instance, and override its `onTimeUpdate(final TimeAnimator animation,
     33 final long totalTime, final long deltaTime)` method.
     34 9. In `onTimeUpdate`, check if the media track has reached the end of stream, using `getSampleFlags()`
     35 on  your MediaExtractor instance and looking for `MediaCodec.BUFFER_FLAG_END_OF_STREAM` flag.
     36 10. Still in `onTimeUpdate`, assuming this isn't the end of the sample, write the media sample to your
     37 MediaDecoder instance, using `queueInputBuffer(index, 0, size, presentationTimeUs, flags)` method.
     38 You will need to set up your buffers, refer to [MediaCodec][1] documentation for details.
     39 11. After writing the media sample, you need to advance the sample, calling `advance()` on your
     40 TimeExtractor instance (this is a blocking operation and should be done outside the main thread).
     41 12. Finally, you can release and render the media sample by calling
     42 `dequeueOutputBuffer(info, timeout)` and `releaseOutputBuffer(i, true)`, refer to [MediaCodec][1]
     43 documentation for details.
     44 13. In `onPause()` or if you have reached the end of the stream, call `end()` on your TimeAnimation instance,
     45 then call `stop()` and `release()` on your MediaCodec instance, and finally, call `release()` on your
     46 MediaExtractor instance.
     47 
     48 [1]: http://developer.android.com/reference/android/media/MediaCodec.html
     49 [2]: http://developer.android.com/reference/android/animation/TimeAnimator.html
     50 [3]: http://developer.android.com/reference/android/media/MediaExtractor.html
     51 [4]: http://developer.android.com/reference/android/view/TextureView.html
     52 
     53 Pre-requisites
     54 --------------
     55 
     56 - Android SDK v21
     57 - Android Build Tools v21.1.1
     58 - Android Support Repository
     59 
     60 Screenshots
     61 -------------
     62 
     63 <img src="screenshots/1-launch.png" height="400" alt="Screenshot"/> <img src="screenshots/2-play-video.png" height="400" alt="Screenshot"/> 
     64 
     65 Getting Started
     66 ---------------
     67 
     68 This sample uses the Gradle build system. To build this project, use the
     69 "gradlew build" command or use "Import Project" in Android Studio.
     70 
     71 Support
     72 -------
     73 
     74 - Google+ Community: https://plus.google.com/communities/105153134372062985968
     75 - Stack Overflow: http://stackoverflow.com/questions/tagged/android
     76 
     77 If you've found an error in this sample, please file an issue:
     78 https://github.com/googlesamples/android-BasicMediaDecoder
     79 
     80 Patches are encouraged, and may be submitted by forking this project and
     81 submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.
     82 
     83 License
     84 -------
     85 
     86 Copyright 2014 The Android Open Source Project, Inc.
     87 
     88 Licensed to the Apache Software Foundation (ASF) under one or more contributor
     89 license agreements.  See the NOTICE file distributed with this work for
     90 additional information regarding copyright ownership.  The ASF licenses this
     91 file to you under the Apache License, Version 2.0 (the "License"); you may not
     92 use this file except in compliance with the License.  You may obtain a copy of
     93 the License at
     94 
     95 http://www.apache.org/licenses/LICENSE-2.0
     96 
     97 Unless required by applicable law or agreed to in writing, software
     98 distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
     99 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
    100 License for the specific language governing permissions and limitations under
    101 the License.
    102