summaryrefslogtreecommitdiffstats
path: root/mobile/android/base/java/org/mozilla/gecko/PresentationMediaPlayerManager.java
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /mobile/android/base/java/org/mozilla/gecko/PresentationMediaPlayerManager.java
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'mobile/android/base/java/org/mozilla/gecko/PresentationMediaPlayerManager.java')
-rw-r--r--mobile/android/base/java/org/mozilla/gecko/PresentationMediaPlayerManager.java149
1 files changed, 149 insertions, 0 deletions
diff --git a/mobile/android/base/java/org/mozilla/gecko/PresentationMediaPlayerManager.java b/mobile/android/base/java/org/mozilla/gecko/PresentationMediaPlayerManager.java
new file mode 100644
index 000000000..e44096489
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/PresentationMediaPlayerManager.java
@@ -0,0 +1,149 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.gecko;
+
+import android.annotation.TargetApi;
+import android.app.Presentation;
+import android.content.Context;
+import android.os.Bundle;
+import android.support.v7.media.MediaRouter;
+import android.util.Log;
+import android.view.Display;
+import android.view.Surface;
+import android.view.SurfaceHolder;
+import android.view.SurfaceView;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+
+import org.mozilla.gecko.AppConstants.Versions;
+
+import org.mozilla.gecko.annotation.WrapForJNI;
+
+/**
+ * A MediaPlayerManager with API 17+ Presentation support.
+ */
+@TargetApi(17)
+public class PresentationMediaPlayerManager extends MediaPlayerManager {
+
+ private static final String LOGTAG = "Gecko" + PresentationMediaPlayerManager.class.getSimpleName();
+
+ private GeckoPresentation presentation;
+
+ public PresentationMediaPlayerManager() {
+ if (!Versions.feature17Plus) {
+ throw new IllegalStateException(PresentationMediaPlayerManager.class.getSimpleName() +
+ " does not support < API 17");
+ }
+ }
+
+ @Override
+ public void onStop() {
+ super.onStop();
+ if (presentation != null) {
+ presentation.dismiss();
+ presentation = null;
+ }
+ }
+
+ @Override
+ protected void updatePresentation() {
+ if (mediaRouter == null) {
+ return;
+ }
+
+ if (isPresentationMode) {
+ return;
+ }
+
+ MediaRouter.RouteInfo route = mediaRouter.getSelectedRoute();
+ Display display = route != null ? route.getPresentationDisplay() : null;
+
+ if (display != null) {
+ if ((presentation != null) && (presentation.getDisplay() != display)) {
+ presentation.dismiss();
+ presentation = null;
+ }
+
+ if (presentation == null) {
+ final GeckoView geckoView = (GeckoView) getActivity().findViewById(R.id.layer_view);
+ presentation = new GeckoPresentation(getActivity(), display, geckoView);
+
+ try {
+ presentation.show();
+ } catch (WindowManager.InvalidDisplayException ex) {
+ Log.w(LOGTAG, "Couldn't show presentation! Display was removed in "
+ + "the meantime.", ex);
+ presentation = null;
+ }
+ }
+ } else if (presentation != null) {
+ presentation.dismiss();
+ presentation = null;
+ }
+ }
+
+ @WrapForJNI(calledFrom = "ui")
+ /* protected */ static native void invalidateAndScheduleComposite(GeckoView geckoView);
+
+ @WrapForJNI(calledFrom = "ui")
+ /* protected */ static native void addPresentationSurface(GeckoView geckoView, Surface surface);
+
+ @WrapForJNI(calledFrom = "ui")
+ /* protected */ static native void removePresentationSurface();
+
+ private static final class GeckoPresentation extends Presentation {
+ private SurfaceView mView;
+ private GeckoView mGeckoView;
+
+ public GeckoPresentation(Context context, Display display, GeckoView geckoView) {
+ super(context, display);
+
+ mGeckoView = geckoView;
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ mView = new SurfaceView(getContext());
+ setContentView(mView, new ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT));
+ mView.getHolder().addCallback(new SurfaceListener(mGeckoView));
+ }
+ }
+
+ private static final class SurfaceListener implements SurfaceHolder.Callback {
+ private GeckoView mGeckoView;
+
+ public SurfaceListener(GeckoView geckoView) {
+ mGeckoView = geckoView;
+ }
+
+ @Override
+ public void surfaceChanged(SurfaceHolder holder, int format, int width,
+ int height) {
+ // Surface changed so force a composite
+ if (GeckoThread.isStateAtLeast(GeckoThread.State.PROFILE_READY)) {
+ invalidateAndScheduleComposite(mGeckoView);
+ }
+ }
+
+ @Override
+ public void surfaceCreated(SurfaceHolder holder) {
+ if (GeckoThread.isStateAtLeast(GeckoThread.State.PROFILE_READY)) {
+ addPresentationSurface(mGeckoView, holder.getSurface());
+ }
+ }
+
+ @Override
+ public void surfaceDestroyed(SurfaceHolder holder) {
+ if (GeckoThread.isStateAtLeast(GeckoThread.State.PROFILE_READY)) {
+ removePresentationSurface();
+ }
+ }
+ }
+}