diff --git a/plugin.xml b/plugin.xml index b844c73..6f77dad 100644 --- a/plugin.xml +++ b/plugin.xml @@ -19,7 +19,7 @@ - + diff --git a/src/android/Configuration.java b/src/android/Configuration.java index 9d73cf9..efd3ff5 100644 --- a/src/android/Configuration.java +++ b/src/android/Configuration.java @@ -54,6 +54,10 @@ public boolean isAudioOnly() { return config.optBoolean("audioOnly"); } + public boolean isRunBehindWebViewMode() { + return config.optBoolean("runBehindWebView"); + } + public boolean autoPlay() { return config.optBoolean("autoPlay", true); } diff --git a/src/android/Player.java b/src/android/Player.java index 1f5685c..bde3431 100644 --- a/src/android/Player.java +++ b/src/android/Player.java @@ -25,6 +25,8 @@ of this software and associated documentation files (the "Software"), to deal import android.app.*; import android.content.*; +import android.content.res.Resources; +import android.graphics.Color; import android.media.*; import android.net.*; import android.os.*; @@ -106,7 +108,7 @@ public void onPositionDiscontinuity(int reason) { public void onRepeatModeChanged(int newRepeatMode) { // Need to see if we want to send this to Cordova. } - + @Override public void onSeekProcessed() { } @@ -116,7 +118,7 @@ public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) { } @Override - public void onTimelineChanged(Timeline timeline, Object manifest) { + public void onTimelineChanged(Timeline timeline, Object manifest, int reason) { JSONObject payload = Payload.timelineChangedEvent(Player.this.exoPlayer, timeline, manifest); new CallbackResponse(Player.this.callbackContext).send(PluginResult.Status.OK, payload, true); } @@ -201,13 +203,37 @@ else if (focusChange == AudioManager.AUDIOFOCUS_LOSS) { } }; - public void createPlayer() { + public void createPlayer(CordovaWebView cordovaWebView) { if (!config.isAudioOnly()) { - createDialog(); + if (config.isRunBehindWebViewMode()) { + createBehindWebView(cordovaWebView); + } else { + createDialog(); + } } preparePlayer(config.getUri()); } + public void createBehindWebView(CordovaWebView cordovaWebView){ + webView.getView().setBackgroundColor(Color.TRANSPARENT); + + FrameLayout wrapperFrameLayout = (FrameLayout) cordovaWebView.getView().getParent(); + LinearLayout linearLayout = new LinearLayout(activity); + linearLayout.setLayoutParams(new LinearLayout.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT)); + wrapperFrameLayout.addView(linearLayout, 0); + + FrameLayout mainLayout = LayoutProvider.getMainLayout(this.activity); + exoView = LayoutProvider.getExoPlayerView(this.activity, config); + exoView.setControllerVisibilityListener(playbackControlVisibilityListener); + mainLayout.addView(exoView); + + linearLayout.addView(mainLayout); + exoView.requestFocus(); + exoView.setOnTouchListener(onTouchListener); + + LayoutProvider.setupController(exoView, activity, config.getController()); + } + public void createDialog() { dialog = new Dialog(this.activity, android.R.style.Theme_Black_NoTitleBar_Fullscreen); dialog.setOnKeyListener(onKeyListener); @@ -432,5 +458,5 @@ private void sendError(String msg) { Log.e(TAG, msg); JSONObject payload = Payload.playerErrorEvent(Player.this.exoPlayer, null, msg); new CallbackResponse(Player.this.callbackContext).send(PluginResult.Status.ERROR, payload, true); - } + } } diff --git a/src/android/Plugin.java b/src/android/Plugin.java index e4b06a2..30944bc 100644 --- a/src/android/Plugin.java +++ b/src/android/Plugin.java @@ -23,13 +23,16 @@ of this software and associated documentation files (the "Software"), to deal */ package co.frontyard.cordova.plugin.exoplayer; +import android.graphics.Color; import android.net.*; +import android.view.View; import android.view.ViewGroup; import org.apache.cordova.*; import org.json.*; public class Plugin extends CordovaPlugin { private Player player; + private boolean webViewVisibilityToggle = true; @Override public boolean execute(final String action, final JSONArray data, final CallbackContext callbackContext) throws JSONException { @@ -43,7 +46,19 @@ public void run() { } JSONObject params = data.optJSONObject(0); self.player = new Player(new Configuration(params), cordova.getActivity(), callbackContext, webView); - self.player.createPlayer(); + self.player.createPlayer(webView); + new CallbackResponse(callbackContext).send(PluginResult.Status.NO_RESULT, true); + } + }); + return true; + } + else if (action.equals("toggleWebViewVisibility")) { + cordova.getActivity().runOnUiThread(new Runnable() { + public void run() { + JSONObject params = data.optJSONObject(0); + Configuration conf = new Configuration(params); + webView.getView().setVisibility( webViewVisibilityToggle ? View.GONE : View.VISIBLE); + webViewVisibilityToggle = !webViewVisibilityToggle; new CallbackResponse(callbackContext).send(PluginResult.Status.NO_RESULT, true); } }); diff --git a/www/exoplayer.js b/www/exoplayer.js index 909db66..cf5895e 100644 --- a/www/exoplayer.js +++ b/www/exoplayer.js @@ -26,6 +26,9 @@ module.exports = { show: function (parameters, successCallback, errorCallback) { cordova.exec(successCallback, errorCallback, "ExoPlayer", "show", [parameters]); }, + toggleWebViewVisibility: function (parameters, successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, "ExoPlayer", "toggleWebViewVisibility", [parameters]); + }, setStream: function (url, controller, successCallback, errorCallback) { cordova.exec(successCallback, errorCallback, "ExoPlayer", "setStream", [url, controller]); },