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