Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</js-module>

<platform name="android">
<framework src="com.google.android.exoplayer:exoplayer:2.6.1"/>
<framework src="com.google.android.exoplayer:exoplayer:2.7.2"/>
<framework src="com.squareup.picasso:picasso:2.5.2"/>

<config-file target="res/xml/config.xml" parent="/*">
Expand Down
4 changes: 4 additions & 0 deletions src/android/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
36 changes: 31 additions & 5 deletions src/android/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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() {
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
}
17 changes: 16 additions & 1 deletion src/android/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
});
Expand Down
3 changes: 3 additions & 0 deletions www/exoplayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
},
Expand Down