diff options
author | Sungsoo Lim <sungsoo@google.com> | 2019-04-26 08:07:39 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-04-26 08:07:39 +0000 |
commit | 6915d78015f9a14e39648a61fc31f2e4869cda7d (patch) | |
tree | 26b33e5ddbc122efb47390e3c07f729369503e62 | |
parent | bdba3ad806b58223c4db4694196397ef6fcc63c7 (diff) | |
parent | 97ed05cac1e2b810a8d6acb08f3f0eff4cd63744 (diff) | |
download | support-6915d78015f9a14e39648a61fc31f2e4869cda7d.tar.gz |
Merge "Make MediaPlayer be a final class" into androidx-master-dev
8 files changed, 17 insertions, 68 deletions
diff --git a/media2/player/api/1.0.0-alpha05.txt b/media2/player/api/1.0.0-alpha05.txt index 85b0b16df99..1cada04981b 100644 --- a/media2/player/api/1.0.0-alpha05.txt +++ b/media2/player/api/1.0.0-alpha05.txt @@ -1,7 +1,7 @@ // Signature format: 3.0 package androidx.media2.player { - public class MediaPlayer extends androidx.media2.common.SessionPlayer { + public final class MediaPlayer extends androidx.media2.common.SessionPlayer { ctor public MediaPlayer(android.content.Context); method public com.google.common.util.concurrent.ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> addPlaylistItem(int, androidx.media2.common.MediaItem); method public com.google.common.util.concurrent.ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> attachAuxEffect(int); diff --git a/media2/player/api/current.txt b/media2/player/api/current.txt index 85b0b16df99..1cada04981b 100644 --- a/media2/player/api/current.txt +++ b/media2/player/api/current.txt @@ -1,7 +1,7 @@ // Signature format: 3.0 package androidx.media2.player { - public class MediaPlayer extends androidx.media2.common.SessionPlayer { + public final class MediaPlayer extends androidx.media2.common.SessionPlayer { ctor public MediaPlayer(android.content.Context); method public com.google.common.util.concurrent.ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> addPlaylistItem(int, androidx.media2.common.MediaItem); method public com.google.common.util.concurrent.ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> attachAuxEffect(int); diff --git a/media2/player/api/restricted_1.0.0-alpha05.txt b/media2/player/api/restricted_1.0.0-alpha05.txt index 863d9b8da5f..ae5648ecf3f 100644 --- a/media2/player/api/restricted_1.0.0-alpha05.txt +++ b/media2/player/api/restricted_1.0.0-alpha05.txt @@ -1,7 +1,7 @@ // Signature format: 3.0 package androidx.media2.player { - public class MediaPlayer extends androidx.media2.common.SessionPlayer { + public final class MediaPlayer extends androidx.media2.common.SessionPlayer { method @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX) public com.google.common.util.concurrent.ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> deselectTrack(androidx.media2.player.MediaPlayer.TrackInfo); method @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX) public androidx.media2.player.MediaPlayer.DrmInfo? getDrmInfo(); method @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX) public android.media.MediaDrm.KeyRequest getDrmKeyRequest(byte[]?, byte[]?, String?, int, java.util.Map<java.lang.String,java.lang.String>?) throws androidx.media2.player.MediaPlayer.NoDrmSchemeException; diff --git a/media2/player/api/restricted_current.txt b/media2/player/api/restricted_current.txt index 863d9b8da5f..ae5648ecf3f 100644 --- a/media2/player/api/restricted_current.txt +++ b/media2/player/api/restricted_current.txt @@ -1,7 +1,7 @@ // Signature format: 3.0 package androidx.media2.player { - public class MediaPlayer extends androidx.media2.common.SessionPlayer { + public final class MediaPlayer extends androidx.media2.common.SessionPlayer { method @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX) public com.google.common.util.concurrent.ListenableFuture<androidx.media2.common.SessionPlayer.PlayerResult> deselectTrack(androidx.media2.player.MediaPlayer.TrackInfo); method @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX) public androidx.media2.player.MediaPlayer.DrmInfo? getDrmInfo(); method @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX) public android.media.MediaDrm.KeyRequest getDrmKeyRequest(byte[]?, byte[]?, String?, int, java.util.Map<java.lang.String,java.lang.String>?) throws androidx.media2.player.MediaPlayer.NoDrmSchemeException; diff --git a/media2/player/src/androidTest/java/androidx/media2/player/MediaPlayer_AudioFocusTest.java b/media2/player/src/androidTest/java/androidx/media2/player/MediaPlayer_AudioFocusTest.java index 2ac95698e58..e78f8b1bb91 100644 --- a/media2/player/src/androidTest/java/androidx/media2/player/MediaPlayer_AudioFocusTest.java +++ b/media2/player/src/androidTest/java/androidx/media2/player/MediaPlayer_AudioFocusTest.java @@ -38,7 +38,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import android.content.Context; import android.content.Intent; @@ -57,8 +56,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.LargeTest; import androidx.test.filters.SdkSuppress; import androidx.test.platform.app.InstrumentationRegistry; - -import com.google.common.util.concurrent.ListenableFuture; +import androidx.testutils.PollingCheck; import org.junit.After; import org.junit.AfterClass; @@ -211,27 +209,8 @@ public class MediaPlayer_AudioFocusTest extends MediaPlayerTestBase { private void testDuckedAfterAction(final AudioAttributesCompat attr, final PlayerRunnable action) throws Exception { - final CountDownLatch latchForDucked = new CountDownLatch(1); final CountDownLatch latchForPlaying = new CountDownLatch(1); - try { - mInstrumentation.runOnMainSync(new Runnable() { - public void run() { - mPlayer = new MediaPlayer(mActivity) { - @Override - public ListenableFuture<PlayerResult> setPlayerVolume(float volume) { - if (volume < getMaxPlayerVolume()) { - latchForDucked.countDown(); - } - return super.setPlayerVolume(volume); - } - }; - } - }); - } catch (Throwable e) { - fail(); - } - initPlayer(attr); mPlayer.registerPlayerCallback(sHandlerExecutor, new SessionPlayer.PlayerCallback() { @Override @@ -245,13 +224,17 @@ public class MediaPlayer_AudioFocusTest extends MediaPlayerTestBase { // Playback becomes PLAYING needs to be propagated to the session and its focus handler. // Wait for a while for that. assertTrue(latchForPlaying.await(WAIT_TIME_MS, TimeUnit.MILLISECONDS)); - assertTrue(latchForDucked.getCount() > 0); + final float curVolume = mPlayer.getPlayerVolume(); // Do something that would pause playback. action.run(mPlayer); - // Wait until pause actually taking effect. - assertTrue(latchForDucked.await(WAIT_TIME_MS, TimeUnit.MILLISECONDS)); + new PollingCheck(WAIT_TIME_MS) { + @Override + protected boolean check() { + return mPlayer.getPlayerVolume() < curVolume || curVolume == 0.0; + } + }.run(); } @Test diff --git a/media2/player/src/main/java/androidx/media2/player/MediaPlayer.java b/media2/player/src/main/java/androidx/media2/player/MediaPlayer.java index b4fd33c0d37..a384522f39a 100644 --- a/media2/player/src/main/java/androidx/media2/player/MediaPlayer.java +++ b/media2/player/src/main/java/androidx/media2/player/MediaPlayer.java @@ -141,7 +141,7 @@ import java.util.concurrent.Executors; * <a href="{@docRoot}guide/topics/media-apps/audio-focus.html">Managing audio focus</a> * <p> */ -public class MediaPlayer extends SessionPlayer { +public final class MediaPlayer extends SessionPlayer { private static final String TAG = "MediaPlayer"; /** diff --git a/media2/widget/src/main/java/androidx/media2/widget/VideoView.java b/media2/widget/src/main/java/androidx/media2/widget/VideoView.java index 7f0af8fcea1..3041f4e16a1 100644 --- a/media2/widget/src/main/java/androidx/media2/widget/VideoView.java +++ b/media2/widget/src/main/java/androidx/media2/widget/VideoView.java @@ -170,7 +170,7 @@ public class VideoView extends SelectiveLayout { VideoTextureView mTextureView; VideoSurfaceView mSurfaceView; - VideoViewPlayer mMediaPlayer; + MediaPlayer mMediaPlayer; MediaItem mMediaItem; MediaControlView mMediaControlView; MediaSession mMediaSession; @@ -527,7 +527,7 @@ public class VideoView extends SelectiveLayout { // Note: MediaPlayer and MediaSession instances are created in onAttachedToWindow() // and closed in onDetachedFromWindow(). if (mMediaPlayer == null) { - mMediaPlayer = new VideoViewPlayer(getContext()); + mMediaPlayer = new MediaPlayer(getContext()); mSurfaceView.setMediaPlayer(mMediaPlayer); mTextureView.setMediaPlayer(mMediaPlayer); @@ -674,7 +674,7 @@ public class VideoView extends SelectiveLayout { try { if (mMediaPlayer == null) { - mMediaPlayer = new VideoViewPlayer(getContext()); + mMediaPlayer = new MediaPlayer(getContext()); } mSurfaceView.setMediaPlayer(mMediaPlayer); mTextureView.setMediaPlayer(mMediaPlayer); @@ -1009,7 +1009,7 @@ public class VideoView extends SelectiveLayout { } } - if (player instanceof VideoViewPlayer) { + if (player instanceof MediaPlayer) { if (needToStart()) { mMediaSession.getPlayer().play(); } diff --git a/media2/widget/src/main/java/androidx/media2/widget/VideoViewPlayer.java b/media2/widget/src/main/java/androidx/media2/widget/VideoViewPlayer.java deleted file mode 100644 index 5fb1de7eab3..00000000000 --- a/media2/widget/src/main/java/androidx/media2/widget/VideoViewPlayer.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2018 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package androidx.media2.widget; - -import android.content.Context; - -import androidx.media2.player.MediaPlayer; - -import com.google.common.util.concurrent.ListenableFuture; - -class VideoViewPlayer extends MediaPlayer { - VideoViewPlayer(Context context) { - super(context); - } - - @Override - public ListenableFuture<PlayerResult> seekTo(long position) { - return super.seekTo(position, SEEK_CLOSEST); - } -} |