MediaExtractor.java revision c52b980277f08aee7981b1fdbca7a89464cf66d9
1/* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.media; 18 19import java.nio.ByteBuffer; 20import java.util.Map; 21 22/** 23 * MediaExtractor 24 * @hide 25*/ 26public class MediaExtractor 27{ 28 public MediaExtractor(String path) { 29 native_setup(path); 30 } 31 32 @Override 33 protected void finalize() { 34 native_finalize(); 35 } 36 37 // Make sure you call this when you're done to free up any resources 38 // instead of relying on the garbage collector to do this for you at 39 // some point in the future. 40 public native final void release(); 41 42 public native int countTracks(); 43 public native Map<String, Object> getTrackFormat(int index); 44 45 // Subsequent calls to "readSampleData", "getSampleTrackIndex" and 46 // "getSampleTime" only retrieve information for the subset of tracks 47 // selected by the call below. 48 // Selecting the same track multiple times has no effect, the track 49 // is only selected once. 50 public native void selectTrack(int index); 51 52 // All selected tracks seek near the requested time. The next sample 53 // returned for each selected track will be a sync sample. 54 public native void seekTo(long timeUs); 55 56 public native boolean advance(); 57 58 // Retrieve the current encoded sample and store it in the byte buffer 59 // starting at the given offset. Returns the sample size. 60 public native int readSampleData(ByteBuffer byteBuf, int offset); 61 62 // Returns the track index the current sample originates from. 63 public native int getSampleTrackIndex(); 64 65 // Returns the current sample's presentation time in microseconds. 66 public native long getSampleTime(); 67 68 private static native final void native_init(); 69 private native final void native_setup(String path); 70 private native final void native_finalize(); 71 72 static { 73 System.loadLibrary("media_jni"); 74 native_init(); 75 } 76 77 private int mNativeContext; 78} 79