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 17 package android.media; 18 19 import android.os.Parcel; 20 21 /** 22 * Class that embodies one timed metadata access unit, 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#setOnTimedMetaDataAvailableListener(android.media.MediaPlayer.OnTimedMetaDataListener) 30 */ 31 public final class TimedMetaData { 32 private static final String TAG = "TimedMetaData"; 33 34 private long mTimestampUs; 35 private byte[] mMetaData; 36 37 /** 38 * @hide 39 */ createTimedMetaDataFromParcel(Parcel parcel)40 static TimedMetaData createTimedMetaDataFromParcel(Parcel parcel) { 41 return new TimedMetaData(parcel); 42 } 43 TimedMetaData(Parcel parcel)44 private TimedMetaData(Parcel parcel) { 45 if (!parseParcel(parcel)) { 46 throw new IllegalArgumentException("parseParcel() fails"); 47 } 48 } 49 50 /** 51 * @return the timestamp associated with this metadata access unit in microseconds; 52 * 0 denotes playback start. 53 */ getTimestamp()54 public long getTimestamp() { 55 return mTimestampUs; 56 } 57 58 /** 59 * @return raw, uninterpreted content of this metadata access unit; for ID3 tags this includes 60 * everything starting from the 3 byte signature "ID3". 61 */ getMetaData()62 public byte[] getMetaData() { 63 return mMetaData; 64 } 65 parseParcel(Parcel parcel)66 private boolean parseParcel(Parcel parcel) { 67 parcel.setDataPosition(0); 68 if (parcel.dataAvail() == 0) { 69 return false; 70 } 71 72 mTimestampUs = parcel.readLong(); 73 mMetaData = new byte[parcel.readInt()]; 74 parcel.readByteArray(mMetaData); 75 76 return true; 77 } 78 } 79