19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/* 29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Copyright (C) 2006 The Android Open Source Project 39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you may not use this file except in compliance with the License. 69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You may obtain a copy of the License at 79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * See the License for the specific language governing permissions and 149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * limitations under the License. 159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpackage android.media; 189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.content.ContentResolver; 209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.content.Context; 219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.content.res.AssetFileDescriptor; 229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.net.Uri; 239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Handler; 249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Looper; 259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Message; 2620cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Cataniaimport android.os.Parcel; 2741f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kangimport android.os.Parcelable; 289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.ParcelFileDescriptor; 299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.PowerManager; 309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.util.Log; 319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.view.Surface; 329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.view.SurfaceHolder; 339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.graphics.Bitmap; 34cc562a3576a6a8096626387472e05e8bee03352aGlenn Kastenimport android.graphics.SurfaceTexture; 359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.media.AudioManager; 369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 37e00b6f3a57d4b480ce674468de93555269bbd71aJames Dongimport java.io.File; 389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport java.io.FileDescriptor; 39e00b6f3a57d4b480ce674468de93555269bbd71aJames Dongimport java.io.FileInputStream; 409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport java.io.IOException; 41720aa282791ef9405d39a15f419a41ab24f11e30John Grossmanimport java.net.InetSocketAddress; 42256430093679e1d62b54fb0c852126e54d162f6fAndreas Huberimport java.util.Map; 439193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Cataniaimport java.util.Set; 449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport java.lang.ref.WeakReference; 459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/** 479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * MediaPlayer class can be used to control playback 489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * of audio/video files and streams. An example on how to use the methods in 499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this class can be found in {@link android.widget.VideoView}. 509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p>Topics covered here are: 529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <ol> 539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li><a href="#StateDiagram">State Diagram</a> 549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li><a href="#Valid_and_Invalid_States">Valid and Invalid States</a> 559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li><a href="#Permissions">Permissions</a> 569ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * <li><a href="#Callbacks">Register informational and error callbacks</a> 579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </ol> 589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 5961fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <div class="special reference"> 6061fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <h3>Developer Guides</h3> 6161fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <p>For more information about how to use MediaPlayer, read the 6261fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <a href="{@docRoot}guide/topics/media/mediaplayer.html">Media Playback</a> developer guide.</p> 6361fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * </div> 6461fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * 659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <a name="StateDiagram"></a> 669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <h3>State Diagram</h3> 679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p>Playback control of audio/video files and streams is managed as a state 699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * machine. The following diagram shows the life cycle and the states of a 709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * MediaPlayer object driven by the supported playback control operations. 719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * The ovals represent the states a MediaPlayer object may reside 729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * in. The arcs represent the playback control operations that drive the object 7332f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * state transition. There are two types of arcs. The arcs with a single arrow 749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * head represent synchronous method calls, while those with 759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * a double arrow head represent asynchronous method calls.</p> 769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p><img src="../../../images/mediaplayer_state_diagram.gif" 789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * alt="MediaPlayer State diagram" 799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * border="0" /></p> 809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p>From this state diagram, one can see that a MediaPlayer object has the 829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * following states:</p> 839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <ul> 8432f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <li>When a MediaPlayer object is just created using <code>new</code> or 8532f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * after {@link #reset()} is called, it is in the <em>Idle</em> state; and after 8632f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * {@link #release()} is called, it is in the <em>End</em> state. Between these 8732f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * two states is the life cycle of the MediaPlayer object. 889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <ul> 8932f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <li>There is a subtle but important difference between a newly constructed 9032f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * MediaPlayer object and the MediaPlayer object after {@link #reset()} 9132f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * is called. It is a programming error to invoke methods such 9232f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * as {@link #getCurrentPosition()}, 9332f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * {@link #getDuration()}, {@link #getVideoHeight()}, 949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link #getVideoWidth()}, {@link #setAudioStreamType(int)}, 959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link #setLooping(boolean)}, 9632f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * {@link #setVolume(float, float)}, {@link #pause()}, {@link #start()}, 9732f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * {@link #stop()}, {@link #seekTo(int)}, {@link #prepare()} or 9832f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * {@link #prepareAsync()} in the <em>Idle</em> state for both cases. If any of these 9932f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * methods is called right after a MediaPlayer object is constructed, 10032f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * the user supplied callback method OnErrorListener.onError() won't be 1019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * called by the internal player engine and the object state remains 10232f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * unchanged; but if these methods are called right after {@link #reset()}, 1039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the user supplied callback method OnErrorListener.onError() will be 10432f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * invoked by the internal player engine and the object will be 1059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * transfered to the <em>Error</em> state. </li> 10632f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <li>It is also recommended that once 10732f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * a MediaPlayer object is no longer being used, call {@link #release()} immediately 10832f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * so that resources used by the internal player engine associated with the 1099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * MediaPlayer object can be released immediately. Resource may include 11032f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * singleton resources such as hardware acceleration components and 1119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * failure to call {@link #release()} may cause subsequent instances of 1129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * MediaPlayer objects to fallback to software implementations or fail 1139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * altogether. Once the MediaPlayer 11432f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * object is in the <em>End</em> state, it can no longer be used and 1159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * there is no way to bring it back to any other state. </li> 11632f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <li>Furthermore, 11732f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * the MediaPlayer objects created using <code>new</code> is in the 11832f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <em>Idle</em> state, while those created with one 11932f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * of the overloaded convenient <code>create</code> methods are <em>NOT</em> 1209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * in the <em>Idle</em> state. In fact, the objects are in the <em>Prepared</em> 1219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * state if the creation using <code>create</code> method is successful. 1229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </li> 1239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </ul> 1249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </li> 1259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>In general, some playback control operation may fail due to various 1269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * reasons, such as unsupported audio/video format, poorly interleaved 1279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * audio/video, resolution too high, streaming timeout, and the like. 1289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Thus, error reporting and recovery is an important concern under 12932f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * these circumstances. Sometimes, due to programming errors, invoking a playback 1309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * control operation in an invalid state may also occur. Under all these 1319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * error conditions, the internal player engine invokes a user supplied 1329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * OnErrorListener.onError() method if an OnErrorListener has been 1339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * registered beforehand via 1349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link #setOnErrorListener(android.media.MediaPlayer.OnErrorListener)}. 1359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <ul> 13632f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <li>It is important to note that once an error occurs, the 13732f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * MediaPlayer object enters the <em>Error</em> state (except as noted 1389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * above), even if an error listener has not been registered by the application.</li> 1399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>In order to reuse a MediaPlayer object that is in the <em> 14032f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * Error</em> state and recover from the error, 1419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link #reset()} can be called to restore the object to its <em>Idle</em> 1429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * state.</li> 14332f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <li>It is good programming practice to have your application 14432f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * register a OnErrorListener to look out for error notifications from 14532f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * the internal player engine.</li> 146c6f8ea4cf26aadc0da765585d37f7850596af6dehugh kennedy * <li>IllegalStateException is 1479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * thrown to prevent programming errors such as calling {@link #prepare()}, 1489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link #prepareAsync()}, or one of the overloaded <code>setDataSource 1499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </code> methods in an invalid state. </li> 1509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </ul> 1519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </li> 1529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>Calling 1539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link #setDataSource(FileDescriptor)}, or 1549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link #setDataSource(String)}, or 1559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link #setDataSource(Context, Uri)}, or 15632f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * {@link #setDataSource(FileDescriptor, long, long)} transfers a 1579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * MediaPlayer object in the <em>Idle</em> state to the 1589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <em>Initialized</em> state. 1599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <ul> 16032f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <li>An IllegalStateException is thrown if 1619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setDataSource() is called in any other state.</li> 16232f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <li>It is good programming 16332f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * practice to always look out for <code>IllegalArgumentException</code> 1649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * and <code>IOException</code> that may be thrown from the overloaded 1659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <code>setDataSource</code> methods.</li> 1669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </ul> 1679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </li> 1689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>A MediaPlayer object must first enter the <em>Prepared</em> state 16932f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * before playback can be started. 1709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <ul> 1719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>There are two ways (synchronous vs. 1729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * asynchronous) that the <em>Prepared</em> state can be reached: 1739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * either a call to {@link #prepare()} (synchronous) which 1749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * transfers the object to the <em>Prepared</em> state once the method call 1759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * returns, or a call to {@link #prepareAsync()} (asynchronous) which 17632f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * first transfers the object to the <em>Preparing</em> state after the 17732f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * call returns (which occurs almost right way) while the internal 1789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * player engine continues working on the rest of preparation work 1799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * until the preparation work completes. When the preparation completes or when {@link #prepare()} call returns, 1809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the internal player engine then calls a user supplied callback method, 1819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * onPrepared() of the OnPreparedListener interface, if an 1829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * OnPreparedListener is registered beforehand via {@link 1839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * #setOnPreparedListener(android.media.MediaPlayer.OnPreparedListener)}.</li> 1849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>It is important to note that 1859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the <em>Preparing</em> state is a transient state, and the behavior 1869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * of calling any method with side effect while a MediaPlayer object is 1879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * in the <em>Preparing</em> state is undefined.</li> 18832f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <li>An IllegalStateException is 18932f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * thrown if {@link #prepare()} or {@link #prepareAsync()} is called in 19032f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * any other state.</li> 19132f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <li>While in the <em>Prepared</em> state, properties 19232f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * such as audio/sound volume, screenOnWhilePlaying, looping can be 1939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * adjusted by invoking the corresponding set methods.</li> 1949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </ul> 1959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </li> 19632f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <li>To start the playback, {@link #start()} must be called. After 1979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link #start()} returns successfully, the MediaPlayer object is in the 19832f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <em>Started</em> state. {@link #isPlaying()} can be called to test 1999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * whether the MediaPlayer object is in the <em>Started</em> state. 2009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <ul> 2019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>While in the <em>Started</em> state, the internal player engine calls 2029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * a user supplied OnBufferingUpdateListener.onBufferingUpdate() callback 20332f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * method if a OnBufferingUpdateListener has been registered beforehand 2049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * via {@link #setOnBufferingUpdateListener(OnBufferingUpdateListener)}. 2059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * This callback allows applications to keep track of the buffering status 2069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * while streaming audio/video.</li> 2079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>Calling {@link #start()} has not effect 2089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * on a MediaPlayer object that is already in the <em>Started</em> state.</li> 2099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </ul> 2109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </li> 2119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>Playback can be paused and stopped, and the current playback position 21232f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * can be adjusted. Playback can be paused via {@link #pause()}. When the call to 2139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link #pause()} returns, the MediaPlayer object enters the 21432f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <em>Paused</em> state. Note that the transition from the <em>Started</em> 21532f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * state to the <em>Paused</em> state and vice versa happens 21632f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * asynchronously in the player engine. It may take some time before 21732f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * the state is updated in calls to {@link #isPlaying()}, and it can be 2189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * a number of seconds in the case of streamed content. 2199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <ul> 22032f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <li>Calling {@link #start()} to resume playback for a paused 2219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * MediaPlayer object, and the resumed playback 22232f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * position is the same as where it was paused. When the call to 2239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link #start()} returns, the paused MediaPlayer object goes back to 2249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the <em>Started</em> state.</li> 2259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>Calling {@link #pause()} has no effect on 2269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * a MediaPlayer object that is already in the <em>Paused</em> state.</li> 2279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </ul> 2289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </li> 22932f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <li>Calling {@link #stop()} stops playback and causes a 2309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * MediaPlayer in the <em>Started</em>, <em>Paused</em>, <em>Prepared 23132f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * </em> or <em>PlaybackCompleted</em> state to enter the 2329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <em>Stopped</em> state. 2339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <ul> 23432f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <li>Once in the <em>Stopped</em> state, playback cannot be started 2359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * until {@link #prepare()} or {@link #prepareAsync()} are called to set 2369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the MediaPlayer object to the <em>Prepared</em> state again.</li> 23732f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <li>Calling {@link #stop()} has no effect on a MediaPlayer 2389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * object that is already in the <em>Stopped</em> state.</li> 2399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </ul> 2409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </li> 24132f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <li>The playback position can be adjusted with a call to 24232f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * {@link #seekTo(int)}. 2439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <ul> 2449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>Although the asynchronuous {@link #seekTo(int)} 2459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * call returns right way, the actual seek operation may take a while to 24632f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * finish, especially for audio/video being streamed. When the actual 24732f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * seek operation completes, the internal player engine calls a user 2489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * supplied OnSeekComplete.onSeekComplete() if an OnSeekCompleteListener 24932f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * has been registered beforehand via 2509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link #setOnSeekCompleteListener(OnSeekCompleteListener)}.</li> 2519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>Please 2529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * note that {@link #seekTo(int)} can also be called in the other states, 2539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * such as <em>Prepared</em>, <em>Paused</em> and <em>PlaybackCompleted 2549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </em> state.</li> 2559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>Furthermore, the actual current playback position 2569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * can be retrieved with a call to {@link #getCurrentPosition()}, which 25732f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * is helpful for applications such as a Music player that need to keep 2589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * track of the playback progress.</li> 2599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </ul> 2609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </li> 2619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>When the playback reaches the end of stream, the playback completes. 2629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <ul> 2639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>If the looping mode was being set to <var>true</var>with 2649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link #setLooping(boolean)}, the MediaPlayer object shall remain in 2659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the <em>Started</em> state.</li> 2669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>If the looping mode was set to <var>false 2679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </var>, the player engine calls a user supplied callback method, 2689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * OnCompletion.onCompletion(), if a OnCompletionListener is registered 2699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * beforehand via {@link #setOnCompletionListener(OnCompletionListener)}. 2709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * The invoke of the callback signals that the object is now in the <em> 2719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * PlaybackCompleted</em> state.</li> 2729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>While in the <em>PlaybackCompleted</em> 2739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * state, calling {@link #start()} can restart the playback from the 2749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * beginning of the audio/video source.</li> 2759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </ul> 2769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 2779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 2789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <a name="Valid_and_Invalid_States"></a> 2799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <h3>Valid and invalid states</h3> 2809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 2819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <table border="0" cellspacing="0" cellpadding="0"> 2829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>Method Name </p></td> 2839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>Valid Sates </p></td> 2849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>Invalid States </p></td> 2859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>Comments </p></td></tr> 28617cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent * <tr><td>attachAuxEffect </p></td> 28717cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent * <td>{Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted} </p></td> 28817cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent * <td>{Idle, Error} </p></td> 28917cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent * <td>This method must be called after setDataSource. 29017cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent * Calling it does not change the object state. </p></td></tr> 29117cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent * <tr><td>getAudioSessionId </p></td> 29217cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent * <td>any </p></td> 29317cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent * <td>{} </p></td> 29417cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent * <td>This method can be called in any state and calling it does not change 29517cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent * the object state. </p></td></tr> 2969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>getCurrentPosition </p></td> 29732f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <td>{Idle, Initialized, Prepared, Started, Paused, Stopped, 2989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * PlaybackCompleted} </p></td> 2999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{Error}</p></td> 3009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>Successful invoke of this method in a valid state does not change the 3019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * state. Calling this method in an invalid state transfers the object 3029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * to the <em>Error</em> state. </p></td></tr> 3039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>getDuration </p></td> 3049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{Prepared, Started, Paused, Stopped, PlaybackCompleted} </p></td> 3059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{Idle, Initialized, Error} </p></td> 3069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>Successful invoke of this method in a valid state does not change the 30732f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * state. Calling this method in an invalid state transfers the object 3089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * to the <em>Error</em> state. </p></td></tr> 3099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>getVideoHeight </p></td> 31032f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <td>{Idle, Initialized, Prepared, Started, Paused, Stopped, 3119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * PlaybackCompleted}</p></td> 3129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{Error}</p></td> 3139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>Successful invoke of this method in a valid state does not change the 31432f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * state. Calling this method in an invalid state transfers the object 3159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * to the <em>Error</em> state. </p></td></tr> 3169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>getVideoWidth </p></td> 3179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{Idle, Initialized, Prepared, Started, Paused, Stopped, 3189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * PlaybackCompleted}</p></td> 3199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{Error}</p></td> 32032f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <td>Successful invoke of this method in a valid state does not change 32132f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * the state. Calling this method in an invalid state transfers the 3229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * object to the <em>Error</em> state. </p></td></tr> 3239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>isPlaying </p></td> 32432f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <td>{Idle, Initialized, Prepared, Started, Paused, Stopped, 3259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * PlaybackCompleted}</p></td> 3269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{Error}</p></td> 3279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>Successful invoke of this method in a valid state does not change 32832f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * the state. Calling this method in an invalid state transfers the 3299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * object to the <em>Error</em> state. </p></td></tr> 3309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>pause </p></td> 3319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{Started, Paused}</p></td> 3329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{Idle, Initialized, Prepared, Stopped, PlaybackCompleted, Error}</p></td> 33332f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <td>Successful invoke of this method in a valid state transfers the 33432f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * object to the <em>Paused</em> state. Calling this method in an 3359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * invalid state transfers the object to the <em>Error</em> state.</p></td></tr> 3369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>prepare </p></td> 3379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{Initialized, Stopped} </p></td> 3389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{Idle, Prepared, Started, Paused, PlaybackCompleted, Error} </p></td> 33932f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <td>Successful invoke of this method in a valid state transfers the 34032f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * object to the <em>Prepared</em> state. Calling this method in an 3419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * invalid state throws an IllegalStateException.</p></td></tr> 3429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>prepareAsync </p></td> 3439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{Initialized, Stopped} </p></td> 3449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{Idle, Prepared, Started, Paused, PlaybackCompleted, Error} </p></td> 34532f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <td>Successful invoke of this method in a valid state transfers the 3469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * object to the <em>Preparing</em> state. Calling this method in an 3479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * invalid state throws an IllegalStateException.</p></td></tr> 3489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>release </p></td> 3499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>any </p></td> 3509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{} </p></td> 3519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>After {@link #release()}, the object is no longer available. </p></td></tr> 3529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>reset </p></td> 35332f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <td>{Idle, Initialized, Prepared, Started, Paused, Stopped, 3549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * PlaybackCompleted, Error}</p></td> 3559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{}</p></td> 3569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>After {@link #reset()}, the object is like being just created.</p></td></tr> 3579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>seekTo </p></td> 3589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{Prepared, Started, Paused, PlaybackCompleted} </p></td> 3599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{Idle, Initialized, Stopped, Error}</p></td> 36032f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <td>Successful invoke of this method in a valid state does not change 36132f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * the state. Calling this method in an invalid state transfers the 3629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * object to the <em>Error</em> state. </p></td></tr> 36317cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent * <tr><td>setAudioSessionId </p></td> 36417cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent * <td>{Idle} </p></td> 36517cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent * <td>{Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted, 36617cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent * Error} </p></td> 36717cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent * <td>This method must be called in idle state as the audio session ID must be known before 36817cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent * calling setDataSource. Calling it does not change the object state. </p></td></tr> 3699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>setAudioStreamType </p></td> 37032f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <td>{Idle, Initialized, Stopped, Prepared, Started, Paused, 3719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * PlaybackCompleted}</p></td> 3729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{Error}</p></td> 3739d96354d7055cd165d7d5625990f810f46339e52James Dong * <td>Successful invoke of this method does not change the state. In order for the 3749d96354d7055cd165d7d5625990f810f46339e52James Dong * target audio stream type to become effective, this method must be called before 3759d96354d7055cd165d7d5625990f810f46339e52James Dong * prepare() or prepareAsync().</p></td></tr> 37617cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent * <tr><td>setAuxEffectSendLevel </p></td> 37717cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent * <td>any</p></td> 37817cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent * <td>{} </p></td> 37917cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent * <td>Calling this method does not change the object state. </p></td></tr> 3809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>setDataSource </p></td> 3819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{Idle} </p></td> 3829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted, 3839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Error} </p></td> 38432f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <td>Successful invoke of this method in a valid state transfers the 38532f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * object to the <em>Initialized</em> state. Calling this method in an 3869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * invalid state throws an IllegalStateException.</p></td></tr> 3879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>setDisplay </p></td> 3889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>any </p></td> 3899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{} </p></td> 3909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>This method can be called in any state and calling it does not change 3919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the object state. </p></td></tr> 392b283dc64bc97f53804108cebf5b904eb4fb77155Jamie Gennis * <tr><td>setSurface </p></td> 393cc562a3576a6a8096626387472e05e8bee03352aGlenn Kasten * <td>any </p></td> 394cc562a3576a6a8096626387472e05e8bee03352aGlenn Kasten * <td>{} </p></td> 395cc562a3576a6a8096626387472e05e8bee03352aGlenn Kasten * <td>This method can be called in any state and calling it does not change 396cc562a3576a6a8096626387472e05e8bee03352aGlenn Kasten * the object state. </p></td></tr> 397454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * <tr><td>setVideoScalingMode </p></td> 398454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * <td>{Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted} </p></td> 399454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * <td>{Idle, Error}</p></td> 400454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * <td>Successful invoke of this method does not change the state.</p></td></tr> 4019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>setLooping </p></td> 40232f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <td>{Idle, Initialized, Stopped, Prepared, Started, Paused, 4039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * PlaybackCompleted}</p></td> 4049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{Error}</p></td> 40532f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <td>Successful invoke of this method in a valid state does not change 40632f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * the state. Calling this method in an 4079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * invalid state transfers the object to the <em>Error</em> state.</p></td></tr> 4089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>isLooping </p></td> 4099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>any </p></td> 4109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{} </p></td> 4119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>This method can be called in any state and calling it does not change 4129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the object state. </p></td></tr> 4139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>setOnBufferingUpdateListener </p></td> 4149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>any </p></td> 4159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{} </p></td> 4169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>This method can be called in any state and calling it does not change 4179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the object state. </p></td></tr> 4189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>setOnCompletionListener </p></td> 4199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>any </p></td> 4209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{} </p></td> 4219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>This method can be called in any state and calling it does not change 4229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the object state. </p></td></tr> 4239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>setOnErrorListener </p></td> 4249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>any </p></td> 4259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{} </p></td> 4269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>This method can be called in any state and calling it does not change 4279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the object state. </p></td></tr> 4289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>setOnPreparedListener </p></td> 4299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>any </p></td> 4309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{} </p></td> 4319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>This method can be called in any state and calling it does not change 4329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the object state. </p></td></tr> 4339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>setOnSeekCompleteListener </p></td> 4349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>any </p></td> 4359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{} </p></td> 4369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>This method can be called in any state and calling it does not change 4379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the object state. </p></td></tr> 4389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>setScreenOnWhilePlaying</></td> 4399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>any </p></td> 4409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{} </p></td> 4419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>This method can be called in any state and calling it does not change 4429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the object state. </p></td></tr> 4439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>setVolume </p></td> 44432f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <td>{Idle, Initialized, Stopped, Prepared, Started, Paused, 4459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * PlaybackCompleted}</p></td> 4469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{Error}</p></td> 4479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>Successful invoke of this method does not change the state. 4489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>setWakeMode </p></td> 4499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>any </p></td> 4509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{} </p></td> 4519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>This method can be called in any state and calling it does not change 4529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the object state.</p></td></tr> 4539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>start </p></td> 4549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{Prepared, Started, Paused, PlaybackCompleted}</p></td> 4559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{Idle, Initialized, Stopped, Error}</p></td> 45632f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <td>Successful invoke of this method in a valid state transfers the 45732f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * object to the <em>Started</em> state. Calling this method in an 4589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * invalid state transfers the object to the <em>Error</em> state.</p></td></tr> 4599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <tr><td>stop </p></td> 4609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{Prepared, Started, Stopped, Paused, PlaybackCompleted}</p></td> 4619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <td>{Idle, Initialized, Error}</p></td> 46232f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * <td>Successful invoke of this method in a valid state transfers the 46332f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * object to the <em>Stopped</em> state. Calling this method in an 4649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * invalid state transfers the object to the <em>Error</em> state.</p></td></tr> 46541f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * <tr><td>getTrackInfo </p></td> 46641f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * <td>{Prepared, Started, Stopped, Paused, PlaybackCompleted}</p></td> 46741f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * <td>{Idle, Initialized, Error}</p></td> 46841f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * <td>Successful invoke of this method does not change the state.</p></td></tr> 4697a9734d769d97470ce6fac0594dd007804d33432James Dong * <tr><td>addTimedTextSource </p></td> 47041f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * <td>{Prepared, Started, Stopped, Paused, PlaybackCompleted}</p></td> 47141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * <td>{Idle, Initialized, Error}</p></td> 47241f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * <td>Successful invoke of this method does not change the state.</p></td></tr> 47341f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * <tr><td>selectTrack </p></td> 47441f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * <td>{Prepared, Started, Stopped, Paused, PlaybackCompleted}</p></td> 47541f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * <td>{Idle, Initialized, Error}</p></td> 47641f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * <td>Successful invoke of this method does not change the state.</p></td></tr> 4777a9734d769d97470ce6fac0594dd007804d33432James Dong * <tr><td>deselectTrack </p></td> 47841f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * <td>{Prepared, Started, Stopped, Paused, PlaybackCompleted}</p></td> 47941f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * <td>{Idle, Initialized, Error}</p></td> 48041f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * <td>Successful invoke of this method does not change the state.</p></td></tr> 481619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent * 4829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </table> 4839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 4849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <a name="Permissions"></a> 4859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <h3>Permissions</h3> 4869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p>One may need to declare a corresponding WAKE_LOCK permission {@link 4879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * android.R.styleable#AndroidManifestUsesPermission <uses-permission>} 4889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * element. 4899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 490fc301b0bb5c635c6bb51b48c504a8db5f9010e5cDave Burke * <p>This class requires the {@link android.Manifest.permission#INTERNET} permission 491fc301b0bb5c635c6bb51b48c504a8db5f9010e5cDave Burke * when used with network-based content. 492fc301b0bb5c635c6bb51b48c504a8db5f9010e5cDave Burke * 4939ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * <a name="Callbacks"></a> 4949ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * <h3>Callbacks</h3> 4959ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * <p>Applications may want to register for informational and error 4969ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * events in order to be informed of some internal state update and 4979ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * possible runtime errors during playback or streaming. Registration for 4989ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * these events is done by properly setting the appropriate listeners (via calls 4999ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * to 5009ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * {@link #setOnPreparedListener(OnPreparedListener)}setOnPreparedListener, 5019ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * {@link #setOnVideoSizeChangedListener(OnVideoSizeChangedListener)}setOnVideoSizeChangedListener, 5029ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * {@link #setOnSeekCompleteListener(OnSeekCompleteListener)}setOnSeekCompleteListener, 5039ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * {@link #setOnCompletionListener(OnCompletionListener)}setOnCompletionListener, 504d52ad9ca8d36afa76161c61b65a71d70977c0d3fJames Dong * {@link #setOnBufferingUpdateListener(OnBufferingUpdateListener)}setOnBufferingUpdateListener, 5059ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * {@link #setOnInfoListener(OnInfoListener)}setOnInfoListener, 5069ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * {@link #setOnErrorListener(OnErrorListener)}setOnErrorListener, etc). 5079ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * In order to receive the respective callback 5089ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * associated with these listeners, applications are required to create 5099ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * MediaPlayer objects on a thread with its own Looper running (main UI 5109ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * thread by default has a Looper running). 5119ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * 5129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 5139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpublic class MediaPlayer 51432f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania{ 5159193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania /** 5169193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania Constant to retrieve only the new metadata since the last 5179193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania call. 5189193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania // FIXME: unhide. 5199193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania // FIXME: add link to getMetadata(boolean, boolean) 5209193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania {@hide} 5219193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania */ 5229193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania public static final boolean METADATA_UPDATE_ONLY = true; 5239193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania 5249193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania /** 5259193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania Constant to retrieve all the metadata. 5269193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania // FIXME: unhide. 5279193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania // FIXME: add link to getMetadata(boolean, boolean) 5289193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania {@hide} 5299193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania */ 5309193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania public static final boolean METADATA_ALL = false; 5319193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania 5329193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania /** 5339193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania Constant to enable the metadata filter during retrieval. 5349193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania // FIXME: unhide. 5359193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania // FIXME: add link to getMetadata(boolean, boolean) 5369193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania {@hide} 5379193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania */ 5389193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania public static final boolean APPLY_METADATA_FILTER = true; 5399193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania 5409193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania /** 5419193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania Constant to disable the metadata filter during retrieval. 5429193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania // FIXME: unhide. 5439193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania // FIXME: add link to getMetadata(boolean, boolean) 5449193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania {@hide} 5459193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania */ 5469193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania public static final boolean BYPASS_METADATA_FILTER = false; 5479193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania 5489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project static { 5499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project System.loadLibrary("media_jni"); 5504935d05eaa306cef88cf0ab13eca386f270409ecMarco Nelissen native_init(); 5519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 55232f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 5539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private final static String TAG = "MediaPlayer"; 55420cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania // Name of the remote interface for the media player. Must be kept 55520cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania // in sync with the 2nd parameter of the IMPLEMENT_META_INTERFACE 55620cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania // macro invocation in IMediaPlayer.cpp 55720cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania private final static String IMEDIA_PLAYER = "android.media.IMediaPlayer"; 55832f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 5599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private int mNativeContext; // accessed by native methods 5601ee60119c4fa51ebfa781cf5fdc33f192e8551b8Ted Bonkenburg private int mNativeSurfaceTexture; // accessed by native methods 5619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private int mListenerContext; // accessed by native methods 5621ee60119c4fa51ebfa781cf5fdc33f192e8551b8Ted Bonkenburg private SurfaceHolder mSurfaceHolder; 5639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private EventHandler mEventHandler; 5649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private PowerManager.WakeLock mWakeLock = null; 5659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private boolean mScreenOnWhilePlaying; 5669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private boolean mStayAwake; 56732f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 5689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 56932f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * Default constructor. Consider using one of the create() methods for 5709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * synchronously instantiating a MediaPlayer from a Uri or resource. 5719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p>When done with the MediaPlayer, you should call {@link #release()}, 5729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * to free the resources. If not released, too many MediaPlayer instances may 5739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * result in an exception.</p> 5749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 5759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public MediaPlayer() { 57632f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 5779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Looper looper; 5789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if ((looper = Looper.myLooper()) != null) { 5799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mEventHandler = new EventHandler(this, looper); 5809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } else if ((looper = Looper.getMainLooper()) != null) { 5819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mEventHandler = new EventHandler(this, looper); 5829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } else { 5839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mEventHandler = null; 5849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 5859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 5869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /* Native setup requires a weak reference to our object. 5879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * It's easier to create it here than in C++. 5889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 5899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_setup(new WeakReference<MediaPlayer>(this)); 5909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 5918b0b174198793cabb2b3fcc015f9bfdc9d5082b5Dave Sparks 5928b0b174198793cabb2b3fcc015f9bfdc9d5082b5Dave Sparks /* 5931ee60119c4fa51ebfa781cf5fdc33f192e8551b8Ted Bonkenburg * Update the MediaPlayer SurfaceTexture. 5941ee60119c4fa51ebfa781cf5fdc33f192e8551b8Ted Bonkenburg * Call after setting a new display surface. 5958b0b174198793cabb2b3fcc015f9bfdc9d5082b5Dave Sparks */ 5961ee60119c4fa51ebfa781cf5fdc33f192e8551b8Ted Bonkenburg private native void _setVideoSurface(Surface surface); 59732f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 59841f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang /* Do not change these values (starting with INVOKE_ID) without updating 59941f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * their counterparts in include/media/mediaplayer.h! 60041f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang */ 60141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang private static final int INVOKE_ID_GET_TRACK_INFO = 1; 60241f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang private static final int INVOKE_ID_ADD_EXTERNAL_SOURCE = 2; 60341f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang private static final int INVOKE_ID_ADD_EXTERNAL_SOURCE_FD = 3; 60441f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang private static final int INVOKE_ID_SELECT_TRACK = 4; 6057a9734d769d97470ce6fac0594dd007804d33432James Dong private static final int INVOKE_ID_DESELECT_TRACK = 5; 606454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong private static final int INVOKE_ID_SET_VIDEO_SCALE_MODE = 6; 60741f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang 6089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 60920cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania * Create a request parcel which can be routed to the native media 61020cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania * player using {@link #invoke(Parcel, Parcel)}. The Parcel 61120cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania * returned has the proper InterfaceToken set. The caller should 61220cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania * not overwrite that token, i.e it can only append data to the 61320cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania * Parcel. 61420cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania * 61520cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania * @return A parcel suitable to hold a request for the native 61620cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania * player. 6173b49e9b52558b5c45240d098410bd5afbd29e1fegwang@google.com * {@hide} 61820cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania */ 61920cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania public Parcel newRequest() { 62020cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania Parcel parcel = Parcel.obtain(); 62120cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania parcel.writeInterfaceToken(IMEDIA_PLAYER); 62220cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania return parcel; 62320cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania } 62420cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania 62520cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania /** 62620cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania * Invoke a generic method on the native player using opaque 62720cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania * parcels for the request and reply. Both payloads' format is a 62820cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania * convention between the java caller and the native player. 62920cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania * Must be called after setDataSource to make sure a native player 6307a9734d769d97470ce6fac0594dd007804d33432James Dong * exists. On failure, a RuntimeException is thrown. 63120cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania * 63220cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania * @param request Parcel with the data for the extension. The 63320cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania * caller must use {@link #newRequest()} to get one. 63420cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania * 6354a51c20ce607c74914f90fd897f04080121ac13bDianne Hackborn * @param reply Output parcel with the data returned by the 63620cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania * native player. 63720cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania * 6383b49e9b52558b5c45240d098410bd5afbd29e1fegwang@google.com * {@hide} 63920cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania */ 6407a9734d769d97470ce6fac0594dd007804d33432James Dong public void invoke(Parcel request, Parcel reply) { 64120cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania int retcode = native_invoke(request, reply); 64220cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania reply.setDataPosition(0); 6437a9734d769d97470ce6fac0594dd007804d33432James Dong if (retcode != 0) { 6447a9734d769d97470ce6fac0594dd007804d33432James Dong throw new RuntimeException("failure code: " + retcode); 6457a9734d769d97470ce6fac0594dd007804d33432James Dong } 64620cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania } 64720cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania 64820cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania /** 649cc562a3576a6a8096626387472e05e8bee03352aGlenn Kasten * Sets the {@link SurfaceHolder} to use for displaying the video 65091784c996f95483e3041169215c0d6635e27ffccGloria Wang * portion of the media. 65132f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 6520de171b0d490a5928d54d2fb67c912d140aac643Ted Bonkenburg * Either a surface holder or surface must be set if a display or video sink 653b283dc64bc97f53804108cebf5b904eb4fb77155Jamie Gennis * is needed. Not calling this method or {@link #setSurface(Surface)} 654cc562a3576a6a8096626387472e05e8bee03352aGlenn Kasten * when playing back a video will result in only the audio track being played. 65591784c996f95483e3041169215c0d6635e27ffccGloria Wang * A null surface holder or surface will result in only the audio track being 65691784c996f95483e3041169215c0d6635e27ffccGloria Wang * played. 6575c2faf3dc310b100707eb9e32e1e5ae8ceffd0c6Glenn Kasten * 6585c2faf3dc310b100707eb9e32e1e5ae8ceffd0c6Glenn Kasten * @param sh the SurfaceHolder to use for video display 659cc562a3576a6a8096626387472e05e8bee03352aGlenn Kasten */ 6609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setDisplay(SurfaceHolder sh) { 6619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mSurfaceHolder = sh; 6621ee60119c4fa51ebfa781cf5fdc33f192e8551b8Ted Bonkenburg Surface surface; 6638b0b174198793cabb2b3fcc015f9bfdc9d5082b5Dave Sparks if (sh != null) { 6641ee60119c4fa51ebfa781cf5fdc33f192e8551b8Ted Bonkenburg surface = sh.getSurface(); 6658b0b174198793cabb2b3fcc015f9bfdc9d5082b5Dave Sparks } else { 6661ee60119c4fa51ebfa781cf5fdc33f192e8551b8Ted Bonkenburg surface = null; 6678b0b174198793cabb2b3fcc015f9bfdc9d5082b5Dave Sparks } 6681ee60119c4fa51ebfa781cf5fdc33f192e8551b8Ted Bonkenburg _setVideoSurface(surface); 669cc562a3576a6a8096626387472e05e8bee03352aGlenn Kasten updateSurfaceScreenOn(); 670cc562a3576a6a8096626387472e05e8bee03352aGlenn Kasten } 671cc562a3576a6a8096626387472e05e8bee03352aGlenn Kasten 672cc562a3576a6a8096626387472e05e8bee03352aGlenn Kasten /** 6730de171b0d490a5928d54d2fb67c912d140aac643Ted Bonkenburg * Sets the {@link Surface} to be used as the sink for the video portion of 674b283dc64bc97f53804108cebf5b904eb4fb77155Jamie Gennis * the media. This is similar to {@link #setDisplay(SurfaceHolder)}, but 675b283dc64bc97f53804108cebf5b904eb4fb77155Jamie Gennis * does not support {@link #setScreenOnWhilePlaying(boolean)}. Setting a 676b283dc64bc97f53804108cebf5b904eb4fb77155Jamie Gennis * Surface will un-set any Surface or SurfaceHolder that was previously set. 67791784c996f95483e3041169215c0d6635e27ffccGloria Wang * A null surface will result in only the audio track being played. 6780de171b0d490a5928d54d2fb67c912d140aac643Ted Bonkenburg * 679b283dc64bc97f53804108cebf5b904eb4fb77155Jamie Gennis * If the Surface sends frames to a {@link SurfaceTexture}, the timestamps 680b283dc64bc97f53804108cebf5b904eb4fb77155Jamie Gennis * returned from {@link SurfaceTexture#getTimestamp()} will have an 681b283dc64bc97f53804108cebf5b904eb4fb77155Jamie Gennis * unspecified zero point. These timestamps cannot be directly compared 682b283dc64bc97f53804108cebf5b904eb4fb77155Jamie Gennis * between different media sources, different instances of the same media 683b283dc64bc97f53804108cebf5b904eb4fb77155Jamie Gennis * source, or multiple runs of the same program. The timestamp is normally 684b283dc64bc97f53804108cebf5b904eb4fb77155Jamie Gennis * monotonically increasing and is unaffected by time-of-day adjustments, 685b283dc64bc97f53804108cebf5b904eb4fb77155Jamie Gennis * but it is reset when the position is set. 6860de171b0d490a5928d54d2fb67c912d140aac643Ted Bonkenburg * 687b283dc64bc97f53804108cebf5b904eb4fb77155Jamie Gennis * @param surface The {@link Surface} to be used for the video portion of 688b283dc64bc97f53804108cebf5b904eb4fb77155Jamie Gennis * the media. 6890de171b0d490a5928d54d2fb67c912d140aac643Ted Bonkenburg */ 6900de171b0d490a5928d54d2fb67c912d140aac643Ted Bonkenburg public void setSurface(Surface surface) { 6911ee60119c4fa51ebfa781cf5fdc33f192e8551b8Ted Bonkenburg if (mScreenOnWhilePlaying && surface != null) { 6920de171b0d490a5928d54d2fb67c912d140aac643Ted Bonkenburg Log.w(TAG, "setScreenOnWhilePlaying(true) is ineffective for Surface"); 6930de171b0d490a5928d54d2fb67c912d140aac643Ted Bonkenburg } 6940de171b0d490a5928d54d2fb67c912d140aac643Ted Bonkenburg mSurfaceHolder = null; 6951ee60119c4fa51ebfa781cf5fdc33f192e8551b8Ted Bonkenburg _setVideoSurface(surface); 6960de171b0d490a5928d54d2fb67c912d140aac643Ted Bonkenburg updateSurfaceScreenOn(); 6970de171b0d490a5928d54d2fb67c912d140aac643Ted Bonkenburg } 6980de171b0d490a5928d54d2fb67c912d140aac643Ted Bonkenburg 699454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong /* Do not change these video scaling mode values below without updating 700454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * their counterparts in system/window.h! Please do not forget to update 701454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * {@link #isVideoScalingModeSupported} when new video scaling modes 702454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * are added. 703454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong */ 704454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong /** 705454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * Specifies a video scaling mode. The content is stretched to the 706454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * surface rendering area. When the surface has the same aspect ratio 707454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * as the content, the aspect ratio of the content is maintained; 708454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * otherwise, the aspect ratio of the content is not maintained when video 709a45746efadd11bb7dfab026fb3c81a25fae74ca4Jeff Smith * is being rendered. Unlike {@link #VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING}, 710454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * there is no content cropping with this video scaling mode. 711454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong */ 712454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong public static final int VIDEO_SCALING_MODE_SCALE_TO_FIT = 1; 713454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong 714454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong /** 715454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * Specifies a video scaling mode. The content is scaled, maintaining 716454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * its aspect ratio. The whole surface area is always used. When the 717454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * aspect ratio of the content is the same as the surface, no content 718454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * is cropped; otherwise, content is cropped to fit the surface. 719454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong */ 720454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong public static final int VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING = 2; 721454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong /** 722454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * Sets video scaling mode. To make the target video scaling mode 723454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * effective during playback, this method must be called after 724454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * data source is set. If not called, the default video 725454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * scaling mode is {@link #VIDEO_SCALING_MODE_SCALE_TO_FIT}. 726454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * 727454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * <p> The supported video scaling modes are: 728454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * <ul> 729454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * <li> {@link #VIDEO_SCALING_MODE_SCALE_TO_FIT} 730454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * <li> {@link #VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING} 731454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * </ul> 732454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * 733454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * @param mode target video scaling mode. Most be one of the supported 734454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * video scaling modes; otherwise, IllegalArgumentException will be thrown. 735454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * 736454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * @see MediaPlayer#VIDEO_SCALING_MODE_SCALE_TO_FIT 737454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * @see MediaPlayer#VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING 738454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong */ 739454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong public void setVideoScalingMode(int mode) { 74079a9cd40f5ebb2453cb982bc17d9797a1cbdf8d8Bryan Mawhinney if (!isVideoScalingModeSupported(mode)) { 741454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong final String msg = "Scaling mode " + mode + " is not supported"; 742454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong throw new IllegalArgumentException(msg); 743454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong } 744454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong Parcel request = Parcel.obtain(); 745454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong Parcel reply = Parcel.obtain(); 746be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang try { 747be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang request.writeInterfaceToken(IMEDIA_PLAYER); 748be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang request.writeInt(INVOKE_ID_SET_VIDEO_SCALE_MODE); 749c3a5cf9aab3d409445accb2a93c09e6b4140d196Bryan Mawhinney request.writeInt(mode); 750be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang invoke(request, reply); 751be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang } finally { 752be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang request.recycle(); 753be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang reply.recycle(); 754be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang } 755454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong } 756454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong 7579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 7589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Convenience method to create a MediaPlayer for a given Uri. 7599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * On success, {@link #prepare()} will already have been called and must not be called again. 7609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p>When done with the MediaPlayer, you should call {@link #release()}, 7619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * to free the resources. If not released, too many MediaPlayer instances will 7629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * result in an exception.</p> 76332f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 76432f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * @param context the Context to use 7659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param uri the Uri from which to get the datasource 7669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return a MediaPlayer object, or null if creation failed 7679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 7689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static MediaPlayer create(Context context, Uri uri) { 7699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return create (context, uri, null); 7709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 77132f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 7729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 7739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Convenience method to create a MediaPlayer for a given Uri. 7749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * On success, {@link #prepare()} will already have been called and must not be called again. 7759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p>When done with the MediaPlayer, you should call {@link #release()}, 7769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * to free the resources. If not released, too many MediaPlayer instances will 7779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * result in an exception.</p> 77832f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 77932f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * @param context the Context to use 7809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param uri the Uri from which to get the datasource 7819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param holder the SurfaceHolder to use for displaying the video 7829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return a MediaPlayer object, or null if creation failed 7839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 7849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static MediaPlayer create(Context context, Uri uri, SurfaceHolder holder) { 78532f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 7869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 7879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project MediaPlayer mp = new MediaPlayer(); 7889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mp.setDataSource(context, uri); 7899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (holder != null) { 7909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mp.setDisplay(holder); 7919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 7929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mp.prepare(); 7939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return mp; 7949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (IOException ex) { 7959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Log.d(TAG, "create failed:", ex); 7969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // fall through 7979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (IllegalArgumentException ex) { 7989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Log.d(TAG, "create failed:", ex); 7999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // fall through 8009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (SecurityException ex) { 8019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Log.d(TAG, "create failed:", ex); 8029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // fall through 8039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 8049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 8059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return null; 8069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 8079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 808cc562a3576a6a8096626387472e05e8bee03352aGlenn Kasten // Note no convenience method to create a MediaPlayer with SurfaceTexture sink. 809cc562a3576a6a8096626387472e05e8bee03352aGlenn Kasten 8109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 8119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Convenience method to create a MediaPlayer for a given resource id. 8129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * On success, {@link #prepare()} will already have been called and must not be called again. 8139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p>When done with the MediaPlayer, you should call {@link #release()}, 8149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * to free the resources. If not released, too many MediaPlayer instances will 8159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * result in an exception.</p> 81632f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 81732f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * @param context the Context to use 81832f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * @param resid the raw resource id (<var>R.raw.<something></var>) for 8199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the resource to use as the datasource 8209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return a MediaPlayer object, or null if creation failed 8219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 8229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static MediaPlayer create(Context context, int resid) { 8239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 8249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project AssetFileDescriptor afd = context.getResources().openRawResourceFd(resid); 8259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (afd == null) return null; 8269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 8279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project MediaPlayer mp = new MediaPlayer(); 8289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); 8299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project afd.close(); 8309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mp.prepare(); 8319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return mp; 8329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (IOException ex) { 8339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Log.d(TAG, "create failed:", ex); 8349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // fall through 8359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (IllegalArgumentException ex) { 8369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Log.d(TAG, "create failed:", ex); 8379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // fall through 8389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (SecurityException ex) { 8399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Log.d(TAG, "create failed:", ex); 8409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // fall through 8419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 8429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return null; 8439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 84432f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 8459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 8469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the data source as a content Uri. 84732f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 8489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param context the Context to use when resolving the Uri 8499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param uri the Content URI of the data you want to play 8509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called in an invalid state 8519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 8529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setDataSource(Context context, Uri uri) 8539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throws IOException, IllegalArgumentException, SecurityException, IllegalStateException { 854256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber setDataSource(context, uri, null); 855256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber } 856256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber 857256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber /** 858256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber * Sets the data source as a content Uri. 859256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber * 860256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber * @param context the Context to use when resolving the Uri 861256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber * @param uri the Content URI of the data you want to play 862256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber * @param headers the headers to be sent together with the request for the data 863256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber * @throws IllegalStateException if it is called in an invalid state 864256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber */ 865256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber public void setDataSource(Context context, Uri uri, Map<String, String> headers) 866256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber throws IOException, IllegalArgumentException, SecurityException, IllegalStateException { 86732f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 8689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project String scheme = uri.getScheme(); 8699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if(scheme == null || scheme.equals("file")) { 8709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project setDataSource(uri.getPath()); 8719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 8729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 8739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 8749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project AssetFileDescriptor fd = null; 8759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 8769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project ContentResolver resolver = context.getContentResolver(); 8779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project fd = resolver.openAssetFileDescriptor(uri, "r"); 8789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (fd == null) { 8799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 8809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 8819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // Note: using getDeclaredLength so that our behavior is the same 8829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // as previous versions when the content provider is returning 8839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // a full file. 8849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (fd.getDeclaredLength() < 0) { 8859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project setDataSource(fd.getFileDescriptor()); 8869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } else { 8879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getDeclaredLength()); 8889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 8899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 8909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (SecurityException ex) { 8919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } catch (IOException ex) { 8929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } finally { 8939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (fd != null) { 8949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project fd.close(); 8959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 8969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 897fc301b0bb5c635c6bb51b48c504a8db5f9010e5cDave Burke 898a2df60598ac0158468ce242498b7bd3cb9383e13Marco Nelissen Log.d(TAG, "Couldn't open file on client side, trying server side"); 899256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber setDataSource(uri.toString(), headers); 9009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 9019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 9029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 9049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the data source (file-path or http/rtsp URL) to use. 90532f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 9069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param path the path of the file, or the http/rtsp URL of the stream you want to play 9079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called in an invalid state 90855d1eea69451ee246a41e12a14be42878773e3cbGlenn Kasten * 90955d1eea69451ee246a41e12a14be42878773e3cbGlenn Kasten * <p>When <code>path</code> refers to a local file, the file may actually be opened by a 91055d1eea69451ee246a41e12a14be42878773e3cbGlenn Kasten * process other than the calling application. This implies that the pathname 91155d1eea69451ee246a41e12a14be42878773e3cbGlenn Kasten * should be an absolute path (as any other process runs with unspecified current working 91255d1eea69451ee246a41e12a14be42878773e3cbGlenn Kasten * directory), and that the pathname should reference a world-readable file. 91355d1eea69451ee246a41e12a14be42878773e3cbGlenn Kasten * As an alternative, the application could first open the file for reading, 91455d1eea69451ee246a41e12a14be42878773e3cbGlenn Kasten * and then use the file descriptor form {@link #setDataSource(FileDescriptor)}. 9159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 916e00b6f3a57d4b480ce674468de93555269bbd71aJames Dong public void setDataSource(String path) 917e00b6f3a57d4b480ce674468de93555269bbd71aJames Dong throws IOException, IllegalArgumentException, SecurityException, IllegalStateException { 918e00b6f3a57d4b480ce674468de93555269bbd71aJames Dong setDataSource(path, null, null); 919e00b6f3a57d4b480ce674468de93555269bbd71aJames Dong } 9209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 922256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber * Sets the data source (file-path or http/rtsp URL) to use. 923256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber * 924256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber * @param path the path of the file, or the http/rtsp URL of the stream you want to play 925256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber * @param headers the headers associated with the http request for the stream you want to play 926256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber * @throws IllegalStateException if it is called in an invalid state 927256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber * @hide pending API council 928256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber */ 92917524dc0d296146c8ffb3f692dc8ab05fee5b1e0James Dong public void setDataSource(String path, Map<String, String> headers) 930fc301b0bb5c635c6bb51b48c504a8db5f9010e5cDave Burke throws IOException, IllegalArgumentException, SecurityException, IllegalStateException 93117524dc0d296146c8ffb3f692dc8ab05fee5b1e0James Dong { 932e4e7b48e33fbdfc00f184c18c50e9f3d6335c5acAndreas Huber String[] keys = null; 933e4e7b48e33fbdfc00f184c18c50e9f3d6335c5acAndreas Huber String[] values = null; 934e4e7b48e33fbdfc00f184c18c50e9f3d6335c5acAndreas Huber 935e4e7b48e33fbdfc00f184c18c50e9f3d6335c5acAndreas Huber if (headers != null) { 936e4e7b48e33fbdfc00f184c18c50e9f3d6335c5acAndreas Huber keys = new String[headers.size()]; 937e4e7b48e33fbdfc00f184c18c50e9f3d6335c5acAndreas Huber values = new String[headers.size()]; 938e4e7b48e33fbdfc00f184c18c50e9f3d6335c5acAndreas Huber 939e4e7b48e33fbdfc00f184c18c50e9f3d6335c5acAndreas Huber int i = 0; 940e4e7b48e33fbdfc00f184c18c50e9f3d6335c5acAndreas Huber for (Map.Entry<String, String> entry: headers.entrySet()) { 941e4e7b48e33fbdfc00f184c18c50e9f3d6335c5acAndreas Huber keys[i] = entry.getKey(); 942e4e7b48e33fbdfc00f184c18c50e9f3d6335c5acAndreas Huber values[i] = entry.getValue(); 943e4e7b48e33fbdfc00f184c18c50e9f3d6335c5acAndreas Huber ++i; 944e4e7b48e33fbdfc00f184c18c50e9f3d6335c5acAndreas Huber } 94517524dc0d296146c8ffb3f692dc8ab05fee5b1e0James Dong } 946e00b6f3a57d4b480ce674468de93555269bbd71aJames Dong setDataSource(path, keys, values); 947e00b6f3a57d4b480ce674468de93555269bbd71aJames Dong } 948e00b6f3a57d4b480ce674468de93555269bbd71aJames Dong 949e00b6f3a57d4b480ce674468de93555269bbd71aJames Dong private void setDataSource(String path, String[] keys, String[] values) 950e00b6f3a57d4b480ce674468de93555269bbd71aJames Dong throws IOException, IllegalArgumentException, SecurityException, IllegalStateException { 951e00b6f3a57d4b480ce674468de93555269bbd71aJames Dong File file = new File(path); 952e00b6f3a57d4b480ce674468de93555269bbd71aJames Dong if (file.exists()) { 953e00b6f3a57d4b480ce674468de93555269bbd71aJames Dong FileInputStream is = new FileInputStream(file); 954e00b6f3a57d4b480ce674468de93555269bbd71aJames Dong FileDescriptor fd = is.getFD(); 955e00b6f3a57d4b480ce674468de93555269bbd71aJames Dong setDataSource(fd); 956e00b6f3a57d4b480ce674468de93555269bbd71aJames Dong is.close(); 957e00b6f3a57d4b480ce674468de93555269bbd71aJames Dong } else { 958e00b6f3a57d4b480ce674468de93555269bbd71aJames Dong _setDataSource(path, keys, values); 959e00b6f3a57d4b480ce674468de93555269bbd71aJames Dong } 96017524dc0d296146c8ffb3f692dc8ab05fee5b1e0James Dong } 96117524dc0d296146c8ffb3f692dc8ab05fee5b1e0James Dong 96217524dc0d296146c8ffb3f692dc8ab05fee5b1e0James Dong private native void _setDataSource( 96317524dc0d296146c8ffb3f692dc8ab05fee5b1e0James Dong String path, String[] keys, String[] values) 964fc301b0bb5c635c6bb51b48c504a8db5f9010e5cDave Burke throws IOException, IllegalArgumentException, SecurityException, IllegalStateException; 965256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber 966256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber /** 9679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the data source (FileDescriptor) to use. It is the caller's responsibility 9689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * to close the file descriptor. It is safe to do so as soon as this call returns. 96932f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 9709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param fd the FileDescriptor for the file you want to play 9719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called in an invalid state 9729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 97332f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania public void setDataSource(FileDescriptor fd) 9749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throws IOException, IllegalArgumentException, IllegalStateException { 9759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // intentionally less than LONG_MAX 9769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project setDataSource(fd, 0, 0x7ffffffffffffffL); 9779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 97832f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 9799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 9806ab180aa65d2b4f155518af0ac7bb2777f9ce61fKenny Root * Sets the data source (FileDescriptor) to use. The FileDescriptor must be 9816ab180aa65d2b4f155518af0ac7bb2777f9ce61fKenny Root * seekable (N.B. a LocalSocket is not seekable). It is the caller's responsibility 9829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * to close the file descriptor. It is safe to do so as soon as this call returns. 98332f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 9849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param fd the FileDescriptor for the file you want to play 9859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param offset the offset into the file where the data to be played starts, in bytes 9869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param length the length in bytes of the data to be played 9879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called in an invalid state 9889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 98932f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania public native void setDataSource(FileDescriptor fd, long offset, long length) 9909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throws IOException, IllegalArgumentException, IllegalStateException; 9919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 9939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Prepares the player for playback, synchronously. 99432f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 9959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * After setting the datasource and the display surface, you need to either 9969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * call prepare() or prepareAsync(). For files, it is OK to call prepare(), 9979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * which blocks until MediaPlayer is ready for playback. 99832f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 9999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called in an invalid state 10009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 10019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void prepare() throws IOException, IllegalStateException; 100232f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 10039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 10049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Prepares the player for playback, asynchronously. 100532f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 10069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * After setting the datasource and the display surface, you need to either 10079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * call prepare() or prepareAsync(). For streams, you should call prepareAsync(), 10089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * which returns immediately, rather than blocking until enough data has been 10099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * buffered. 101032f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 10119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called in an invalid state 10129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 10139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void prepareAsync() throws IllegalStateException; 101432f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 10159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 10169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Starts or resumes playback. If playback had previously been paused, 10179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * playback will continue from where it was paused. If playback had 10189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * been stopped, or never started before, playback will start at the 10199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * beginning. 102032f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 10219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called in an invalid state 10229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 10239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void start() throws IllegalStateException { 10249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project stayAwake(true); 10259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project _start(); 10269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 10289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private native void _start() throws IllegalStateException; 102932f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 10309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 103132f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * Stops playback after playback has been stopped or paused. 103232f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 10339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if the internal player engine has not been 10349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * initialized. 10359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 10369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void stop() throws IllegalStateException { 10379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project stayAwake(false); 10389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project _stop(); 10399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 10419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private native void _stop() throws IllegalStateException; 104232f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 10439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 10449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Pauses playback. Call start() to resume. 104532f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 10469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if the internal player engine has not been 10479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * initialized. 10489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 10499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void pause() throws IllegalStateException { 10509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project stayAwake(false); 10519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project _pause(); 10529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 10549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private native void _pause() throws IllegalStateException; 105532f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 10569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 10579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Set the low-level power management behavior for this MediaPlayer. This 10589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * can be used when the MediaPlayer is not playing through a SurfaceHolder 10599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * set with {@link #setDisplay(SurfaceHolder)} and thus can use the 10609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * high-level {@link #setScreenOnWhilePlaying(boolean)} feature. 106132f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 10629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p>This function has the MediaPlayer access the low-level power manager 10639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * service to control the device's power usage while playing is occurring. 10649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * The parameter is a combination of {@link android.os.PowerManager} wake flags. 10659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Use of this method requires {@link android.Manifest.permission#WAKE_LOCK} 10669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * permission. 10679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * By default, no attempt is made to keep the device awake during playback. 106832f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 10699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param context the Context to use 10709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param mode the power/wake mode to set 10719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.os.PowerManager 10729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 10739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setWakeMode(Context context, int mode) { 10749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project boolean washeld = false; 10759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mWakeLock != null) { 10769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mWakeLock.isHeld()) { 10779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project washeld = true; 10789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mWakeLock.release(); 10799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mWakeLock = null; 10819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 10839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE); 10849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mWakeLock = pm.newWakeLock(mode|PowerManager.ON_AFTER_RELEASE, MediaPlayer.class.getName()); 10859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mWakeLock.setReferenceCounted(false); 10869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (washeld) { 10879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mWakeLock.acquire(); 10889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 109032f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 10919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 10929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Control whether we should use the attached SurfaceHolder to keep the 10939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * screen on while video playback is occurring. This is the preferred 10949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * method over {@link #setWakeMode} where possible, since it doesn't 10959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * require that the application have permission for low-level wake lock 10969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * access. 109732f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 10989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param screenOn Supply true to keep the screen on, false to allow it 10999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * to turn off. 11009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 11019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setScreenOnWhilePlaying(boolean screenOn) { 11029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mScreenOnWhilePlaying != screenOn) { 11030de171b0d490a5928d54d2fb67c912d140aac643Ted Bonkenburg if (screenOn && mSurfaceHolder == null) { 11040de171b0d490a5928d54d2fb67c912d140aac643Ted Bonkenburg Log.w(TAG, "setScreenOnWhilePlaying(true) is ineffective without a SurfaceHolder"); 1105817c161ef27b6087c496755768d65fcb4f78f04cGlenn Kasten } 11069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mScreenOnWhilePlaying = screenOn; 11079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project updateSurfaceScreenOn(); 11089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 11099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 111032f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 11119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private void stayAwake(boolean awake) { 11129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mWakeLock != null) { 11139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (awake && !mWakeLock.isHeld()) { 11149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mWakeLock.acquire(); 11159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } else if (!awake && mWakeLock.isHeld()) { 11169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mWakeLock.release(); 11179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 11189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 11199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mStayAwake = awake; 11209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project updateSurfaceScreenOn(); 11219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 112232f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 11239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private void updateSurfaceScreenOn() { 11249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mSurfaceHolder != null) { 11259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mSurfaceHolder.setKeepScreenOn(mScreenOnWhilePlaying && mStayAwake); 11269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 11279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 112832f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 11299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 11309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Returns the width of the video. 113132f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 11329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return the width of the video, or 0 if there is no video, 1133ea5f767246ad201a9e2bba0d657404e002cd7c70Jean-Baptiste Queru * no display surface was set, or the width has not been determined 1134ea5f767246ad201a9e2bba0d657404e002cd7c70Jean-Baptiste Queru * yet. The OnVideoSizeChangedListener can be registered via 1135ea5f767246ad201a9e2bba0d657404e002cd7c70Jean-Baptiste Queru * {@link #setOnVideoSizeChangedListener(OnVideoSizeChangedListener)} 1136ea5f767246ad201a9e2bba0d657404e002cd7c70Jean-Baptiste Queru * to provide a notification when the width is available. 11379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 11389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native int getVideoWidth(); 113932f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 11409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 11419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Returns the height of the video. 114232f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 11439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return the height of the video, or 0 if there is no video, 1144ea5f767246ad201a9e2bba0d657404e002cd7c70Jean-Baptiste Queru * no display surface was set, or the height has not been determined 1145ea5f767246ad201a9e2bba0d657404e002cd7c70Jean-Baptiste Queru * yet. The OnVideoSizeChangedListener can be registered via 1146ea5f767246ad201a9e2bba0d657404e002cd7c70Jean-Baptiste Queru * {@link #setOnVideoSizeChangedListener(OnVideoSizeChangedListener)} 1147ea5f767246ad201a9e2bba0d657404e002cd7c70Jean-Baptiste Queru * to provide a notification when the height is available. 11489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 11499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native int getVideoHeight(); 115032f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 11519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 11529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Checks whether the MediaPlayer is playing. 115332f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 11549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return true if currently playing, false otherwise 1155099fd80f984b8493de58bdda8ea05563261b0af2Scott Main * @throws IllegalStateException if the internal player engine has not been 1156099fd80f984b8493de58bdda8ea05563261b0af2Scott Main * initialized or has been released. 11579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 11589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native boolean isPlaying(); 115932f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 11609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 11619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Seeks to specified time position. 116232f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 11639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param msec the offset in milliseconds from the start to seek to 11649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if the internal player engine has not been 11659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * initialized 11669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 11679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void seekTo(int msec) throws IllegalStateException; 116832f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 11699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 11709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Gets the current playback position. 117132f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 11729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return the current position in milliseconds 11739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 11749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native int getCurrentPosition(); 117532f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 11769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 11779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Gets the duration of the file. 117832f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 11799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return the duration in milliseconds 11809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 11819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native int getDuration(); 118232f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 11839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 11849193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * Gets the media metadata. 11859193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * 11869193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * @param update_only controls whether the full set of available 11879193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * metadata is returned or just the set that changed since the 11889193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * last call. See {@see #METADATA_UPDATE_ONLY} and {@see 11899193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * #METADATA_ALL}. 11909193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * 11919193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * @param apply_filter if true only metadata that matches the 11929193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * filter is returned. See {@see #APPLY_METADATA_FILTER} and {@see 11939193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * #BYPASS_METADATA_FILTER}. 11949193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * 11959193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * @return The metadata, possibly empty. null if an error occured. 11969193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania // FIXME: unhide. 11979193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * {@hide} 11989193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania */ 11999193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania public Metadata getMetadata(final boolean update_only, 12009193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania final boolean apply_filter) { 12015d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania Parcel reply = Parcel.obtain(); 12025d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania Metadata data = new Metadata(); 12035d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania 12045d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania if (!native_getMetadata(update_only, apply_filter, reply)) { 12055d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania reply.recycle(); 12065d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania return null; 12075d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania } 12085d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania 12095d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania // Metadata takes over the parcel, don't recycle it unless 12105d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania // there is an error. 12115d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania if (!data.parse(reply)) { 12125d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania reply.recycle(); 12135d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania return null; 12145d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania } 12155d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania return data; 12169193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania } 12179193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania 12189193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania /** 12199193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * Set a filter for the metadata update notification and update 12209193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * retrieval. The caller provides 2 set of metadata keys, allowed 1221b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania * and blocked. The blocked set always takes precedence over the 1222b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania * allowed one. 12239193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * Metadata.MATCH_ALL and Metadata.MATCH_NONE are 2 sets available as 1224b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania * shorthands to allow/block all or no metadata. 12259193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * 12269193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * By default, there is no filter set. 12279193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * 12289193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * @param allow Is the set of metadata the client is interested 1229b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania * in receiving new notifications for. 1230b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania * @param block Is the set of metadata the client is not interested 1231b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania * in receiving new notifications for. 12329193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * @return The call status code. 12339193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * 12349193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania // FIXME: unhide. 12359193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * {@hide} 12369193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania */ 1237b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania public int setMetadataFilter(Set<Integer> allow, Set<Integer> block) { 1238b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania // Do our serialization manually instead of calling 1239b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania // Parcel.writeArray since the sets are made of the same type 1240b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania // we avoid paying the price of calling writeValue (used by 1241b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania // writeArray) which burns an extra int per element to encode 1242b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania // the type. 1243b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania Parcel request = newRequest(); 1244b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania 1245b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania // The parcel starts already with an interface token. There 1246b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania // are 2 filters. Each one starts with a 4bytes number to 1247b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania // store the len followed by a number of int (4 bytes as well) 1248b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania // representing the metadata type. 1249b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania int capacity = request.dataSize() + 4 * (1 + allow.size() + 1 + block.size()); 1250b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania 1251b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania if (request.dataCapacity() < capacity) { 1252b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania request.setDataCapacity(capacity); 1253b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania } 1254b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania 1255b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania request.writeInt(allow.size()); 1256b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania for(Integer t: allow) { 1257b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania request.writeInt(t); 1258b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania } 1259b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania request.writeInt(block.size()); 1260b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania for(Integer t: block) { 1261b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania request.writeInt(t); 1262b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania } 1263b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania return native_setMetadataFilter(request); 12649193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania } 12659193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania 12669193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania /** 126784b832054552e00257bb04997143ca33d6d100beMarco Nelissen * Set the MediaPlayer to start when this MediaPlayer finishes playback 126884b832054552e00257bb04997143ca33d6d100beMarco Nelissen * (i.e. reaches the end of the stream). 126984b832054552e00257bb04997143ca33d6d100beMarco Nelissen * The media framework will attempt to transition from this player to 127084b832054552e00257bb04997143ca33d6d100beMarco Nelissen * the next as seamlessly as possible. The next player can be set at 127184b832054552e00257bb04997143ca33d6d100beMarco Nelissen * any time before completion. The next player must be prepared by the 127284b832054552e00257bb04997143ca33d6d100beMarco Nelissen * app, and the application should not call start() on it. 127384b832054552e00257bb04997143ca33d6d100beMarco Nelissen * The next MediaPlayer must be different from 'this'. An exception 127484b832054552e00257bb04997143ca33d6d100beMarco Nelissen * will be thrown if next == this. 127584b832054552e00257bb04997143ca33d6d100beMarco Nelissen * The application may call setNextMediaPlayer(null) to indicate no 127684b832054552e00257bb04997143ca33d6d100beMarco Nelissen * next player should be started at the end of playback. 127784b832054552e00257bb04997143ca33d6d100beMarco Nelissen * If the current player is looping, it will keep looping and the next 127884b832054552e00257bb04997143ca33d6d100beMarco Nelissen * player will not be started. 127984b832054552e00257bb04997143ca33d6d100beMarco Nelissen * 128084b832054552e00257bb04997143ca33d6d100beMarco Nelissen * @param next the player to start after this one completes playback. 128184b832054552e00257bb04997143ca33d6d100beMarco Nelissen * 128284b832054552e00257bb04997143ca33d6d100beMarco Nelissen */ 128384b832054552e00257bb04997143ca33d6d100beMarco Nelissen public native void setNextMediaPlayer(MediaPlayer next); 128484b832054552e00257bb04997143ca33d6d100beMarco Nelissen 128584b832054552e00257bb04997143ca33d6d100beMarco Nelissen /** 12869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Releases resources associated with this MediaPlayer object. 12879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * It is considered good practice to call this method when you're 128889ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * done using the MediaPlayer. In particular, whenever an Activity 128989ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * of an application is paused (its onPause() method is called), 129089ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * or stopped (its onStop() method is called), this method should be 129189ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * invoked to release the MediaPlayer object, unless the application 129289ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * has a special need to keep the object around. In addition to 129389ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * unnecessary resources (such as memory and instances of codecs) 129489ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * being held, failure to call this method immediately if a 129589ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * MediaPlayer object is no longer needed may also lead to 129689ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * continuous battery consumption for mobile devices, and playback 129789ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * failure for other applications if no multiple instances of the 129889ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * same codec are supported on a device. Even if multiple instances 129989ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * of the same codec are supported, some performance degradation 130089ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * may be expected when unnecessary multiple instances are used 130189ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * at the same time. 13029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 13039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void release() { 13049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project stayAwake(false); 13059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project updateSurfaceScreenOn(); 13069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mOnPreparedListener = null; 13079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mOnBufferingUpdateListener = null; 13089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mOnCompletionListener = null; 13099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mOnSeekCompleteListener = null; 13109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mOnErrorListener = null; 1311c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project mOnInfoListener = null; 13129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mOnVideoSizeChangedListener = null; 1313162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang mOnTimedTextListener = null; 13149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project _release(); 13159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 13169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 13179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private native void _release(); 131832f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 13199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 13209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Resets the MediaPlayer to its uninitialized state. After calling 13219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this method, you will have to initialize it again by setting the 13229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * data source and calling prepare(). 13239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 13249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void reset() { 13259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project stayAwake(false); 13269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project _reset(); 13279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // make sure none of the listeners get called anymore 13289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mEventHandler.removeCallbacksAndMessages(null); 13299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 133032f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 13319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private native void _reset(); 133232f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 13339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 13349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the audio stream type for this MediaPlayer. See {@link AudioManager} 13359d96354d7055cd165d7d5625990f810f46339e52James Dong * for a list of stream types. Must call this method before prepare() or 13369d96354d7055cd165d7d5625990f810f46339e52James Dong * prepareAsync() in order for the target stream type to become effective 13379d96354d7055cd165d7d5625990f810f46339e52James Dong * thereafter. 133832f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 13399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param streamtype the audio stream type 13409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.media.AudioManager 13419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 13429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setAudioStreamType(int streamtype); 13439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 13449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 13459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the player to be looping or non-looping. 134632f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 13479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param looping whether to loop or not 13489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 13499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setLooping(boolean looping); 13509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 13519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 13529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Checks whether the MediaPlayer is looping or non-looping. 135332f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 13549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return true if the MediaPlayer is currently looping, false otherwise 13559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 13569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native boolean isLooping(); 13579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 13589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 135932f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * Sets the volume on this player. 13609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * This API is recommended for balancing the output of audio streams 13619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * within an application. Unless you are writing an application to 13629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * control user settings, this API should be used in preference to 13639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link AudioManager#setStreamVolume(int, int, int)} which sets the volume of ALL streams of 13649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * a particular type. Note that the passed volume values are raw scalars. 13659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * UI controls should be scaled logarithmically. 13669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 13679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param leftVolume left volume scalar 13689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param rightVolume right volume scalar 13699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 13709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setVolume(float leftVolume, float rightVolume); 13719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 13729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 13739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Currently not implemented, returns null. 13749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @deprecated 13759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @hide 13769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 13779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native Bitmap getFrameAt(int msec) throws IllegalStateException; 137832f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 137920cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania /** 1380619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent * Sets the audio session ID. 1381619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent * 138217cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent * @param sessionId the audio session ID. 1383619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent * The audio session ID is a system wide unique identifier for the audio stream played by 1384619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent * this MediaPlayer instance. 1385619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent * The primary use of the audio session ID is to associate audio effects to a particular 1386619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent * instance of MediaPlayer: if an audio session ID is provided when creating an audio effect, 1387619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent * this effect will be applied only to the audio content of media players within the same 1388619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent * audio session and not to the output mix. 1389619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent * When created, a MediaPlayer instance automatically generates its own audio session ID. 1390619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent * However, it is possible to force this player to be part of an already existing audio session 1391619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent * by calling this method. 1392619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent * This method must be called before one of the overloaded <code> setDataSource </code> methods. 1393619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent * @throws IllegalStateException if it is called in an invalid state 1394619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent */ 1395619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent public native void setAudioSessionId(int sessionId) throws IllegalArgumentException, IllegalStateException; 1396619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent 1397619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent /** 1398619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent * Returns the audio session ID. 1399619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent * 140017cb280e7f1ac3556eac90ab08263712e0348cb9Eric Laurent * @return the audio session ID. {@see #setAudioSessionId(int)} 1401619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent * Note that the audio session ID is 0 only if a problem occured when the MediaPlayer was contructed. 1402619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent */ 1403619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent public native int getAudioSessionId(); 1404619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent 1405619346f902241736d933657a4fe10f10c50a1ba8Eric Laurent /** 14067070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent * Attaches an auxiliary effect to the player. A typical auxiliary effect is a reverberation 14077070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent * effect which can be applied on any sound source that directs a certain amount of its 14087070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent * energy to this effect. This amount is defined by setAuxEffectSendLevel(). 14097070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent * {@see #setAuxEffectSendLevel(float)}. 14101a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * <p>After creating an auxiliary effect (e.g. 14111a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * {@link android.media.audiofx.EnvironmentalReverb}), retrieve its ID with 14121a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * {@link android.media.audiofx.AudioEffect#getId()} and use it when calling this method 14131a5149e5d7f2dddc8b324f7695e69fd89af73c52Eric Laurent * to attach the player to the effect. 14147070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent * <p>To detach the effect from the player, call this method with a null effect id. 14157070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent * <p>This method must be called after one of the overloaded <code> setDataSource </code> 14167070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent * methods. 14177070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent * @param effectId system wide unique id of the effect to attach 14187070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent */ 14197070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent public native void attachAuxEffect(int effectId); 14207070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent 142113bc8cde1c842bea1fa3000a48739a6e22f25a9cGloria Wang /* Do not change these values (starting with KEY_PARAMETER) without updating 142213bc8cde1c842bea1fa3000a48739a6e22f25a9cGloria Wang * their counterparts in include/media/mediaplayer.h! 1423c6091ddd3a22da98b5e83d4b5d864939b451b752Gloria Wang */ 1424c6091ddd3a22da98b5e83d4b5d864939b451b752Gloria Wang 14256ff9b812abe388478bbaba118a580c3f4a30c863Glenn Kasten // There are currently no defined keys usable from Java with get*Parameter. 14266ff9b812abe388478bbaba118a580c3f4a30c863Glenn Kasten // But if any keys are defined, the order must be kept in sync with include/media/mediaplayer.h. 14276ff9b812abe388478bbaba118a580c3f4a30c863Glenn Kasten // private static final int KEY_PARAMETER_... = ...; 14286ff9b812abe388478bbaba118a580c3f4a30c863Glenn Kasten 14297070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent /** 1430d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * Sets the parameter indicated by key. 1431d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * @param key key indicates the parameter to be set. 1432d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * @param value value of the parameter to be set. 1433d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * @return true if the parameter is set successfully, false otherwise 1434d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * {@hide} 1435d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang */ 1436d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang public native boolean setParameter(int key, Parcel value); 1437d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang 1438d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang /** 1439d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * Sets the parameter indicated by key. 1440d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * @param key key indicates the parameter to be set. 1441d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * @param value value of the parameter to be set. 1442d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * @return true if the parameter is set successfully, false otherwise 1443d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * {@hide} 1444d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang */ 1445d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang public boolean setParameter(int key, String value) { 1446d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang Parcel p = Parcel.obtain(); 1447d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang p.writeString(value); 14486ff9b812abe388478bbaba118a580c3f4a30c863Glenn Kasten boolean ret = setParameter(key, p); 14496ff9b812abe388478bbaba118a580c3f4a30c863Glenn Kasten p.recycle(); 14506ff9b812abe388478bbaba118a580c3f4a30c863Glenn Kasten return ret; 1451d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang } 1452d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang 1453d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang /** 1454d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * Sets the parameter indicated by key. 1455d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * @param key key indicates the parameter to be set. 1456d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * @param value value of the parameter to be set. 1457d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * @return true if the parameter is set successfully, false otherwise 1458d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * {@hide} 1459d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang */ 1460d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang public boolean setParameter(int key, int value) { 1461d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang Parcel p = Parcel.obtain(); 1462d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang p.writeInt(value); 14636ff9b812abe388478bbaba118a580c3f4a30c863Glenn Kasten boolean ret = setParameter(key, p); 14646ff9b812abe388478bbaba118a580c3f4a30c863Glenn Kasten p.recycle(); 14656ff9b812abe388478bbaba118a580c3f4a30c863Glenn Kasten return ret; 1466d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang } 1467d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang 146841f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang /* 1469d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * Gets the value of the parameter indicated by key. 1470d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * @param key key indicates the parameter to get. 1471d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * @param reply value of the parameter to get. 1472d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang */ 1473d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang private native void getParameter(int key, Parcel reply); 1474d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang 1475d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang /** 1476d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * Gets the value of the parameter indicated by key. 14776ff9b812abe388478bbaba118a580c3f4a30c863Glenn Kasten * The caller is responsible for recycling the returned parcel. 1478d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * @param key key indicates the parameter to get. 1479d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * @return value of the parameter. 1480d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * {@hide} 1481d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang */ 1482d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang public Parcel getParcelParameter(int key) { 1483d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang Parcel p = Parcel.obtain(); 1484d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang getParameter(key, p); 1485d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang return p; 1486d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang } 1487d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang 1488d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang /** 1489d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * Gets the value of the parameter indicated by key. 1490d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * @param key key indicates the parameter to get. 1491d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * @return value of the parameter. 1492d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * {@hide} 1493d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang */ 1494d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang public String getStringParameter(int key) { 1495d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang Parcel p = Parcel.obtain(); 1496d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang getParameter(key, p); 14976ff9b812abe388478bbaba118a580c3f4a30c863Glenn Kasten String ret = p.readString(); 14986ff9b812abe388478bbaba118a580c3f4a30c863Glenn Kasten p.recycle(); 14996ff9b812abe388478bbaba118a580c3f4a30c863Glenn Kasten return ret; 1500d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang } 1501d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang 1502d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang /** 1503d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * Gets the value of the parameter indicated by key. 1504d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * @param key key indicates the parameter to get. 1505d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * @return value of the parameter. 1506d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang * {@hide} 1507d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang */ 1508d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang public int getIntParameter(int key) { 1509d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang Parcel p = Parcel.obtain(); 1510d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang getParameter(key, p); 15116ff9b812abe388478bbaba118a580c3f4a30c863Glenn Kasten int ret = p.readInt(); 15126ff9b812abe388478bbaba118a580c3f4a30c863Glenn Kasten p.recycle(); 15136ff9b812abe388478bbaba118a580c3f4a30c863Glenn Kasten return ret; 1514d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang } 1515d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang 1516d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang /** 15177070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent * Sets the send level of the player to the attached auxiliary effect 15187070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent * {@see #attachAuxEffect(int)}. The level value range is 0 to 1.0. 15197070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent * <p>By default the send level is 0, so even if an effect is attached to the player 15207070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent * this method must be called for the effect to be applied. 15217070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent * <p>Note that the passed level value is a raw scalar. UI controls should be scaled 15227070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent * logarithmically: the gain applied by audio framework ranges from -72dB to 0dB, 15237070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent * so an appropriate conversion from linear UI input x to level is: 15247070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent * x == 0 -> level = 0 15257070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent * 0 < x <= R -> level = 10^(72*(x-R)/20/R) 15267070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent * @param level send level scalar 15277070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent */ 15287070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent public native void setAuxEffectSendLevel(float level); 15297070b36549d511d6627538c73dfbab23fbae5b43Eric Laurent 153041f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang /* 153120cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania * @param request Parcel destinated to the media player. The 153220cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania * Interface token must be set to the IMediaPlayer 153320cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania * one to be routed correctly through the system. 15345d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania * @param reply[out] Parcel that will contain the reply. 153520cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania * @return The status code. 153620cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania */ 153720cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania private native final int native_invoke(Parcel request, Parcel reply); 153820cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania 15395d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania 154041f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang /* 15415d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania * @param update_only If true fetch only the set of metadata that have 15425d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania * changed since the last invocation of getMetadata. 15435d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania * The set is built using the unfiltered 15445d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania * notifications the native player sent to the 15455d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania * MediaPlayerService during that period of 15465d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania * time. If false, all the metadatas are considered. 15475d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania * @param apply_filter If true, once the metadata set has been built based on 15485d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania * the value update_only, the current filter is applied. 15495d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania * @param reply[out] On return contains the serialized 15505d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania * metadata. Valid only if the call was successful. 15515d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania * @return The status code. 15525d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania */ 15535d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania private native final boolean native_getMetadata(boolean update_only, 15545d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania boolean apply_filter, 15555d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania Parcel reply); 15565d55c7119820ee9bb06fc072e416fe98ba77cd28Nicolas Catania 155741f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang /* 1558b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania * @param request Parcel with the 2 serialized lists of allowed 1559b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania * metadata types followed by the one to be 1560b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania * dropped. Each list starts with an integer 1561b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania * indicating the number of metadata type elements. 1562b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania * @return The status code. 1563b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania */ 1564b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania private native final int native_setMetadataFilter(Parcel request); 1565b2c693919be966f179080a9ec70a7a82dbf57627Nicolas Catania 15664935d05eaa306cef88cf0ab13eca386f270409ecMarco Nelissen private static native final void native_init(); 15679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private native final void native_setup(Object mediaplayer_this); 15689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private native final void native_finalize(); 156920cb94eeb5b9672573fc86bf51e09bd66a774581Nicolas Catania 1570d211f41f764fe81fe00b10a99b4b44cb84479cbeGloria Wang /** 157141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * Class for MediaPlayer to return each audio/video/subtitle track's metadata. 157241f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * 15737a9734d769d97470ce6fac0594dd007804d33432James Dong * @see android.media.MediaPlayer#getTrackInfo 157441f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang */ 157541f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang static public class TrackInfo implements Parcelable { 157641f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang /** 157741f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * Gets the track type. 157841f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * @return TrackType which indicates if the track is video, audio, timed text. 157941f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang */ 158041f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang public int getTrackType() { 158141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang return mTrackType; 158241f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang } 158341f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang 158441f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang /** 158541f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * Gets the language code of the track. 158641f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * @return a language code in either way of ISO-639-1 or ISO-639-2. 158741f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * When the language is unknown or could not be determined, 158841f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * ISO-639-2 language code, "und", is returned. 158941f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang */ 159041f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang public String getLanguage() { 159141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang return mLanguage; 159241f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang } 159341f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang 159441f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang public static final int MEDIA_TRACK_TYPE_UNKNOWN = 0; 159541f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang public static final int MEDIA_TRACK_TYPE_VIDEO = 1; 159641f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang public static final int MEDIA_TRACK_TYPE_AUDIO = 2; 159741f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang public static final int MEDIA_TRACK_TYPE_TIMEDTEXT = 3; 159841f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang 159941f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang final int mTrackType; 160041f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang final String mLanguage; 160141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang 160241f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang TrackInfo(Parcel in) { 160341f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang mTrackType = in.readInt(); 160441f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang mLanguage = in.readString(); 160541f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang } 160641f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang 16077a9734d769d97470ce6fac0594dd007804d33432James Dong /** 16087a9734d769d97470ce6fac0594dd007804d33432James Dong * {@inheritDoc} 160941f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang */ 161041f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang @Override 161141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang public int describeContents() { 161241f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang return 0; 161341f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang } 161441f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang 16157a9734d769d97470ce6fac0594dd007804d33432James Dong /** 16167a9734d769d97470ce6fac0594dd007804d33432James Dong * {@inheritDoc} 161741f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang */ 161841f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang @Override 161941f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang public void writeToParcel(Parcel dest, int flags) { 162041f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang dest.writeInt(mTrackType); 162141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang dest.writeString(mLanguage); 162241f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang } 162341f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang 162441f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang /** 162541f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * Used to read a TrackInfo from a Parcel. 162641f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang */ 162741f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang static final Parcelable.Creator<TrackInfo> CREATOR 162841f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang = new Parcelable.Creator<TrackInfo>() { 162941f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang @Override 163041f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang public TrackInfo createFromParcel(Parcel in) { 163141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang return new TrackInfo(in); 163241f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang } 163341f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang 163441f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang @Override 163541f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang public TrackInfo[] newArray(int size) { 163641f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang return new TrackInfo[size]; 163741f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang } 163841f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang }; 163941f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang 164041f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang }; 164141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang 164241f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang /** 164341f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * Returns an array of track information. 164441f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * 1645831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * @return Array of track info. The total number of tracks is the array length. 16467a9734d769d97470ce6fac0594dd007804d33432James Dong * Must be called again if an external timed text source has been added after any of the 16477a9734d769d97470ce6fac0594dd007804d33432James Dong * addTimedTextSource methods are called. 16487a9734d769d97470ce6fac0594dd007804d33432James Dong * @throws IllegalStateException if it is called in an invalid state. 164941f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang */ 16507a9734d769d97470ce6fac0594dd007804d33432James Dong public TrackInfo[] getTrackInfo() throws IllegalStateException { 165141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang Parcel request = Parcel.obtain(); 165241f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang Parcel reply = Parcel.obtain(); 1653be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang try { 1654be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang request.writeInterfaceToken(IMEDIA_PLAYER); 1655be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang request.writeInt(INVOKE_ID_GET_TRACK_INFO); 1656be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang invoke(request, reply); 1657be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang TrackInfo trackInfo[] = reply.createTypedArray(TrackInfo.CREATOR); 1658be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang return trackInfo; 1659be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang } finally { 1660be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang request.recycle(); 1661be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang reply.recycle(); 1662be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang } 166341f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang } 166441f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang 1665831f0a90cad923ec6b00c5c598ac4356e5849431James Dong /* Do not change these values without updating their counterparts 1666831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * in include/media/stagefright/MediaDefs.h and media/libstagefright/MediaDefs.cpp! 1667831f0a90cad923ec6b00c5c598ac4356e5849431James Dong */ 1668831f0a90cad923ec6b00c5c598ac4356e5849431James Dong /** 16697a9734d769d97470ce6fac0594dd007804d33432James Dong * MIME type for SubRip (SRT) container. Used in addTimedTextSource APIs. 1670831f0a90cad923ec6b00c5c598ac4356e5849431James Dong */ 1671831f0a90cad923ec6b00c5c598ac4356e5849431James Dong public static final String MEDIA_MIMETYPE_TEXT_SUBRIP = "application/x-subrip"; 1672831f0a90cad923ec6b00c5c598ac4356e5849431James Dong 167341f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang /* 167441f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * A helper function to check if the mime type is supported by media framework. 167541f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang */ 1676831f0a90cad923ec6b00c5c598ac4356e5849431James Dong private static boolean availableMimeTypeForExternalSource(String mimeType) { 167741f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang if (mimeType == MEDIA_MIMETYPE_TEXT_SUBRIP) { 167841f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang return true; 167941f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang } 168041f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang return false; 168141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang } 168241f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang 168341f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang /* TODO: Limit the total number of external timed text source to a reasonable number. 168441f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang */ 168541f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang /** 16867a9734d769d97470ce6fac0594dd007804d33432James Dong * Adds an external timed text source file. 168741f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * 168841f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * Currently supported format is SubRip with the file extension .srt, case insensitive. 16897a9734d769d97470ce6fac0594dd007804d33432James Dong * Note that a single external timed text source may contain multiple tracks in it. 169041f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * One can find the total number of available tracks using {@link #getTrackInfo()} to see what 169141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * additional tracks become available after this method call. 169241f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * 16937a9734d769d97470ce6fac0594dd007804d33432James Dong * @param path The file path of external timed text source file. 1694831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * @param mimeType The mime type of the file. Must be one of the mime types listed above. 1695831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * @throws IOException if the file cannot be accessed or is corrupted. 1696831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * @throws IllegalArgumentException if the mimeType is not supported. 16977a9734d769d97470ce6fac0594dd007804d33432James Dong * @throws IllegalStateException if called in an invalid state. 169841f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang */ 16997a9734d769d97470ce6fac0594dd007804d33432James Dong public void addTimedTextSource(String path, String mimeType) 17007a9734d769d97470ce6fac0594dd007804d33432James Dong throws IOException, IllegalArgumentException, IllegalStateException { 170141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang if (!availableMimeTypeForExternalSource(mimeType)) { 17027a9734d769d97470ce6fac0594dd007804d33432James Dong final String msg = "Illegal mimeType for timed text source: " + mimeType; 1703c4c0284e45e1b69a03309cd55f937bcc638c0becJames Dong throw new IllegalArgumentException(msg); 170441f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang } 170541f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang 1706c4c0284e45e1b69a03309cd55f937bcc638c0becJames Dong File file = new File(path); 1707c4c0284e45e1b69a03309cd55f937bcc638c0becJames Dong if (file.exists()) { 1708c4c0284e45e1b69a03309cd55f937bcc638c0becJames Dong FileInputStream is = new FileInputStream(file); 1709c4c0284e45e1b69a03309cd55f937bcc638c0becJames Dong FileDescriptor fd = is.getFD(); 17107a9734d769d97470ce6fac0594dd007804d33432James Dong addTimedTextSource(fd, mimeType); 1711c4c0284e45e1b69a03309cd55f937bcc638c0becJames Dong is.close(); 1712c4c0284e45e1b69a03309cd55f937bcc638c0becJames Dong } else { 1713c4c0284e45e1b69a03309cd55f937bcc638c0becJames Dong // We do not support the case where the path is not a file. 1714c4c0284e45e1b69a03309cd55f937bcc638c0becJames Dong throw new IOException(path); 1715c4c0284e45e1b69a03309cd55f937bcc638c0becJames Dong } 171641f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang } 171741f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang 171841f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang /** 17197a9734d769d97470ce6fac0594dd007804d33432James Dong * Adds an external timed text source file (Uri). 172041f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * 172141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * Currently supported format is SubRip with the file extension .srt, case insensitive. 17227a9734d769d97470ce6fac0594dd007804d33432James Dong * Note that a single external timed text source may contain multiple tracks in it. 172341f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * One can find the total number of available tracks using {@link #getTrackInfo()} to see what 172441f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * additional tracks become available after this method call. 172541f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * 172641f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * @param context the Context to use when resolving the Uri 172741f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * @param uri the Content URI of the data you want to play 1728831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * @param mimeType The mime type of the file. Must be one of the mime types listed above. 1729831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * @throws IOException if the file cannot be accessed or is corrupted. 1730831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * @throws IllegalArgumentException if the mimeType is not supported. 17317a9734d769d97470ce6fac0594dd007804d33432James Dong * @throws IllegalStateException if called in an invalid state. 1732c6091ddd3a22da98b5e83d4b5d864939b451b752Gloria Wang */ 17337a9734d769d97470ce6fac0594dd007804d33432James Dong public void addTimedTextSource(Context context, Uri uri, String mimeType) 17347a9734d769d97470ce6fac0594dd007804d33432James Dong throws IOException, IllegalArgumentException, IllegalStateException { 173541f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang String scheme = uri.getScheme(); 173641f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang if(scheme == null || scheme.equals("file")) { 17377a9734d769d97470ce6fac0594dd007804d33432James Dong addTimedTextSource(uri.getPath(), mimeType); 173841f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang return; 1739c6091ddd3a22da98b5e83d4b5d864939b451b752Gloria Wang } 174041f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang 174141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang AssetFileDescriptor fd = null; 174241f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang try { 174341f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang ContentResolver resolver = context.getContentResolver(); 174441f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang fd = resolver.openAssetFileDescriptor(uri, "r"); 174541f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang if (fd == null) { 174641f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang return; 174741f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang } 17487a9734d769d97470ce6fac0594dd007804d33432James Dong addTimedTextSource(fd.getFileDescriptor(), mimeType); 174941f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang return; 175041f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang } catch (SecurityException ex) { 175141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang } catch (IOException ex) { 175241f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang } finally { 175341f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang if (fd != null) { 175441f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang fd.close(); 175541f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang } 175641f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang } 1757c6091ddd3a22da98b5e83d4b5d864939b451b752Gloria Wang } 1758c6091ddd3a22da98b5e83d4b5d864939b451b752Gloria Wang 175941f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang /** 17607a9734d769d97470ce6fac0594dd007804d33432James Dong * Adds an external timed text source file (FileDescriptor). 17617a9734d769d97470ce6fac0594dd007804d33432James Dong * 176241f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * It is the caller's responsibility to close the file descriptor. 176341f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * It is safe to do so as soon as this call returns. 176441f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * 17657a9734d769d97470ce6fac0594dd007804d33432James Dong * Currently supported format is SubRip. Note that a single external timed text source may 17667a9734d769d97470ce6fac0594dd007804d33432James Dong * contain multiple tracks in it. One can find the total number of available tracks 17677a9734d769d97470ce6fac0594dd007804d33432James Dong * using {@link #getTrackInfo()} to see what additional tracks become available 17687a9734d769d97470ce6fac0594dd007804d33432James Dong * after this method call. 176941f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * 177041f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * @param fd the FileDescriptor for the file you want to play 1771831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * @param mimeType The mime type of the file. Must be one of the mime types listed above. 1772831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * @throws IllegalArgumentException if the mimeType is not supported. 17737a9734d769d97470ce6fac0594dd007804d33432James Dong * @throws IllegalStateException if called in an invalid state. 177441f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang */ 17757a9734d769d97470ce6fac0594dd007804d33432James Dong public void addTimedTextSource(FileDescriptor fd, String mimeType) 17767a9734d769d97470ce6fac0594dd007804d33432James Dong throws IllegalArgumentException, IllegalStateException { 177741f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang // intentionally less than LONG_MAX 17787a9734d769d97470ce6fac0594dd007804d33432James Dong addTimedTextSource(fd, 0, 0x7ffffffffffffffL, mimeType); 177941f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang } 178041f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang 178141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang /** 178241f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * Adds an external timed text file (FileDescriptor). 17837a9734d769d97470ce6fac0594dd007804d33432James Dong * 178441f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * It is the caller's responsibility to close the file descriptor. 178541f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * It is safe to do so as soon as this call returns. 178641f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * 17877a9734d769d97470ce6fac0594dd007804d33432James Dong * Currently supported format is SubRip. Note that a single external timed text source may 17887a9734d769d97470ce6fac0594dd007804d33432James Dong * contain multiple tracks in it. One can find the total number of available tracks 17897a9734d769d97470ce6fac0594dd007804d33432James Dong * using {@link #getTrackInfo()} to see what additional tracks become available 17907a9734d769d97470ce6fac0594dd007804d33432James Dong * after this method call. 179141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * 179241f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * @param fd the FileDescriptor for the file you want to play 179341f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * @param offset the offset into the file where the data to be played starts, in bytes 179441f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * @param length the length in bytes of the data to be played 1795831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * @param mimeType The mime type of the file. Must be one of the mime types listed above. 1796831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * @throws IllegalArgumentException if the mimeType is not supported. 17977a9734d769d97470ce6fac0594dd007804d33432James Dong * @throws IllegalStateException if called in an invalid state. 179841f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang */ 17997a9734d769d97470ce6fac0594dd007804d33432James Dong public void addTimedTextSource(FileDescriptor fd, long offset, long length, String mimeType) 18007a9734d769d97470ce6fac0594dd007804d33432James Dong throws IllegalArgumentException, IllegalStateException { 180141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang if (!availableMimeTypeForExternalSource(mimeType)) { 18027a9734d769d97470ce6fac0594dd007804d33432James Dong throw new IllegalArgumentException("Illegal mimeType for timed text source: " + mimeType); 180341f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang } 1804c4c0284e45e1b69a03309cd55f937bcc638c0becJames Dong 180541f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang Parcel request = Parcel.obtain(); 180641f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang Parcel reply = Parcel.obtain(); 1807be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang try { 1808be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang request.writeInterfaceToken(IMEDIA_PLAYER); 1809be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang request.writeInt(INVOKE_ID_ADD_EXTERNAL_SOURCE_FD); 1810be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang request.writeFileDescriptor(fd); 1811be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang request.writeLong(offset); 1812be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang request.writeLong(length); 1813be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang request.writeString(mimeType); 1814be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang invoke(request, reply); 1815be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang } finally { 1816be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang request.recycle(); 1817be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang reply.recycle(); 1818be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang } 1819c6091ddd3a22da98b5e83d4b5d864939b451b752Gloria Wang } 1820c6091ddd3a22da98b5e83d4b5d864939b451b752Gloria Wang 1821c6091ddd3a22da98b5e83d4b5d864939b451b752Gloria Wang /** 182241f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * Selects a track. 182341f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * <p> 1824831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * If a MediaPlayer is in invalid state, it throws an IllegalStateException exception. 1825831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * If a MediaPlayer is in <em>Started</em> state, the selected track is presented immediately. 182641f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * If a MediaPlayer is not in Started state, it just marks the track to be played. 182741f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * </p> 182841f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * <p> 182941f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * In any valid state, if it is called multiple times on the same type of track (ie. Video, 183041f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * Audio, Timed Text), the most recent one will be chosen. 183141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * </p> 183241f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * <p> 1833831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * The first audio and video tracks are selected by default if available, even though 1834831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * this method is not called. However, no timed text track will be selected until 1835831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * this function is called. 1836831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * </p> 1837831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * <p> 1838831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * Currently, only timed text tracks or audio tracks can be selected via this method. 1839831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * In addition, the support for selecting an audio track at runtime is pretty limited 1840831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * in that an audio track can only be selected in the <em>Prepared</em> state. 184141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * </p> 1842831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * @param index the index of the track to be selected. The valid range of the index 1843831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * is 0..total number of track - 1. The total number of tracks as well as the type of 1844831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * each individual track can be found by calling {@link #getTrackInfo()} method. 18457a9734d769d97470ce6fac0594dd007804d33432James Dong * @throws IllegalStateException if called in an invalid state. 18467a9734d769d97470ce6fac0594dd007804d33432James Dong * 18477a9734d769d97470ce6fac0594dd007804d33432James Dong * @see android.media.MediaPlayer#getTrackInfo 1848c6091ddd3a22da98b5e83d4b5d864939b451b752Gloria Wang */ 18497a9734d769d97470ce6fac0594dd007804d33432James Dong public void selectTrack(int index) throws IllegalStateException { 18507a9734d769d97470ce6fac0594dd007804d33432James Dong selectOrDeselectTrack(index, true /* select */); 185141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang } 185241f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang 185341f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang /** 18547a9734d769d97470ce6fac0594dd007804d33432James Dong * Deselect a track. 1855831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * <p> 1856831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * Currently, the track must be a timed text track and no audio or video tracks can be 18577a9734d769d97470ce6fac0594dd007804d33432James Dong * deselected. If the timed text track identified by index has not been 1858831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * selected before, it throws an exception. 1859831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * </p> 18607a9734d769d97470ce6fac0594dd007804d33432James Dong * @param index the index of the track to be deselected. The valid range of the index 1861831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * is 0..total number of tracks - 1. The total number of tracks as well as the type of 1862831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * each individual track can be found by calling {@link #getTrackInfo()} method. 18637a9734d769d97470ce6fac0594dd007804d33432James Dong * @throws IllegalStateException if called in an invalid state. 1864831f0a90cad923ec6b00c5c598ac4356e5849431James Dong * 18657a9734d769d97470ce6fac0594dd007804d33432James Dong * @see android.media.MediaPlayer#getTrackInfo 186641f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang */ 18677a9734d769d97470ce6fac0594dd007804d33432James Dong public void deselectTrack(int index) throws IllegalStateException { 18687a9734d769d97470ce6fac0594dd007804d33432James Dong selectOrDeselectTrack(index, false /* select */); 1869831f0a90cad923ec6b00c5c598ac4356e5849431James Dong } 1870831f0a90cad923ec6b00c5c598ac4356e5849431James Dong 18717a9734d769d97470ce6fac0594dd007804d33432James Dong private void selectOrDeselectTrack(int index, boolean select) 18727a9734d769d97470ce6fac0594dd007804d33432James Dong throws IllegalStateException { 187341f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang Parcel request = Parcel.obtain(); 187441f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang Parcel reply = Parcel.obtain(); 1875be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang try { 1876be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang request.writeInterfaceToken(IMEDIA_PLAYER); 1877be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang request.writeInt(select? INVOKE_ID_SELECT_TRACK: INVOKE_ID_DESELECT_TRACK); 1878be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang request.writeInt(index); 1879be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang invoke(request, reply); 1880be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang } finally { 1881be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang request.recycle(); 1882be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang reply.recycle(); 1883be0ea968bf8b3f92f6975ccd14031aec23a2c47fInsun Kang } 1884c6091ddd3a22da98b5e83d4b5d864939b451b752Gloria Wang } 1885c6091ddd3a22da98b5e83d4b5d864939b451b752Gloria Wang 1886831f0a90cad923ec6b00c5c598ac4356e5849431James Dong 1887c6091ddd3a22da98b5e83d4b5d864939b451b752Gloria Wang /** 1888d211f41f764fe81fe00b10a99b4b44cb84479cbeGloria Wang * @param reply Parcel with audio/video duration info for battery 1889d211f41f764fe81fe00b10a99b4b44cb84479cbeGloria Wang tracking usage 1890d211f41f764fe81fe00b10a99b4b44cb84479cbeGloria Wang * @return The status code. 1891d211f41f764fe81fe00b10a99b4b44cb84479cbeGloria Wang * {@hide} 1892d211f41f764fe81fe00b10a99b4b44cb84479cbeGloria Wang */ 1893d211f41f764fe81fe00b10a99b4b44cb84479cbeGloria Wang public native static int native_pullBatteryData(Parcel reply); 1894d211f41f764fe81fe00b10a99b4b44cb84479cbeGloria Wang 1895720aa282791ef9405d39a15f419a41ab24f11e30John Grossman /** 1896720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * Sets the target UDP re-transmit endpoint for the low level player. 1897720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * Generally, the address portion of the endpoint is an IP multicast 1898720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * address, although a unicast address would be equally valid. When a valid 1899720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * retransmit endpoint has been set, the media player will not decode and 1900720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * render the media presentation locally. Instead, the player will attempt 1901720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * to re-multiplex its media data using the Android@Home RTP profile and 1902720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * re-transmit to the target endpoint. Receiver devices (which may be 1903720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * either the same as the transmitting device or different devices) may 1904720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * instantiate, prepare, and start a receiver player using a setDataSource 1905720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * URL of the form... 1906720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * 1907720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * aahRX://<multicastIP>:<port> 1908720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * 1909720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * to receive, decode and render the re-transmitted content. 1910720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * 1911720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * setRetransmitEndpoint may only be called before setDataSource has been 1912720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * called; while the player is in the Idle state. 1913720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * 1914720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * @param endpoint the address and UDP port of the re-transmission target or 1915720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * null if no re-transmission is to be performed. 1916720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * @throws IllegalStateException if it is called in an invalid state 1917720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * @throws IllegalArgumentException if the retransmit endpoint is supplied, 1918720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * but invalid. 1919720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * 1920720aa282791ef9405d39a15f419a41ab24f11e30John Grossman * {@hide} pending API council 1921720aa282791ef9405d39a15f419a41ab24f11e30John Grossman */ 1922720aa282791ef9405d39a15f419a41ab24f11e30John Grossman public void setRetransmitEndpoint(InetSocketAddress endpoint) 1923720aa282791ef9405d39a15f419a41ab24f11e30John Grossman throws IllegalStateException, IllegalArgumentException 1924720aa282791ef9405d39a15f419a41ab24f11e30John Grossman { 1925720aa282791ef9405d39a15f419a41ab24f11e30John Grossman String addrString = null; 1926720aa282791ef9405d39a15f419a41ab24f11e30John Grossman int port = 0; 1927720aa282791ef9405d39a15f419a41ab24f11e30John Grossman 1928720aa282791ef9405d39a15f419a41ab24f11e30John Grossman if (null != endpoint) { 1929720aa282791ef9405d39a15f419a41ab24f11e30John Grossman addrString = endpoint.getAddress().getHostAddress(); 1930720aa282791ef9405d39a15f419a41ab24f11e30John Grossman port = endpoint.getPort(); 1931720aa282791ef9405d39a15f419a41ab24f11e30John Grossman } 1932720aa282791ef9405d39a15f419a41ab24f11e30John Grossman 1933720aa282791ef9405d39a15f419a41ab24f11e30John Grossman int ret = native_setRetransmitEndpoint(addrString, port); 1934720aa282791ef9405d39a15f419a41ab24f11e30John Grossman if (ret != 0) { 1935720aa282791ef9405d39a15f419a41ab24f11e30John Grossman throw new IllegalArgumentException("Illegal re-transmit endpoint; native ret " + ret); 1936720aa282791ef9405d39a15f419a41ab24f11e30John Grossman } 1937720aa282791ef9405d39a15f419a41ab24f11e30John Grossman } 1938720aa282791ef9405d39a15f419a41ab24f11e30John Grossman 1939720aa282791ef9405d39a15f419a41ab24f11e30John Grossman private native final int native_setRetransmitEndpoint(String addrString, int port); 1940720aa282791ef9405d39a15f419a41ab24f11e30John Grossman 19419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project @Override 19429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project protected void finalize() { native_finalize(); } 19439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 19449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /* Do not change these values without updating their counterparts 19459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * in include/media/mediaplayer.h! 19469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 19479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private static final int MEDIA_NOP = 0; // interface test message 19489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private static final int MEDIA_PREPARED = 1; 19499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private static final int MEDIA_PLAYBACK_COMPLETE = 2; 19509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private static final int MEDIA_BUFFERING_UPDATE = 3; 19519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private static final int MEDIA_SEEK_COMPLETE = 4; 19529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private static final int MEDIA_SET_VIDEO_SIZE = 5; 1953162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang private static final int MEDIA_TIMED_TEXT = 99; 19549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private static final int MEDIA_ERROR = 100; 1955c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project private static final int MEDIA_INFO = 200; 19569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 19579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private class EventHandler extends Handler 19589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 19599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private MediaPlayer mMediaPlayer; 19609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 19619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public EventHandler(MediaPlayer mp, Looper looper) { 19629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project super(looper); 19639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mMediaPlayer = mp; 19649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 19659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 19669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project @Override 19679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void handleMessage(Message msg) { 19689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mMediaPlayer.mNativeContext == 0) { 19699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Log.w(TAG, "mediaplayer went away with unhandled events"); 19709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 19719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 19729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project switch(msg.what) { 19739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project case MEDIA_PREPARED: 19749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mOnPreparedListener != null) 19759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mOnPreparedListener.onPrepared(mMediaPlayer); 19769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 19779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 19789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project case MEDIA_PLAYBACK_COMPLETE: 19799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mOnCompletionListener != null) 19809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mOnCompletionListener.onCompletion(mMediaPlayer); 19819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project stayAwake(false); 19829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 19839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 19849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project case MEDIA_BUFFERING_UPDATE: 19859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mOnBufferingUpdateListener != null) 19869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mOnBufferingUpdateListener.onBufferingUpdate(mMediaPlayer, msg.arg1); 19879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 19889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 19899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project case MEDIA_SEEK_COMPLETE: 19909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mOnSeekCompleteListener != null) 19919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mOnSeekCompleteListener.onSeekComplete(mMediaPlayer); 19929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 19939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 19949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project case MEDIA_SET_VIDEO_SIZE: 19959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mOnVideoSizeChangedListener != null) 19969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mOnVideoSizeChangedListener.onVideoSizeChanged(mMediaPlayer, msg.arg1, msg.arg2); 19979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 19989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 19999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project case MEDIA_ERROR: 20009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Log.e(TAG, "Error (" + msg.arg1 + "," + msg.arg2 + ")"); 20019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project boolean error_was_handled = false; 20029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mOnErrorListener != null) { 20039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project error_was_handled = mOnErrorListener.onError(mMediaPlayer, msg.arg1, msg.arg2); 20049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 20059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mOnCompletionListener != null && ! error_was_handled) { 20069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mOnCompletionListener.onCompletion(mMediaPlayer); 20079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 20089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project stayAwake(false); 20099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 2010c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project 2011c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project case MEDIA_INFO: 201252c7832e35b6f0c7d6197eb09346cea7dc5bea6bAndreas Huber if (msg.arg1 != MEDIA_INFO_VIDEO_TRACK_LAGGING) { 201352c7832e35b6f0c7d6197eb09346cea7dc5bea6bAndreas Huber Log.i(TAG, "Info (" + msg.arg1 + "," + msg.arg2 + ")"); 201452c7832e35b6f0c7d6197eb09346cea7dc5bea6bAndreas Huber } 2015c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project if (mOnInfoListener != null) { 2016c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project mOnInfoListener.onInfo(mMediaPlayer, msg.arg1, msg.arg2); 2017c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project } 2018c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project // No real default action so far. 2019c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project return; 2020162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang case MEDIA_TIMED_TEXT: 202141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang if (mOnTimedTextListener == null) 202241f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang return; 202341f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang if (msg.obj == null) { 202441f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang mOnTimedTextListener.onTimedText(mMediaPlayer, null); 202541f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang } else { 20268902097bb686752ff207e3bda12713be1a8c74ebInsun Kang if (msg.obj instanceof Parcel) { 20278902097bb686752ff207e3bda12713be1a8c74ebInsun Kang Parcel parcel = (Parcel)msg.obj; 20288902097bb686752ff207e3bda12713be1a8c74ebInsun Kang TimedText text = new TimedText(parcel); 2029333c09945e7399c6a2b1f4d9fdf981508e38db52Insun Kang parcel.recycle(); 203041f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang mOnTimedTextListener.onTimedText(mMediaPlayer, text); 2031eaa5d8f9c0117bdaa20fd0a57921156bb0c06345Gloria Wang } 2032162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang } 2033162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang return; 2034c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project 20359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project case MEDIA_NOP: // interface test message - ignore 20369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project break; 20379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 20389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project default: 20399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Log.e(TAG, "Unknown message type " + msg.what); 20409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 20419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 20429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 20439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 20449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 204541f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang /* 20469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Called from native code when an interesting event happens. This method 20479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * just uses the EventHandler system to post the event back to the main app thread. 20489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * We use a weak reference to the original MediaPlayer object so that the native 20499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * code is safe from the object disappearing from underneath it. (This is 20509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the cookie passed to native_setup().) 20519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 20529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private static void postEventFromNative(Object mediaplayer_ref, 20539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project int what, int arg1, int arg2, Object obj) 20549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 20559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project MediaPlayer mp = (MediaPlayer)((WeakReference)mediaplayer_ref).get(); 20569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mp == null) { 20579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 20589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 20599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 206084b832054552e00257bb04997143ca33d6d100beMarco Nelissen if (what == MEDIA_INFO && arg1 == MEDIA_INFO_STARTED_AS_NEXT) { 206184b832054552e00257bb04997143ca33d6d100beMarco Nelissen // this acquires the wakelock if needed, and sets the client side state 206284b832054552e00257bb04997143ca33d6d100beMarco Nelissen mp.start(); 206384b832054552e00257bb04997143ca33d6d100beMarco Nelissen } 20649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mp.mEventHandler != null) { 20659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Message m = mp.mEventHandler.obtainMessage(what, arg1, arg2, obj); 20669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mp.mEventHandler.sendMessage(m); 20679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 20689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 20699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 20709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 20719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Interface definition for a callback to be invoked when the media 20729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * source is ready for playback. 20739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 20749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public interface OnPreparedListener 20759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 20769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 20779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Called when the media file is ready for playback. 207832f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 20799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param mp the MediaPlayer that is ready for playback 20809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 20819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project void onPrepared(MediaPlayer mp); 20829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 20839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 20849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 20859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Register a callback to be invoked when the media source is ready 20869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * for playback. 20879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 2088105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * @param listener the callback that will be run 20899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 2090105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project public void setOnPreparedListener(OnPreparedListener listener) 20919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 2092105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project mOnPreparedListener = listener; 20939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 20949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 20959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private OnPreparedListener mOnPreparedListener; 20969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 20979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 20989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Interface definition for a callback to be invoked when playback of 20999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * a media source has completed. 21009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 21019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public interface OnCompletionListener 21029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 21039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 21049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Called when the end of a media source is reached during playback. 210532f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 21069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param mp the MediaPlayer that reached the end of the file 21079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 21089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project void onCompletion(MediaPlayer mp); 21099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 21109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 21119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 21129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Register a callback to be invoked when the end of a media source 21139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * has been reached during playback. 21149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 2115105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * @param listener the callback that will be run 21169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 2117105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project public void setOnCompletionListener(OnCompletionListener listener) 21189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 2119105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project mOnCompletionListener = listener; 21209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 21219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 21229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private OnCompletionListener mOnCompletionListener; 21239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 21249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 21259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Interface definition of a callback to be invoked indicating buffering 21269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * status of a media resource being streamed over the network. 21279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 21289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public interface OnBufferingUpdateListener 21299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 21309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 2131ea763069b1dca16193d32c6cf3ceab1c23743271Jean-Michel Trivi * Called to update status in buffering a media stream received through 2132ea763069b1dca16193d32c6cf3ceab1c23743271Jean-Michel Trivi * progressive HTTP download. The received buffering percentage 2133ea763069b1dca16193d32c6cf3ceab1c23743271Jean-Michel Trivi * indicates how much of the content has been buffered or played. 2134ea763069b1dca16193d32c6cf3ceab1c23743271Jean-Michel Trivi * For example a buffering update of 80 percent when half the content 2135ea763069b1dca16193d32c6cf3ceab1c23743271Jean-Michel Trivi * has already been played indicates that the next 30 percent of the 2136ea763069b1dca16193d32c6cf3ceab1c23743271Jean-Michel Trivi * content to play has been buffered. 213732f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 21389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param mp the MediaPlayer the update pertains to 2139ea763069b1dca16193d32c6cf3ceab1c23743271Jean-Michel Trivi * @param percent the percentage (0-100) of the content 2140ea763069b1dca16193d32c6cf3ceab1c23743271Jean-Michel Trivi * that has been buffered or played thus far 21419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 21429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project void onBufferingUpdate(MediaPlayer mp, int percent); 21439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 214432f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 21459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 21469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Register a callback to be invoked when the status of a network 21479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * stream's buffer has changed. 21489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 2149105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * @param listener the callback that will be run. 21509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 2151105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project public void setOnBufferingUpdateListener(OnBufferingUpdateListener listener) 21529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 2153105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project mOnBufferingUpdateListener = listener; 21549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 21559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 21569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private OnBufferingUpdateListener mOnBufferingUpdateListener; 215732f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 21589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 21599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Interface definition of a callback to be invoked indicating 21609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the completion of a seek operation. 21619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 21629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public interface OnSeekCompleteListener 21639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 21649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 21659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Called to indicate the completion of a seek operation. 216632f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 21679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param mp the MediaPlayer that issued the seek operation 21689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 21699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void onSeekComplete(MediaPlayer mp); 21709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 217132f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 21729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 21739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Register a callback to be invoked when a seek operation has been 21749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * completed. 217532f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 2176105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * @param listener the callback that will be run 21779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 2178105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project public void setOnSeekCompleteListener(OnSeekCompleteListener listener) 21799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 2180105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project mOnSeekCompleteListener = listener; 21819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 218232f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 21839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private OnSeekCompleteListener mOnSeekCompleteListener; 21849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 21859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 21869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Interface definition of a callback to be invoked when the 21879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * video size is first known or updated 21889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 21899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public interface OnVideoSizeChangedListener 21909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 21919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 21929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Called to indicate the video size 219332f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 2194ca402cdcacfdcd2978a22d59f446c93aad34c75eJames Dong * The video size (width and height) could be 0 if there was no video, 2195ca402cdcacfdcd2978a22d59f446c93aad34c75eJames Dong * no display surface was set, or the value was not determined yet. 2196ca402cdcacfdcd2978a22d59f446c93aad34c75eJames Dong * 21979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param mp the MediaPlayer associated with this callback 21989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param width the width of the video 21999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param height the height of the video 22009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 22019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void onVideoSizeChanged(MediaPlayer mp, int width, int height); 22029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 220332f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 22049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 22059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Register a callback to be invoked when the video size is 22069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * known or updated. 220732f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 2208105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * @param listener the callback that will be run 22099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 2210105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project public void setOnVideoSizeChangedListener(OnVideoSizeChangedListener listener) 22119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 2212105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project mOnVideoSizeChangedListener = listener; 22139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 221432f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 22159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private OnVideoSizeChangedListener mOnVideoSizeChangedListener; 22169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2217162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang /** 2218162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang * Interface definition of a callback to be invoked when a 2219162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang * timed text is available for display. 2220162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang */ 2221162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang public interface OnTimedTextListener 2222162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang { 2223162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang /** 2224eaa5d8f9c0117bdaa20fd0a57921156bb0c06345Gloria Wang * Called to indicate an avaliable timed text 2225162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang * 2226162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang * @param mp the MediaPlayer associated with this callback 2227eaa5d8f9c0117bdaa20fd0a57921156bb0c06345Gloria Wang * @param text the timed text sample which contains the text 2228eaa5d8f9c0117bdaa20fd0a57921156bb0c06345Gloria Wang * needed to be displayed and the display format. 2229162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang */ 2230eaa5d8f9c0117bdaa20fd0a57921156bb0c06345Gloria Wang public void onTimedText(MediaPlayer mp, TimedText text); 2231162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang } 2232162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang 2233162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang /** 2234162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang * Register a callback to be invoked when a timed text is available 2235162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang * for display. 2236162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang * 2237162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang * @param listener the callback that will be run 2238162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang */ 2239162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang public void setOnTimedTextListener(OnTimedTextListener listener) 2240162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang { 2241162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang mOnTimedTextListener = listener; 2242162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang } 2243162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang 2244162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang private OnTimedTextListener mOnTimedTextListener; 2245162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang 2246162ee49e1ce8800de80697fdd0e0e42ad7e9374eGloria Wang 22479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /* Do not change these values without updating their counterparts 22489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * in include/media/mediaplayer.h! 22499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 22509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** Unspecified media player error. 22519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.media.MediaPlayer.OnErrorListener 22529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 22539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int MEDIA_ERROR_UNKNOWN = 1; 2254c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project 22559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** Media server died. In this case, the application must release the 225632f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * MediaPlayer object and instantiate a new one. 22579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.media.MediaPlayer.OnErrorListener 22589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 22599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int MEDIA_ERROR_SERVER_DIED = 100; 226032f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 2261c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project /** The video is streamed and its container is not valid for progressive 2262c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * playback i.e the video's index (e.g moov atom) is not at the start of the 2263c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * file. 22644a0029f95db144ba735b35e636400e8ce535383fNiko Catania * @see android.media.MediaPlayer.OnErrorListener 2265c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project */ 2266c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project public static final int MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK = 200; 22679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 22682adac496a891ba70cc2797a36aacf642e10b8c8dJames Dong /** File or network related operation errors. */ 22692adac496a891ba70cc2797a36aacf642e10b8c8dJames Dong public static final int MEDIA_ERROR_IO = -1004; 22702adac496a891ba70cc2797a36aacf642e10b8c8dJames Dong /** Bitstream is not conforming to the related coding standard or file spec. */ 22712adac496a891ba70cc2797a36aacf642e10b8c8dJames Dong public static final int MEDIA_ERROR_MALFORMED = -1007; 22722adac496a891ba70cc2797a36aacf642e10b8c8dJames Dong /** Bitstream is conforming to the related coding standard or file spec, but 22732adac496a891ba70cc2797a36aacf642e10b8c8dJames Dong * the media framework does not support the feature. */ 22742adac496a891ba70cc2797a36aacf642e10b8c8dJames Dong public static final int MEDIA_ERROR_UNSUPPORTED = -1010; 22752adac496a891ba70cc2797a36aacf642e10b8c8dJames Dong /** Some operation takes too long to complete, usually more than 3-5 seconds. */ 22762adac496a891ba70cc2797a36aacf642e10b8c8dJames Dong public static final int MEDIA_ERROR_TIMED_OUT = -110; 22772adac496a891ba70cc2797a36aacf642e10b8c8dJames Dong 22789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 22799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Interface definition of a callback to be invoked when there 22809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * has been an error during an asynchronous operation (other errors 22819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * will throw exceptions at method call time). 22829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 22839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public interface OnErrorListener 22849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 22859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 22869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Called to indicate an error. 228732f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 22889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param mp the MediaPlayer the error pertains to 22899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param what the type of error that has occurred: 22909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <ul> 22919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>{@link #MEDIA_ERROR_UNKNOWN} 22929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>{@link #MEDIA_ERROR_SERVER_DIED} 22939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </ul> 2294c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * @param extra an extra code, specific to the error. Typically 2295b10ec1f4b1f6a3552060d44359dd64cc37b1a497James Dong * implementation dependent. 22962adac496a891ba70cc2797a36aacf642e10b8c8dJames Dong * <ul> 22972adac496a891ba70cc2797a36aacf642e10b8c8dJames Dong * <li>{@link #MEDIA_ERROR_IO} 22982adac496a891ba70cc2797a36aacf642e10b8c8dJames Dong * <li>{@link #MEDIA_ERROR_MALFORMED} 22992adac496a891ba70cc2797a36aacf642e10b8c8dJames Dong * <li>{@link #MEDIA_ERROR_UNSUPPORTED} 23002adac496a891ba70cc2797a36aacf642e10b8c8dJames Dong * <li>{@link #MEDIA_ERROR_TIMED_OUT} 23012adac496a891ba70cc2797a36aacf642e10b8c8dJames Dong * </ul> 23029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return True if the method handled the error, false if it didn't. 23039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Returning false, or not having an OnErrorListener at all, will 23049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * cause the OnCompletionListener to be called. 23059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 23069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project boolean onError(MediaPlayer mp, int what, int extra); 23079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 230832f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania 23099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 23109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Register a callback to be invoked when an error has happened 23119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * during an asynchronous operation. 231232f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 2313c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * @param listener the callback that will be run 23149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 2315c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project public void setOnErrorListener(OnErrorListener listener) 23169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 2317c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project mOnErrorListener = listener; 23189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 23199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 23209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private OnErrorListener mOnErrorListener; 2321c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project 2322c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project 2323c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project /* Do not change these values without updating their counterparts 2324c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * in include/media/mediaplayer.h! 2325c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project */ 2326c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project /** Unspecified media player info. 2327c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * @see android.media.MediaPlayer.OnInfoListener 2328c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project */ 2329c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project public static final int MEDIA_INFO_UNKNOWN = 1; 2330c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project 233184b832054552e00257bb04997143ca33d6d100beMarco Nelissen /** The player was started because it was used as the next player for another 233284b832054552e00257bb04997143ca33d6d100beMarco Nelissen * player, which just completed playback. 233384b832054552e00257bb04997143ca33d6d100beMarco Nelissen * @see android.media.MediaPlayer.OnInfoListener 233484b832054552e00257bb04997143ca33d6d100beMarco Nelissen * @hide 233584b832054552e00257bb04997143ca33d6d100beMarco Nelissen */ 233684b832054552e00257bb04997143ca33d6d100beMarco Nelissen public static final int MEDIA_INFO_STARTED_AS_NEXT = 2; 233784b832054552e00257bb04997143ca33d6d100beMarco Nelissen 233815a89e6b48e9cd0112efcfd903843c5912e26567James Dong /** The player just pushed the very first video frame for rendering. 233915a89e6b48e9cd0112efcfd903843c5912e26567James Dong * @see android.media.MediaPlayer.OnInfoListener 234015a89e6b48e9cd0112efcfd903843c5912e26567James Dong */ 234115a89e6b48e9cd0112efcfd903843c5912e26567James Dong public static final int MEDIA_INFO_VIDEO_RENDERING_START = 3; 234215a89e6b48e9cd0112efcfd903843c5912e26567James Dong 2343c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project /** The video is too complex for the decoder: it can't decode frames fast 2344c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * enough. Possibly only the audio plays fine at this stage. 2345c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * @see android.media.MediaPlayer.OnInfoListener 2346c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project */ 2347c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project public static final int MEDIA_INFO_VIDEO_TRACK_LAGGING = 700; 2348c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project 23494d61f602bf67fe61256c23f090d6119992ad5160Andreas Huber /** MediaPlayer is temporarily pausing playback internally in order to 23504d61f602bf67fe61256c23f090d6119992ad5160Andreas Huber * buffer more data. 2351c36b3c6956479f1a154fe1e08b679ff4657097e1James Dong * @see android.media.MediaPlayer.OnInfoListener 23524d61f602bf67fe61256c23f090d6119992ad5160Andreas Huber */ 23534d61f602bf67fe61256c23f090d6119992ad5160Andreas Huber public static final int MEDIA_INFO_BUFFERING_START = 701; 23544d61f602bf67fe61256c23f090d6119992ad5160Andreas Huber 23554d61f602bf67fe61256c23f090d6119992ad5160Andreas Huber /** MediaPlayer is resuming playback after filling buffers. 2356c36b3c6956479f1a154fe1e08b679ff4657097e1James Dong * @see android.media.MediaPlayer.OnInfoListener 23574d61f602bf67fe61256c23f090d6119992ad5160Andreas Huber */ 23584d61f602bf67fe61256c23f090d6119992ad5160Andreas Huber public static final int MEDIA_INFO_BUFFERING_END = 702; 23594d61f602bf67fe61256c23f090d6119992ad5160Andreas Huber 2360c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project /** Bad interleaving means that a media has been improperly interleaved or 2361c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * not interleaved at all, e.g has all the video samples first then all the 2362c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * audio ones. Video is playing but a lot of disk seeks may be happening. 2363c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * @see android.media.MediaPlayer.OnInfoListener 2364c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project */ 2365c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project public static final int MEDIA_INFO_BAD_INTERLEAVING = 800; 2366c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project 2367c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project /** The media cannot be seeked (e.g live stream) 2368c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * @see android.media.MediaPlayer.OnInfoListener 2369c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project */ 2370c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project public static final int MEDIA_INFO_NOT_SEEKABLE = 801; 2371c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project 23729193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania /** A new set of metadata is available. 23739193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * @see android.media.MediaPlayer.OnInfoListener 23749193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania */ 23759193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania public static final int MEDIA_INFO_METADATA_UPDATE = 802; 23769193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania 237741f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang /** Failed to handle timed text track properly. 237841f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * @see android.media.MediaPlayer.OnInfoListener 237941f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * 238041f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang * {@hide} 238141f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang */ 238241f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang public static final int MEDIA_INFO_TIMED_TEXT_ERROR = 900; 238341f3f716b07265fb355ef70e89b9d7e1ad5f0a6fInsun Kang 2384c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project /** 2385c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * Interface definition of a callback to be invoked to communicate some 2386c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * info and/or warning about the media or its playback. 2387c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project */ 2388c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project public interface OnInfoListener 2389c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project { 2390c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project /** 2391c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * Called to indicate an info or a warning. 239232f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 2393c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * @param mp the MediaPlayer the info pertains to. 2394c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * @param what the type of info or warning. 2395c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * <ul> 2396c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * <li>{@link #MEDIA_INFO_UNKNOWN} 2397c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * <li>{@link #MEDIA_INFO_VIDEO_TRACK_LAGGING} 239815a89e6b48e9cd0112efcfd903843c5912e26567James Dong * <li>{@link #MEDIA_INFO_VIDEO_RENDERING_START} 2399c36b3c6956479f1a154fe1e08b679ff4657097e1James Dong * <li>{@link #MEDIA_INFO_BUFFERING_START} 2400c36b3c6956479f1a154fe1e08b679ff4657097e1James Dong * <li>{@link #MEDIA_INFO_BUFFERING_END} 2401c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * <li>{@link #MEDIA_INFO_BAD_INTERLEAVING} 2402c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * <li>{@link #MEDIA_INFO_NOT_SEEKABLE} 24039193e08dc1d91401fdf1846eaad4689da3911dc1Nicolas Catania * <li>{@link #MEDIA_INFO_METADATA_UPDATE} 2404c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * </ul> 2405c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * @param extra an extra code, specific to the info. Typically 2406b10ec1f4b1f6a3552060d44359dd64cc37b1a497James Dong * implementation dependent. 2407c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * @return True if the method handled the info, false if it didn't. 2408c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * Returning false, or not having an OnErrorListener at all, will 2409c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * cause the info to be discarded. 2410c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project */ 2411c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project boolean onInfo(MediaPlayer mp, int what, int extra); 2412c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project } 2413c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project 2414c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project /** 2415c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * Register a callback to be invoked when an info/warning is available. 241632f82774884bdd709789ab9f3ccdf5b972ff7681Nicolas Catania * 2417c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project * @param listener the callback that will be run 2418c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project */ 2419c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project public void setOnInfoListener(OnInfoListener listener) 2420c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project { 2421c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project mOnInfoListener = listener; 2422c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project } 2423c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project 2424c39a6e0c51e182338deb8b63d07933b585134929The Android Open Source Project private OnInfoListener mOnInfoListener; 2425c39d2e3c012fb96999991e30659a474f9f30f789Marco Nelissen 2426454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong /* 2427454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong * Test whether a given video scaling mode is supported. 2428454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong */ 2429454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong private boolean isVideoScalingModeSupported(int mode) { 2430454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong return (mode == VIDEO_SCALING_MODE_SCALE_TO_FIT || 2431454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong mode == VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING); 2432454014e55fe5a0d9a4b47080f8017b5297d016a8James Dong } 24339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} 2434