Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaSessionTabHelper.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaSessionTabHelper.java b/chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaSessionTabHelper.java |
| index 19252e1106b262e2fa3f854d5bc5f0e043cc2386..7cf7fb0dc209f85b8e179aa99e0808e4cc47b7c9 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaSessionTabHelper.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaSessionTabHelper.java |
| @@ -19,8 +19,8 @@ import org.chromium.chrome.browser.tab.EmptyTabObserver; |
| import org.chromium.chrome.browser.tab.Tab; |
| import org.chromium.chrome.browser.tab.TabObserver; |
| import org.chromium.components.url_formatter.UrlFormatter; |
| +import org.chromium.content_public.browser.MediaSessionDelegate; |
| import org.chromium.content_public.browser.WebContents; |
| -import org.chromium.content_public.browser.WebContentsObserver; |
| import org.chromium.content_public.common.MediaMetadata; |
| import org.chromium.ui.base.WindowAndroid; |
| @@ -43,7 +43,7 @@ public class MediaSessionTabHelper implements MediaImageCallback { |
| private Bitmap mCurrentMediaImage = null; |
| private String mOrigin = null; |
| private WebContents mWebContents; |
|
whywhat
2016/10/20 15:38:33
this seems to be unused, I guess destroy() is hand
Zhiqiang Zhang (Slow)
2016/10/20 16:22:32
destroy() is now MediaSessionDelegate.mediaSession
|
| - private WebContentsObserver mWebContentsObserver; |
| + private MediaSessionDelegate mMediaSessionDelegate; |
| private int mPreviousVolumeControlStream = AudioManager.USE_DEFAULT_STREAM_TYPE; |
| private MediaNotificationInfo.Builder mNotificationInfoBuilder = null; |
| // The fallback title if |mPageMetadata| is null or its title is empty. |
| @@ -59,24 +59,21 @@ public class MediaSessionTabHelper implements MediaImageCallback { |
| public void onPlay(int actionSource) { |
| MediaSessionUMA |
| .recordPlay(MediaSessionTabHelper.convertMediaActionSourceToUMA(actionSource)); |
| - |
| - mWebContents.resumeMediaSession(); |
| + if (mMediaSessionDelegate != null) mMediaSessionDelegate.resumeMediaSession(); |
| } |
| @Override |
| public void onPause(int actionSource) { |
| MediaSessionUMA.recordPause( |
| MediaSessionTabHelper.convertMediaActionSourceToUMA(actionSource)); |
| - |
| - mWebContents.suspendMediaSession(); |
| + if (mMediaSessionDelegate != null) mMediaSessionDelegate.suspendMediaSession(); |
| } |
| @Override |
| public void onStop(int actionSource) { |
| MediaSessionUMA |
| .recordStop(MediaSessionTabHelper.convertMediaActionSourceToUMA(actionSource)); |
| - |
| - mWebContents.stopMediaSession(); |
| + if (mMediaSessionDelegate != null) mMediaSessionDelegate.stopMediaSession(); |
| } |
| }; |
| @@ -92,16 +89,16 @@ public class MediaSessionTabHelper implements MediaImageCallback { |
| mNotificationInfoBuilder = null; |
| } |
| - private WebContentsObserver createWebContentsObserver(WebContents webContents) { |
| - return new WebContentsObserver(webContents) { |
| + private MediaSessionDelegate createMediaSessionDelegate(WebContents webContents) { |
| + MediaSessionDelegate delegate = new MediaSessionDelegate() { |
| @Override |
| - public void destroy() { |
| + public void mediaSessionDisconnected() { |
| hideNotification(); |
| - super.destroy(); |
| } |
| @Override |
| public void mediaSessionStateChanged(boolean isControllable, boolean isPaused) { |
| + Log.i(TAG, "Android MediaSessionStateChanged()"); |
| if (!isControllable) { |
| hideNotification(); |
| return; |
| @@ -150,6 +147,9 @@ public class MediaSessionTabHelper implements MediaImageCallback { |
| updateNotificationMetadata(); |
| } |
| }; |
| + Log.i(TAG, "createMediaSessionDelegate()"); |
| + webContents.addMediaSessionDelegate(delegate); |
| + return delegate; |
| } |
| private void setWebContents(WebContents webContents) { |
| @@ -157,13 +157,17 @@ public class MediaSessionTabHelper implements MediaImageCallback { |
| cleanupWebContents(); |
| mWebContents = webContents; |
| - if (mWebContents != null) mWebContentsObserver = createWebContentsObserver(mWebContents); |
| + if (mWebContents != null) { |
| + if (mMediaSessionDelegate != null) mMediaSessionDelegate.unlinkMediaSession(); |
| + |
| + mMediaSessionDelegate = createMediaSessionDelegate(mWebContents); |
| + } |
| mMediaImageManager.setWebContents(mWebContents); |
| } |
| private void cleanupWebContents() { |
| - if (mWebContentsObserver != null) mWebContentsObserver.destroy(); |
| - mWebContentsObserver = null; |
| + if (mMediaSessionDelegate != null) mMediaSessionDelegate.unlinkMediaSession(); |
| + mMediaSessionDelegate = null; |
| mWebContents = null; |
| } |