@@ -1577,26 +1577,39 @@ public TrackInfo[] newArray(int size) {
15771577
15781578 /**
15791579 * Returns an array of track information.
1580+ * If it is called in an invalid state, IllegalStateException will be thrown.
15801581 *
1581- * @return Array of track info. null if an error occured.
1582+ * @return Array of track info. The total number of tracks is the array length.
1583+ * Must be called again if an external source has been added after any of the
1584+ * addExternalSource methods are called.
15821585 * {@hide}
15831586 */
1584- // FIXME: It returns timed text tracks' information for now. Other types of tracks will be
1585- // supported in future.
15861587 public TrackInfo [] getTrackInfo () {
15871588 Parcel request = Parcel .obtain ();
15881589 Parcel reply = Parcel .obtain ();
15891590 request .writeInterfaceToken (IMEDIA_PLAYER );
15901591 request .writeInt (INVOKE_ID_GET_TRACK_INFO );
1591- invoke (request , reply );
1592+ int status = invoke (request , reply );
1593+ if (status != 0 ) {
1594+ throw new IllegalStateException ();
1595+ }
15921596 TrackInfo trackInfo [] = reply .createTypedArray (TrackInfo .CREATOR );
15931597 return trackInfo ;
15941598 }
15951599
1600+ /* Do not change these values without updating their counterparts
1601+ * in include/media/stagefright/MediaDefs.h and media/libstagefright/MediaDefs.cpp!
1602+ */
1603+ /**
1604+ * MIME type for SubRip (SRT) container. Used in addExternalSource APIs.
1605+ * {@hide}
1606+ */
1607+ public static final String MEDIA_MIMETYPE_TEXT_SUBRIP = "application/x-subrip" ;
1608+
15961609 /*
15971610 * A helper function to check if the mime type is supported by media framework.
15981611 */
1599- private boolean availableMimeTypeForExternalSource (String mimeType ) {
1612+ private static boolean availableMimeTypeForExternalSource (String mimeType ) {
16001613 if (mimeType == MEDIA_MIMETYPE_TEXT_SUBRIP ) {
16011614 return true ;
16021615 }
@@ -1614,10 +1627,11 @@ private boolean availableMimeTypeForExternalSource(String mimeType) {
16141627 * additional tracks become available after this method call.
16151628 *
16161629 * @param path The file path of external source file.
1630+ * @param mimeType The mime type of the file. Must be one of the mime types listed above.
1631+ * @throws IOException if the file cannot be accessed or is corrupted.
1632+ * @throws IllegalArgumentException if the mimeType is not supported.
16171633 * {@hide}
16181634 */
1619- // FIXME: define error codes and throws exceptions according to the error codes.
1620- // (IllegalStateException, IOException).
16211635 public void addExternalSource (String path , String mimeType )
16221636 throws IOException , IllegalArgumentException {
16231637 if (!availableMimeTypeForExternalSource (mimeType )) {
@@ -1647,10 +1661,11 @@ public void addExternalSource(String path, String mimeType)
16471661 *
16481662 * @param context the Context to use when resolving the Uri
16491663 * @param uri the Content URI of the data you want to play
1664+ * @param mimeType The mime type of the file. Must be one of the mime types listed above.
1665+ * @throws IOException if the file cannot be accessed or is corrupted.
1666+ * @throws IllegalArgumentException if the mimeType is not supported.
16501667 * {@hide}
16511668 */
1652- // FIXME: define error codes and throws exceptions according to the error codes.
1653- // (IllegalStateException, IOException).
16541669 public void addExternalSource (Context context , Uri uri , String mimeType )
16551670 throws IOException , IllegalArgumentException {
16561671 String scheme = uri .getScheme ();
@@ -1677,15 +1692,6 @@ public void addExternalSource(Context context, Uri uri, String mimeType)
16771692 }
16781693 }
16791694
1680- /* Do not change these values without updating their counterparts
1681- * in include/media/stagefright/MediaDefs.h and media/libstagefright/MediaDefs.cpp!
1682- */
1683- /**
1684- * MIME type for SubRip (SRT) container. Used in {@link #addExternalSource()} APIs.
1685- * {@hide}
1686- */
1687- public static final String MEDIA_MIMETYPE_TEXT_SUBRIP = "application/x-subrip" ;
1688-
16891695 /**
16901696 * Adds an external source file (FileDescriptor).
16911697 * It is the caller's responsibility to close the file descriptor.
@@ -1697,14 +1703,10 @@ public void addExternalSource(Context context, Uri uri, String mimeType)
16971703 * additional tracks become available after this method call.
16981704 *
16991705 * @param fd the FileDescriptor for the file you want to play
1700- * @param mimeType A MIME type for the content. It can be null.
1701- * <ul>
1702- * <li>{@link #MEDIA_MIMETYPE_TEXT_SUBRIP}
1703- * </ul>
1706+ * @param mimeType The mime type of the file. Must be one of the mime types listed above.
1707+ * @throws IllegalArgumentException if the mimeType is not supported.
17041708 * {@hide}
17051709 */
1706- // FIXME: define error codes and throws exceptions according to the error codes.
1707- // (IllegalStateException, IOException).
17081710 public void addExternalSource (FileDescriptor fd , String mimeType )
17091711 throws IllegalArgumentException {
17101712 // intentionally less than LONG_MAX
@@ -1724,11 +1726,10 @@ public void addExternalSource(FileDescriptor fd, String mimeType)
17241726 * @param fd the FileDescriptor for the file you want to play
17251727 * @param offset the offset into the file where the data to be played starts, in bytes
17261728 * @param length the length in bytes of the data to be played
1727- * @param mimeType A MIME type for the content. It can be null.
1729+ * @param mimeType The mime type of the file. Must be one of the mime types listed above.
1730+ * @throws IllegalArgumentException if the mimeType is not supported.
17281731 * {@hide}
17291732 */
1730- // FIXME: define error codes and throws exceptions according to the error codes.
1731- // (IllegalStateException, IOException).
17321733 public void addExternalSource (FileDescriptor fd , long offset , long length , String mimeType )
17331734 throws IllegalArgumentException {
17341735 if (!availableMimeTypeForExternalSource (mimeType )) {
@@ -1749,47 +1750,67 @@ public void addExternalSource(FileDescriptor fd, long offset, long length, Strin
17491750 /**
17501751 * Selects a track.
17511752 * <p>
1752- * If a MediaPlayer is in invalid state, it throws exception.
1753- * If a MediaPlayer is in Started state, the selected track will be presented immediately.
1753+ * If a MediaPlayer is in invalid state, it throws an IllegalStateException exception.
1754+ * If a MediaPlayer is in <em> Started</em> state, the selected track is presented immediately.
17541755 * If a MediaPlayer is not in Started state, it just marks the track to be played.
17551756 * </p>
17561757 * <p>
17571758 * In any valid state, if it is called multiple times on the same type of track (ie. Video,
17581759 * Audio, Timed Text), the most recent one will be chosen.
17591760 * </p>
17601761 * <p>
1761- * The first audio and video tracks will be selected by default, even though this function is not
1762- * called. However, no timed text track will be selected until this function is called.
1762+ * The first audio and video tracks are selected by default if available, even though
1763+ * this method is not called. However, no timed text track will be selected until
1764+ * this function is called.
1765+ * </p>
1766+ * <p>
1767+ * Currently, only timed text tracks or audio tracks can be selected via this method.
1768+ * In addition, the support for selecting an audio track at runtime is pretty limited
1769+ * in that an audio track can only be selected in the <em>Prepared</em> state.
17631770 * </p>
1771+ * @param index the index of the track to be selected. The valid range of the index
1772+ * is 0..total number of track - 1. The total number of tracks as well as the type of
1773+ * each individual track can be found by calling {@link #getTrackInfo()} method.
1774+ * @see android.media.MediaPlayer.getTrackInfo
17641775 * {@hide}
17651776 */
1766- // FIXME: define error codes and throws exceptions according to the error codes.
1767- // (IllegalStateException, IOException, IllegalArgumentException).
17681777 public void selectTrack (int index ) {
1769- Parcel request = Parcel .obtain ();
1770- Parcel reply = Parcel .obtain ();
1771- request .writeInterfaceToken (IMEDIA_PLAYER );
1772- request .writeInt (INVOKE_ID_SELECT_TRACK );
1773- request .writeInt (index );
1774- invoke (request , reply );
1778+ selectOrUnselectTrack (index , true /* select */ );
17751779 }
17761780
17771781 /**
17781782 * Unselect a track.
1779- * If the track identified by index has not been selected before, it throws an exception.
1783+ * <p>
1784+ * Currently, the track must be a timed text track and no audio or video tracks can be
1785+ * unselected. If the timed text track identified by index has not been
1786+ * selected before, it throws an exception.
1787+ * </p>
1788+ * @param index the index of the track to be unselected. The valid range of the index
1789+ * is 0..total number of tracks - 1. The total number of tracks as well as the type of
1790+ * each individual track can be found by calling {@link #getTrackInfo()} method.
1791+ *
1792+ * @see android.media.MediaPlayer.getTrackInfo
17801793 * {@hide}
17811794 */
1782- // FIXME: define error codes and throws exceptions according to the error codes.
1783- // (IllegalStateException, IOException, IllegalArgumentException).
17841795 public void unselectTrack (int index ) {
1796+ selectOrUnselectTrack (index , false /* select */ );
1797+ }
1798+
1799+ private void selectOrUnselectTrack (int index , boolean select ) {
17851800 Parcel request = Parcel .obtain ();
17861801 Parcel reply = Parcel .obtain ();
17871802 request .writeInterfaceToken (IMEDIA_PLAYER );
1788- request .writeInt (INVOKE_ID_UNSELECT_TRACK );
1803+ request .writeInt (select ? INVOKE_ID_SELECT_TRACK : INVOKE_ID_UNSELECT_TRACK );
17891804 request .writeInt (index );
1790- invoke (request , reply );
1805+ int status = invoke (request , reply );
1806+ if (status != 0 ) {
1807+ String msg = select ? "selectTrack " : "unselectTrack " ;
1808+ msg += "failed for track index: " + index ;
1809+ throw new RuntimeException (msg );
1810+ }
17911811 }
17921812
1813+
17931814 /**
17941815 * @param reply Parcel with audio/video duration info for battery
17951816 tracking usage
0 commit comments