TimedMetaData.java revision ac033f033d2c0ff3d7cfd037409278d73260e87c
1/* 2 * Copyright 2015 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 android.os.Parcel; 20 21/** 22 * Class that embodies a piece of timed metadata, including 23 * 24 * <ul> 25 * <li> a time stamp, and </li> 26 * <li> raw uninterpreted byte-array extracted directly from the container. </li> 27 * </ul> 28 * 29 * @see MediaPlayer#setOnTimedMetaDataListener(android.media.MediaPlayer.OnTimedMetaDataListener) 30 */ 31 32public class TimedMetaData { 33 private static final String TAG = "TimedMetaData"; 34 35 private long mTimeUs; 36 private byte[] mRawData; 37 38 /** 39 * @hide 40 */ 41 static TimedMetaData createTimedMetaDataFromParcel(Parcel parcel) { 42 return new TimedMetaData(parcel); 43 } 44 45 private TimedMetaData(Parcel parcel) { 46 if (!parseParcel(parcel)) { 47 throw new IllegalArgumentException("parseParcel() fails"); 48 } 49 } 50 51 public long getTimeUs() { 52 return mTimeUs; 53 } 54 55 public byte[] getRawData() { 56 return mRawData; 57 } 58 59 private boolean parseParcel(Parcel parcel) { 60 parcel.setDataPosition(0); 61 if (parcel.dataAvail() == 0) { 62 return false; 63 } 64 65 mTimeUs = parcel.readLong(); 66 mRawData = new byte[parcel.readInt()]; 67 parcel.readByteArray(mRawData); 68 69 return true; 70 } 71} 72