Home | History | Annotate | Download | only in media
      1 /*
      2  * Copyright (C) 2011 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  * @hide
     23  *
     24  * Class to hold the subtitle track's data, including:
     25  * <ul>
     26  * <li> Track index</li>
     27  * <li> Start time (in microseconds) of the data</li>
     28  * <li> Duration (in microseconds) of the data</li>
     29  * <li> A byte-array of the data</li>
     30  * </ul>
     31  *
     32  * <p> To receive the subtitle data, applications need to do the following:
     33  *
     34  * <ul>
     35  * <li> Select a track of type MEDIA_TRACK_TYPE_SUBTITLE with {@link MediaPlayer.selectTrack(int)</li>
     36  * <li> Implement the {@link MediaPlayer.OnSubtitleDataListener} interface</li>
     37  * <li> Register the {@link MediaPlayer.OnSubtitleDataListener} callback on a MediaPlayer object</li>
     38  * </ul>
     39  *
     40  * @see android.media.MediaPlayer
     41  */
     42 public final class SubtitleData
     43 {
     44     private static final String TAG = "SubtitleData";
     45 
     46     private int mTrackIndex;
     47     private long mStartTimeUs;
     48     private long mDurationUs;
     49     private byte[] mData;
     50 
     51     public SubtitleData(Parcel parcel) {
     52         if (!parseParcel(parcel)) {
     53             throw new IllegalArgumentException("parseParcel() fails");
     54         }
     55     }
     56 
     57     public int getTrackIndex() {
     58         return mTrackIndex;
     59     }
     60 
     61     public long getStartTimeUs() {
     62         return mStartTimeUs;
     63     }
     64 
     65     public long getDurationUs() {
     66         return mDurationUs;
     67     }
     68 
     69     public byte[] getData() {
     70         return mData;
     71     }
     72 
     73     private boolean parseParcel(Parcel parcel) {
     74         parcel.setDataPosition(0);
     75         if (parcel.dataAvail() == 0) {
     76             return false;
     77         }
     78 
     79         mTrackIndex = parcel.readInt();
     80         mStartTimeUs = parcel.readLong();
     81         mDurationUs = parcel.readLong();
     82         mData = new byte[parcel.readInt()];
     83         parcel.readByteArray(mData);
     84 
     85         return true;
     86     }
     87 }
     88