Loading media/java/android/media/MediaPlayer2.java +61 −142 Original line number Diff line number Diff line Loading @@ -453,8 +453,8 @@ import java.util.concurrent.Executor; * thread by default has a Looper running). * */ public abstract class MediaPlayer2 extends MediaPlayerBase implements SubtitleController.Listener public abstract class MediaPlayer2 implements SubtitleController.Listener , AutoCloseable , AudioRouting { /** * Create a MediaPlayer2 object. Loading Loading @@ -513,6 +513,12 @@ public abstract class MediaPlayer2 extends MediaPlayerBase // add hidden empty constructor so it doesn't show in SDK public MediaPlayer2() { } /** * Returns a {@link MediaPlayerBase} implementation which runs based on * this MediaPlayer2 instance. */ public abstract MediaPlayerBase getMediaPlayerBase(); /** * Releases the resources held by this {@code MediaPlayer2} object. * Loading Loading @@ -549,7 +555,6 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * */ // This is an asynchronous call. @Override public abstract void play(); /** Loading @@ -560,21 +565,18 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * */ // This is an asynchronous call. @Override public abstract void prepare(); /** * Pauses playback. Call play() to resume. */ // This is an asynchronous call. @Override public abstract void pause(); /** * Tries to play next data source if applicable. */ // This is an asynchronous call. @Override public abstract void skipToNext(); /** Loading @@ -584,7 +586,6 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * @param msec the offset in milliseconds from the start to seek to */ // This is an asynchronous call. @Override public void seekTo(long msec) { seekTo(msec, SEEK_PREVIOUS_SYNC /* mode */); } Loading @@ -594,7 +595,6 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * * @return the current position in milliseconds */ @Override public abstract long getCurrentPosition(); /** Loading @@ -603,7 +603,6 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * @return the duration in milliseconds, if no duration is available * (for example, if streaming live content), -1 is returned. */ @Override public abstract long getDuration(); /** Loading @@ -615,25 +614,60 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * * @return the current buffered media source position in milliseconds */ @Override public abstract long getBufferedPosition(); /** * Gets the current player state. * * @return the current player state. * MediaPlayer2 has not been prepared or just has been reset. * In this state, MediaPlayer2 doesn't fetch data. * @hide */ @Override public abstract @PlayerState int getPlayerState(); public static final int PLAYER_STATE_IDLE = 1001; /** * Gets the current buffering state of the player. * During buffering, see {@link #getBufferedPosition()} for the quantifying the amount already * buffered. * @return the buffering state, one of the following: * MediaPlayer2 has been just prepared. * In this state, MediaPlayer2 just fetches data from media source, * but doesn't actively render data. * @hide */ @Override public abstract @BuffState int getBufferingState(); public static final int PLAYER_STATE_PREPARED = 1002; /** * MediaPlayer2 is paused. * In this state, MediaPlayer2 doesn't actively render data. * @hide */ public static final int PLAYER_STATE_PAUSED = 1003; /** * MediaPlayer2 is actively playing back data. * @hide */ public static final int PLAYER_STATE_PLAYING = 1004; /** * MediaPlayer2 has hit some fatal error and cannot continue playback. * @hide */ public static final int PLAYER_STATE_ERROR = 1005; /** * @hide */ @IntDef(flag = false, prefix = "MEDIAPLAYER2_STATE", value = { PLAYER_STATE_IDLE, PLAYER_STATE_PREPARED, PLAYER_STATE_PAUSED, PLAYER_STATE_PLAYING, PLAYER_STATE_ERROR }) @Retention(RetentionPolicy.SOURCE) public @interface MediaPlayer2State {} /** * Gets the current player state. * * @return the current player state. */ public abstract @MediaPlayer2State int getState(); /** * Sets the audio attributes for this MediaPlayer2. Loading @@ -643,14 +677,12 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * @param attributes a non-null set of audio attributes */ // This is an asynchronous call. @Override public abstract void setAudioAttributes(@NonNull AudioAttributes attributes); /** * Gets the audio attributes for this MediaPlayer2. * @return attributes a set of audio attributes */ @Override public abstract @Nullable AudioAttributes getAudioAttributes(); /** Loading @@ -659,7 +691,6 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * @param dsd the descriptor of data source you want to play */ // This is an asynchronous call. @Override public abstract void setDataSource(@NonNull DataSourceDesc dsd); /** Loading @@ -669,7 +700,6 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * @param dsd the descriptor of data source you want to play after current one */ // This is an asynchronous call. @Override public abstract void setNextDataSource(@NonNull DataSourceDesc dsd); /** Loading @@ -678,7 +708,6 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * @param dsds the list of data sources you want to play after current one */ // This is an asynchronous call. @Override public abstract void setNextDataSources(@NonNull List<DataSourceDesc> dsds); /** Loading @@ -686,7 +715,6 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * * @return the current DataSourceDesc */ @Override public abstract @NonNull DataSourceDesc getCurrentDataSource(); /** Loading @@ -694,43 +722,8 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * @param loop true if the current data source is meant to loop. */ // This is an asynchronous call. @Override public abstract void loopCurrent(boolean loop); /** * Sets the playback speed. * A value of 1.0f is the default playback value. * A negative value indicates reverse playback, check {@link #isReversePlaybackSupported()} * before using negative values.<br> * After changing the playback speed, it is recommended to query the actual speed supported * by the player, see {@link #getPlaybackSpeed()}. * @param speed the desired playback speed */ // This is an asynchronous call. @Override public abstract void setPlaybackSpeed(float speed); /** * Returns the actual playback speed to be used by the player when playing. * Note that it may differ from the speed set in {@link #setPlaybackSpeed(float)}. * @return the actual playback speed */ @Override public float getPlaybackSpeed() { return 1.0f; } /** * Indicates whether reverse playback is supported. * Reverse playback is indicated by negative playback speeds, see * {@link #setPlaybackSpeed(float)}. * @return true if reverse playback is supported. */ @Override public boolean isReversePlaybackSupported() { return false; } /** * Sets the volume of the audio of the media to play, expressed as a linear multiplier * on the audio samples. Loading @@ -741,7 +734,6 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * @param volume a value between 0.0f and {@link #getMaxPlayerVolume()}. */ // This is an asynchronous call. @Override public abstract void setPlayerVolume(float volume); /** Loading @@ -749,35 +741,15 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * Note that it does not take into account the associated stream volume. * @return the player volume. */ @Override public abstract float getPlayerVolume(); /** * @return the maximum volume that can be used in {@link #setPlayerVolume(float)}. */ @Override public float getMaxPlayerVolume() { return 1.0f; } /** * Adds a callback to be notified of events for this player. * @param e the {@link Executor} to be used for the events. * @param cb the callback to receive the events. */ // This is a synchronous call. @Override public abstract void registerPlayerEventCallback(@NonNull Executor e, @NonNull PlayerEventCallback cb); /** * Removes a previously registered callback for player events * @param cb the callback to remove */ // This is a synchronous call. @Override public abstract void unregisterPlayerEventCallback(@NonNull PlayerEventCallback cb); /** * Create a request parcel which can be routed to the native media * player using {@link #invoke(Parcel, Parcel)}. The Parcel Loading Loading @@ -973,7 +945,8 @@ public abstract class MediaPlayer2 extends MediaPlayerBase */ // This is a synchronous call. @Override public abstract void removeOnRoutingChangedListener(AudioRouting.OnRoutingChangedListener listener); public abstract void removeOnRoutingChangedListener( AudioRouting.OnRoutingChangedListener listener); /** * Set the low-level power management behavior for this MediaPlayer2. Loading Loading @@ -1024,7 +997,8 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * no display surface was set, or the height has not been determined * yet. The {@code EventCallback} can be registered via * {@link #setEventCallback(Executor, EventCallback)} to provide a * notification {@code EventCallback.onVideoSizeChanged} when the height is available. * notification {@code EventCallback.onVideoSizeChanged} when the height is * available. */ public abstract int getVideoHeight(); Loading @@ -1050,60 +1024,6 @@ public abstract class MediaPlayer2 extends MediaPlayerBase */ public abstract boolean isPlaying(); /** * MediaPlayer2 has not been prepared or just has been reset. * In this state, MediaPlayer2 doesn't fetch data. * @hide */ public static final int MEDIAPLAYER2_STATE_IDLE = 1; /** * MediaPlayer2 has been just prepared. * In this state, MediaPlayer2 just fetches data from media source, * but doesn't actively render data. * @hide */ public static final int MEDIAPLAYER2_STATE_PREPARED = 2; /** * MediaPlayer2 is paused. * In this state, MediaPlayer2 doesn't actively render data. * @hide */ public static final int MEDIAPLAYER2_STATE_PAUSED = 3; /** * MediaPlayer2 is actively playing back data. * @hide */ public static final int MEDIAPLAYER2_STATE_PLAYING = 4; /** * MediaPlayer2 has hit some fatal error and cannot continue playback. * @hide */ public static final int MEDIAPLAYER2_STATE_ERROR = 5; /** * @hide */ @IntDef(flag = false, prefix = "MEDIAPLAYER2_STATE", value = { MEDIAPLAYER2_STATE_IDLE, MEDIAPLAYER2_STATE_PREPARED, MEDIAPLAYER2_STATE_PAUSED, MEDIAPLAYER2_STATE_PLAYING, MEDIAPLAYER2_STATE_ERROR }) @Retention(RetentionPolicy.SOURCE) public @interface MediaPlayer2State {} /** * Gets the current MediaPlayer2 state. * * @return the current MediaPlayer2 state. * @hide */ public abstract @MediaPlayer2State int getMediaPlayer2State(); /** * Gets the current buffering management params used by the source component. * Calling it only after {@code setDataSource} has been called. Loading Loading @@ -1383,7 +1303,6 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * data source and calling prepare(). */ // This is a synchronous call. @Override public abstract void reset(); /** Loading Loading @@ -1718,7 +1637,8 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * @param width the width of the video * @param height the height of the video */ public void onVideoSizeChanged(MediaPlayer2 mp, DataSourceDesc dsd, int width, int height) { } public void onVideoSizeChanged( MediaPlayer2 mp, DataSourceDesc dsd, int width, int height) { } /** * Called to indicate an avaliable timed text Loading Loading @@ -2200,7 +2120,6 @@ public abstract class MediaPlayer2 extends MediaPlayerBase CALL_COMPLETED_SET_NEXT_DATA_SOURCE, CALL_COMPLETED_SET_NEXT_DATA_SOURCES, CALL_COMPLETED_SET_PLAYBACK_PARAMS, CALL_COMPLETED_SET_PLAYBACK_SPEED, CALL_COMPLETED_SET_PLAYER_VOLUME, CALL_COMPLETED_SET_SURFACE, CALL_COMPLETED_SET_SYNC_PARAMS, Loading media/java/android/media/MediaPlayer2Impl.java +12 −101 Original line number Diff line number Diff line Loading @@ -173,6 +173,11 @@ public final class MediaPlayer2Impl extends MediaPlayer2 { native_setup(new WeakReference<MediaPlayer2Impl>(this)); } @Override public MediaPlayerBase getMediaPlayerBase() { return null; } /** * Releases the resources held by this {@code MediaPlayer2} object. * Loading Loading @@ -313,39 +318,11 @@ public final class MediaPlayer2Impl extends MediaPlayer2 { } @Override public @PlayerState int getPlayerState() { int mediaplayer2State = getMediaPlayer2State(); int playerState; switch (mediaplayer2State) { case MEDIAPLAYER2_STATE_IDLE: playerState = PLAYER_STATE_IDLE; break; case MEDIAPLAYER2_STATE_PREPARED: case MEDIAPLAYER2_STATE_PAUSED: playerState = PLAYER_STATE_PAUSED; break; case MEDIAPLAYER2_STATE_PLAYING: playerState = PLAYER_STATE_PLAYING; break; case MEDIAPLAYER2_STATE_ERROR: default: playerState = PLAYER_STATE_ERROR; break; } return playerState; public @MediaPlayer2State int getState() { return native_getState(); } /** * Gets the current buffering state of the player. * During buffering, see {@link #getBufferedPosition()} for the quantifying the amount already * buffered. */ @Override public @BuffState int getBufferingState() { // TODO: use cached state or call native function. return BUFFERING_STATE_UNKNOWN; } private native int native_getState(); /** * Sets the audio attributes for this MediaPlayer2. Loading Loading @@ -427,8 +404,8 @@ public final class MediaPlayer2Impl extends MediaPlayer2 { mNextSourceState = NEXT_SOURCE_STATE_INIT; mNextSourcePlayPending = false; } int state = getMediaPlayer2State(); if (state != MEDIAPLAYER2_STATE_IDLE) { int state = getState(); if (state != PLAYER_STATE_IDLE) { synchronized (mSrcLock) { prepareNextDataSource_l(); } Loading Loading @@ -465,8 +442,8 @@ public final class MediaPlayer2Impl extends MediaPlayer2 { mNextSourceState = NEXT_SOURCE_STATE_INIT; mNextSourcePlayPending = false; } int state = getMediaPlayer2State(); if (state != MEDIAPLAYER2_STATE_IDLE) { int state = getState(); if (state != PLAYER_STATE_IDLE) { synchronized (mSrcLock) { prepareNextDataSource_l(); } Loading Loading @@ -499,46 +476,6 @@ public final class MediaPlayer2Impl extends MediaPlayer2 { private native void setLooping(boolean looping); /** * Sets the playback speed. * A value of 1.0f is the default playback value. * A negative value indicates reverse playback, check {@link #isReversePlaybackSupported()} * before using negative values.<br> * After changing the playback speed, it is recommended to query the actual speed supported * by the player, see {@link #getPlaybackSpeed()}. * @param speed the desired playback speed */ @Override public void setPlaybackSpeed(float speed) { addTask(new Task(CALL_COMPLETED_SET_PLAYBACK_SPEED, false) { @Override void process() { _setPlaybackParams(getPlaybackParams().setSpeed(speed)); } }); } /** * Returns the actual playback speed to be used by the player when playing. * Note that it may differ from the speed set in {@link #setPlaybackSpeed(float)}. * @return the actual playback speed */ @Override public float getPlaybackSpeed() { return getPlaybackParams().getSpeed(); } /** * Indicates whether reverse playback is supported. * Reverse playback is indicated by negative playback speeds, see * {@link #setPlaybackSpeed(float)}. * @return true if reverse playback is supported. */ @Override public boolean isReversePlaybackSupported() { return false; } /** * Sets the volume of the audio of the media to play, expressed as a linear multiplier * on the audio samples. Loading Loading @@ -579,25 +516,6 @@ public final class MediaPlayer2Impl extends MediaPlayer2 { return 1.0f; } /** * Adds a callback to be notified of events for this player. * @param e the {@link Executor} to be used for the events. * @param cb the callback to receive the events. */ @Override public void registerPlayerEventCallback(@NonNull Executor e, @NonNull PlayerEventCallback cb) { } /** * Removes a previously registered callback for player events * @param cb the callback to remove */ @Override public void unregisterPlayerEventCallback(@NonNull PlayerEventCallback cb) { } private static final int NEXT_SOURCE_STATE_ERROR = -1; private static final int NEXT_SOURCE_STATE_INIT = 0; private static final int NEXT_SOURCE_STATE_PREPARING = 1; Loading Loading @@ -1355,13 +1273,6 @@ public final class MediaPlayer2Impl extends MediaPlayer2 { @Override public native boolean isPlaying(); @Override public @MediaPlayer2State int getMediaPlayer2State() { return native_getMediaPlayer2State(); } private native int native_getMediaPlayer2State(); /** * Gets the current buffering management params used by the source component. * Calling it only after {@code setDataSource} has been called. Loading media/jni/android_media_MediaPlayer2.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -786,13 +786,13 @@ android_media_MediaPlayer2_notifyAt(JNIEnv *env, jobject thiz, jlong mediaTimeUs } static jint android_media_MediaPlayer2_getMediaPlayer2State(JNIEnv *env, jobject thiz) android_media_MediaPlayer2_getState(JNIEnv *env, jobject thiz) { sp<MediaPlayer2> mp = getMediaPlayer(env, thiz); if (mp == NULL) { return MEDIAPLAYER2_STATE_IDLE; } return (jint)mp->getMediaPlayer2State(); return (jint)mp->getState(); } static jint Loading Loading @@ -1502,7 +1502,7 @@ static const JNINativeMethod gMethods[] = { {"_prepare", "()V", (void *)android_media_MediaPlayer2_prepare}, {"_start", "()V", (void *)android_media_MediaPlayer2_start}, {"_stop", "()V", (void *)android_media_MediaPlayer2_stop}, {"native_getMediaPlayer2State", "()I", (void *)android_media_MediaPlayer2_getMediaPlayer2State}, {"native_getState", "()I", (void *)android_media_MediaPlayer2_getState}, {"getVideoWidth", "()I", (void *)android_media_MediaPlayer2_getVideoWidth}, {"getVideoHeight", "()I", (void *)android_media_MediaPlayer2_getVideoHeight}, {"native_getMetrics", "()Landroid/os/PersistableBundle;", (void *)android_media_MediaPlayer2_native_getMetrics}, Loading Loading
media/java/android/media/MediaPlayer2.java +61 −142 Original line number Diff line number Diff line Loading @@ -453,8 +453,8 @@ import java.util.concurrent.Executor; * thread by default has a Looper running). * */ public abstract class MediaPlayer2 extends MediaPlayerBase implements SubtitleController.Listener public abstract class MediaPlayer2 implements SubtitleController.Listener , AutoCloseable , AudioRouting { /** * Create a MediaPlayer2 object. Loading Loading @@ -513,6 +513,12 @@ public abstract class MediaPlayer2 extends MediaPlayerBase // add hidden empty constructor so it doesn't show in SDK public MediaPlayer2() { } /** * Returns a {@link MediaPlayerBase} implementation which runs based on * this MediaPlayer2 instance. */ public abstract MediaPlayerBase getMediaPlayerBase(); /** * Releases the resources held by this {@code MediaPlayer2} object. * Loading Loading @@ -549,7 +555,6 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * */ // This is an asynchronous call. @Override public abstract void play(); /** Loading @@ -560,21 +565,18 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * */ // This is an asynchronous call. @Override public abstract void prepare(); /** * Pauses playback. Call play() to resume. */ // This is an asynchronous call. @Override public abstract void pause(); /** * Tries to play next data source if applicable. */ // This is an asynchronous call. @Override public abstract void skipToNext(); /** Loading @@ -584,7 +586,6 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * @param msec the offset in milliseconds from the start to seek to */ // This is an asynchronous call. @Override public void seekTo(long msec) { seekTo(msec, SEEK_PREVIOUS_SYNC /* mode */); } Loading @@ -594,7 +595,6 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * * @return the current position in milliseconds */ @Override public abstract long getCurrentPosition(); /** Loading @@ -603,7 +603,6 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * @return the duration in milliseconds, if no duration is available * (for example, if streaming live content), -1 is returned. */ @Override public abstract long getDuration(); /** Loading @@ -615,25 +614,60 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * * @return the current buffered media source position in milliseconds */ @Override public abstract long getBufferedPosition(); /** * Gets the current player state. * * @return the current player state. * MediaPlayer2 has not been prepared or just has been reset. * In this state, MediaPlayer2 doesn't fetch data. * @hide */ @Override public abstract @PlayerState int getPlayerState(); public static final int PLAYER_STATE_IDLE = 1001; /** * Gets the current buffering state of the player. * During buffering, see {@link #getBufferedPosition()} for the quantifying the amount already * buffered. * @return the buffering state, one of the following: * MediaPlayer2 has been just prepared. * In this state, MediaPlayer2 just fetches data from media source, * but doesn't actively render data. * @hide */ @Override public abstract @BuffState int getBufferingState(); public static final int PLAYER_STATE_PREPARED = 1002; /** * MediaPlayer2 is paused. * In this state, MediaPlayer2 doesn't actively render data. * @hide */ public static final int PLAYER_STATE_PAUSED = 1003; /** * MediaPlayer2 is actively playing back data. * @hide */ public static final int PLAYER_STATE_PLAYING = 1004; /** * MediaPlayer2 has hit some fatal error and cannot continue playback. * @hide */ public static final int PLAYER_STATE_ERROR = 1005; /** * @hide */ @IntDef(flag = false, prefix = "MEDIAPLAYER2_STATE", value = { PLAYER_STATE_IDLE, PLAYER_STATE_PREPARED, PLAYER_STATE_PAUSED, PLAYER_STATE_PLAYING, PLAYER_STATE_ERROR }) @Retention(RetentionPolicy.SOURCE) public @interface MediaPlayer2State {} /** * Gets the current player state. * * @return the current player state. */ public abstract @MediaPlayer2State int getState(); /** * Sets the audio attributes for this MediaPlayer2. Loading @@ -643,14 +677,12 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * @param attributes a non-null set of audio attributes */ // This is an asynchronous call. @Override public abstract void setAudioAttributes(@NonNull AudioAttributes attributes); /** * Gets the audio attributes for this MediaPlayer2. * @return attributes a set of audio attributes */ @Override public abstract @Nullable AudioAttributes getAudioAttributes(); /** Loading @@ -659,7 +691,6 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * @param dsd the descriptor of data source you want to play */ // This is an asynchronous call. @Override public abstract void setDataSource(@NonNull DataSourceDesc dsd); /** Loading @@ -669,7 +700,6 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * @param dsd the descriptor of data source you want to play after current one */ // This is an asynchronous call. @Override public abstract void setNextDataSource(@NonNull DataSourceDesc dsd); /** Loading @@ -678,7 +708,6 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * @param dsds the list of data sources you want to play after current one */ // This is an asynchronous call. @Override public abstract void setNextDataSources(@NonNull List<DataSourceDesc> dsds); /** Loading @@ -686,7 +715,6 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * * @return the current DataSourceDesc */ @Override public abstract @NonNull DataSourceDesc getCurrentDataSource(); /** Loading @@ -694,43 +722,8 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * @param loop true if the current data source is meant to loop. */ // This is an asynchronous call. @Override public abstract void loopCurrent(boolean loop); /** * Sets the playback speed. * A value of 1.0f is the default playback value. * A negative value indicates reverse playback, check {@link #isReversePlaybackSupported()} * before using negative values.<br> * After changing the playback speed, it is recommended to query the actual speed supported * by the player, see {@link #getPlaybackSpeed()}. * @param speed the desired playback speed */ // This is an asynchronous call. @Override public abstract void setPlaybackSpeed(float speed); /** * Returns the actual playback speed to be used by the player when playing. * Note that it may differ from the speed set in {@link #setPlaybackSpeed(float)}. * @return the actual playback speed */ @Override public float getPlaybackSpeed() { return 1.0f; } /** * Indicates whether reverse playback is supported. * Reverse playback is indicated by negative playback speeds, see * {@link #setPlaybackSpeed(float)}. * @return true if reverse playback is supported. */ @Override public boolean isReversePlaybackSupported() { return false; } /** * Sets the volume of the audio of the media to play, expressed as a linear multiplier * on the audio samples. Loading @@ -741,7 +734,6 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * @param volume a value between 0.0f and {@link #getMaxPlayerVolume()}. */ // This is an asynchronous call. @Override public abstract void setPlayerVolume(float volume); /** Loading @@ -749,35 +741,15 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * Note that it does not take into account the associated stream volume. * @return the player volume. */ @Override public abstract float getPlayerVolume(); /** * @return the maximum volume that can be used in {@link #setPlayerVolume(float)}. */ @Override public float getMaxPlayerVolume() { return 1.0f; } /** * Adds a callback to be notified of events for this player. * @param e the {@link Executor} to be used for the events. * @param cb the callback to receive the events. */ // This is a synchronous call. @Override public abstract void registerPlayerEventCallback(@NonNull Executor e, @NonNull PlayerEventCallback cb); /** * Removes a previously registered callback for player events * @param cb the callback to remove */ // This is a synchronous call. @Override public abstract void unregisterPlayerEventCallback(@NonNull PlayerEventCallback cb); /** * Create a request parcel which can be routed to the native media * player using {@link #invoke(Parcel, Parcel)}. The Parcel Loading Loading @@ -973,7 +945,8 @@ public abstract class MediaPlayer2 extends MediaPlayerBase */ // This is a synchronous call. @Override public abstract void removeOnRoutingChangedListener(AudioRouting.OnRoutingChangedListener listener); public abstract void removeOnRoutingChangedListener( AudioRouting.OnRoutingChangedListener listener); /** * Set the low-level power management behavior for this MediaPlayer2. Loading Loading @@ -1024,7 +997,8 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * no display surface was set, or the height has not been determined * yet. The {@code EventCallback} can be registered via * {@link #setEventCallback(Executor, EventCallback)} to provide a * notification {@code EventCallback.onVideoSizeChanged} when the height is available. * notification {@code EventCallback.onVideoSizeChanged} when the height is * available. */ public abstract int getVideoHeight(); Loading @@ -1050,60 +1024,6 @@ public abstract class MediaPlayer2 extends MediaPlayerBase */ public abstract boolean isPlaying(); /** * MediaPlayer2 has not been prepared or just has been reset. * In this state, MediaPlayer2 doesn't fetch data. * @hide */ public static final int MEDIAPLAYER2_STATE_IDLE = 1; /** * MediaPlayer2 has been just prepared. * In this state, MediaPlayer2 just fetches data from media source, * but doesn't actively render data. * @hide */ public static final int MEDIAPLAYER2_STATE_PREPARED = 2; /** * MediaPlayer2 is paused. * In this state, MediaPlayer2 doesn't actively render data. * @hide */ public static final int MEDIAPLAYER2_STATE_PAUSED = 3; /** * MediaPlayer2 is actively playing back data. * @hide */ public static final int MEDIAPLAYER2_STATE_PLAYING = 4; /** * MediaPlayer2 has hit some fatal error and cannot continue playback. * @hide */ public static final int MEDIAPLAYER2_STATE_ERROR = 5; /** * @hide */ @IntDef(flag = false, prefix = "MEDIAPLAYER2_STATE", value = { MEDIAPLAYER2_STATE_IDLE, MEDIAPLAYER2_STATE_PREPARED, MEDIAPLAYER2_STATE_PAUSED, MEDIAPLAYER2_STATE_PLAYING, MEDIAPLAYER2_STATE_ERROR }) @Retention(RetentionPolicy.SOURCE) public @interface MediaPlayer2State {} /** * Gets the current MediaPlayer2 state. * * @return the current MediaPlayer2 state. * @hide */ public abstract @MediaPlayer2State int getMediaPlayer2State(); /** * Gets the current buffering management params used by the source component. * Calling it only after {@code setDataSource} has been called. Loading Loading @@ -1383,7 +1303,6 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * data source and calling prepare(). */ // This is a synchronous call. @Override public abstract void reset(); /** Loading Loading @@ -1718,7 +1637,8 @@ public abstract class MediaPlayer2 extends MediaPlayerBase * @param width the width of the video * @param height the height of the video */ public void onVideoSizeChanged(MediaPlayer2 mp, DataSourceDesc dsd, int width, int height) { } public void onVideoSizeChanged( MediaPlayer2 mp, DataSourceDesc dsd, int width, int height) { } /** * Called to indicate an avaliable timed text Loading Loading @@ -2200,7 +2120,6 @@ public abstract class MediaPlayer2 extends MediaPlayerBase CALL_COMPLETED_SET_NEXT_DATA_SOURCE, CALL_COMPLETED_SET_NEXT_DATA_SOURCES, CALL_COMPLETED_SET_PLAYBACK_PARAMS, CALL_COMPLETED_SET_PLAYBACK_SPEED, CALL_COMPLETED_SET_PLAYER_VOLUME, CALL_COMPLETED_SET_SURFACE, CALL_COMPLETED_SET_SYNC_PARAMS, Loading
media/java/android/media/MediaPlayer2Impl.java +12 −101 Original line number Diff line number Diff line Loading @@ -173,6 +173,11 @@ public final class MediaPlayer2Impl extends MediaPlayer2 { native_setup(new WeakReference<MediaPlayer2Impl>(this)); } @Override public MediaPlayerBase getMediaPlayerBase() { return null; } /** * Releases the resources held by this {@code MediaPlayer2} object. * Loading Loading @@ -313,39 +318,11 @@ public final class MediaPlayer2Impl extends MediaPlayer2 { } @Override public @PlayerState int getPlayerState() { int mediaplayer2State = getMediaPlayer2State(); int playerState; switch (mediaplayer2State) { case MEDIAPLAYER2_STATE_IDLE: playerState = PLAYER_STATE_IDLE; break; case MEDIAPLAYER2_STATE_PREPARED: case MEDIAPLAYER2_STATE_PAUSED: playerState = PLAYER_STATE_PAUSED; break; case MEDIAPLAYER2_STATE_PLAYING: playerState = PLAYER_STATE_PLAYING; break; case MEDIAPLAYER2_STATE_ERROR: default: playerState = PLAYER_STATE_ERROR; break; } return playerState; public @MediaPlayer2State int getState() { return native_getState(); } /** * Gets the current buffering state of the player. * During buffering, see {@link #getBufferedPosition()} for the quantifying the amount already * buffered. */ @Override public @BuffState int getBufferingState() { // TODO: use cached state or call native function. return BUFFERING_STATE_UNKNOWN; } private native int native_getState(); /** * Sets the audio attributes for this MediaPlayer2. Loading Loading @@ -427,8 +404,8 @@ public final class MediaPlayer2Impl extends MediaPlayer2 { mNextSourceState = NEXT_SOURCE_STATE_INIT; mNextSourcePlayPending = false; } int state = getMediaPlayer2State(); if (state != MEDIAPLAYER2_STATE_IDLE) { int state = getState(); if (state != PLAYER_STATE_IDLE) { synchronized (mSrcLock) { prepareNextDataSource_l(); } Loading Loading @@ -465,8 +442,8 @@ public final class MediaPlayer2Impl extends MediaPlayer2 { mNextSourceState = NEXT_SOURCE_STATE_INIT; mNextSourcePlayPending = false; } int state = getMediaPlayer2State(); if (state != MEDIAPLAYER2_STATE_IDLE) { int state = getState(); if (state != PLAYER_STATE_IDLE) { synchronized (mSrcLock) { prepareNextDataSource_l(); } Loading Loading @@ -499,46 +476,6 @@ public final class MediaPlayer2Impl extends MediaPlayer2 { private native void setLooping(boolean looping); /** * Sets the playback speed. * A value of 1.0f is the default playback value. * A negative value indicates reverse playback, check {@link #isReversePlaybackSupported()} * before using negative values.<br> * After changing the playback speed, it is recommended to query the actual speed supported * by the player, see {@link #getPlaybackSpeed()}. * @param speed the desired playback speed */ @Override public void setPlaybackSpeed(float speed) { addTask(new Task(CALL_COMPLETED_SET_PLAYBACK_SPEED, false) { @Override void process() { _setPlaybackParams(getPlaybackParams().setSpeed(speed)); } }); } /** * Returns the actual playback speed to be used by the player when playing. * Note that it may differ from the speed set in {@link #setPlaybackSpeed(float)}. * @return the actual playback speed */ @Override public float getPlaybackSpeed() { return getPlaybackParams().getSpeed(); } /** * Indicates whether reverse playback is supported. * Reverse playback is indicated by negative playback speeds, see * {@link #setPlaybackSpeed(float)}. * @return true if reverse playback is supported. */ @Override public boolean isReversePlaybackSupported() { return false; } /** * Sets the volume of the audio of the media to play, expressed as a linear multiplier * on the audio samples. Loading Loading @@ -579,25 +516,6 @@ public final class MediaPlayer2Impl extends MediaPlayer2 { return 1.0f; } /** * Adds a callback to be notified of events for this player. * @param e the {@link Executor} to be used for the events. * @param cb the callback to receive the events. */ @Override public void registerPlayerEventCallback(@NonNull Executor e, @NonNull PlayerEventCallback cb) { } /** * Removes a previously registered callback for player events * @param cb the callback to remove */ @Override public void unregisterPlayerEventCallback(@NonNull PlayerEventCallback cb) { } private static final int NEXT_SOURCE_STATE_ERROR = -1; private static final int NEXT_SOURCE_STATE_INIT = 0; private static final int NEXT_SOURCE_STATE_PREPARING = 1; Loading Loading @@ -1355,13 +1273,6 @@ public final class MediaPlayer2Impl extends MediaPlayer2 { @Override public native boolean isPlaying(); @Override public @MediaPlayer2State int getMediaPlayer2State() { return native_getMediaPlayer2State(); } private native int native_getMediaPlayer2State(); /** * Gets the current buffering management params used by the source component. * Calling it only after {@code setDataSource} has been called. Loading
media/jni/android_media_MediaPlayer2.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -786,13 +786,13 @@ android_media_MediaPlayer2_notifyAt(JNIEnv *env, jobject thiz, jlong mediaTimeUs } static jint android_media_MediaPlayer2_getMediaPlayer2State(JNIEnv *env, jobject thiz) android_media_MediaPlayer2_getState(JNIEnv *env, jobject thiz) { sp<MediaPlayer2> mp = getMediaPlayer(env, thiz); if (mp == NULL) { return MEDIAPLAYER2_STATE_IDLE; } return (jint)mp->getMediaPlayer2State(); return (jint)mp->getState(); } static jint Loading Loading @@ -1502,7 +1502,7 @@ static const JNINativeMethod gMethods[] = { {"_prepare", "()V", (void *)android_media_MediaPlayer2_prepare}, {"_start", "()V", (void *)android_media_MediaPlayer2_start}, {"_stop", "()V", (void *)android_media_MediaPlayer2_stop}, {"native_getMediaPlayer2State", "()I", (void *)android_media_MediaPlayer2_getMediaPlayer2State}, {"native_getState", "()I", (void *)android_media_MediaPlayer2_getState}, {"getVideoWidth", "()I", (void *)android_media_MediaPlayer2_getVideoWidth}, {"getVideoHeight", "()I", (void *)android_media_MediaPlayer2_getVideoHeight}, {"native_getMetrics", "()Landroid/os/PersistableBundle;", (void *)android_media_MediaPlayer2_native_getMetrics}, Loading