cordova-plugin-media3 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,132 @@
1
+ /*
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) 2017 Nedim Cholich
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+ */
24
+ package co.frontyard.cordova.plugin.exoplayer;
25
+
26
+ import android.app.UiModeManager;
27
+ import android.content.Context;
28
+ import android.content.pm.PackageManager;
29
+ import android.content.res.Configuration;
30
+ import android.os.Build;
31
+ import android.util.Log;
32
+
33
+ import java.lang.*;
34
+ import java.util.*;
35
+ import org.apache.cordova.*;
36
+ import org.json.*;
37
+
38
+ public class DeviceDetector {
39
+
40
+ private static final String TAG = "DeviceDetector";
41
+ // private final CallbackContext callbackContext;
42
+
43
+ public static JSONObject isTV(Context context) {
44
+ JSONObject response = new JSONObject();
45
+
46
+ try {
47
+ // Check UI mode (most reliable)
48
+ UiModeManager uiModeManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);
49
+ boolean isTV = uiModeManager != null && uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
50
+
51
+ // Check Leanback feature (TV UI)
52
+ PackageManager pm = context.getPackageManager();
53
+ boolean isLeanback = pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK);
54
+ // boolean isTelevision = pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION);
55
+ boolean isTelevision = pm.hasSystemFeature("android.hardware.type.television");
56
+
57
+ // Check if device has HDMIndroid_tv
58
+ boolean isAndroidTv = pm.hasSystemFeature("com.google.android.tv");
59
+
60
+ // Build properties
61
+ String manufacturer = Build.MANUFACTURER.toLowerCase();
62
+ String model = Build.MODEL.toLowerCase();
63
+ String device = Build.DEVICE.toLowerCase();
64
+ String product = Build.PRODUCT.toLowerCase();
65
+
66
+ // Fire TV detection
67
+ // boolean isFireTV = manufacturer.contains("amazon") ||
68
+ // model.contains("aft") ||
69
+ // device.contains("aft") ||
70
+ // product.contains("aft");
71
+ boolean isFireTV = pm.hasSystemFeature("amazon.hardware.fire_tv");
72
+
73
+ // Generic Android Boxes
74
+ boolean isBox = manufacturer.contains("amlogic") ||
75
+ manufacturer.contains("rockchip") ||
76
+ manufacturer.contains("allwinner") ||
77
+ model.contains("tvbox") ||
78
+ model.contains("android tv") ||
79
+ model.contains("google tv");
80
+
81
+ // Mobile / Tablet distinction
82
+ boolean isTablet = (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
83
+ if (!isTablet) {
84
+ isTablet = (context.getResources().getConfiguration().smallestScreenWidthDp >= 600);
85
+ }
86
+ // if (!isTablet) {
87
+ // isTablet = context.getResources().getBoolean(R.bool.isTablet); NO WORKING CODE
88
+ // }
89
+
90
+ boolean isShield = manufacturer.contains("nvidia") || model.contains("shield");
91
+
92
+ boolean isXiaomi = manufacturer.contains("xiaomi");
93
+
94
+ // boolean isOnePlus = manufacturer.contains("oneplus");
95
+
96
+ response.put("isTV", isTV ? "true" : "false");
97
+ response.put("isTelevision", isTelevision ? "true" : "false");
98
+ response.put("isLeanback", isLeanback ? "true" : "false");
99
+ response.put("isAndroidTv", isAndroidTv ? "true" : "false");
100
+ response.put("isBox", isBox ? "true" : "false");
101
+ response.put("isFireTV", isFireTV ? "true" : "false");
102
+ response.put("isTablet", isTablet ? "true" : "false");
103
+ response.put("isShield", isShield ? "true" : "false");
104
+ response.put("isXiaomi", isXiaomi ? "true" : "false");
105
+ // response.put("isOnePlus", isOnePlus ? "true" : "false");
106
+ // response.put("isSamsung", isSamsung ? "true" : "false");
107
+ response.put("success", true);
108
+
109
+ try {
110
+ String hdmi_device_type = "-1";
111
+ Class<?> systemProperties = Class.forName("android.os.SystemProperties");
112
+ hdmi_device_type = (String) systemProperties.getMethod("get", String.class, String.class)
113
+ .invoke(null, "ro.hdmi.device_type", "-1");
114
+
115
+ response.put("hdmi_device_type", hdmi_device_type);
116
+
117
+ } catch (Exception e) {
118
+ // e.printStackTrace();
119
+ }
120
+
121
+ } catch (JSONException e) {
122
+ try {
123
+ response.put("success", false);
124
+ response.put("error", "Failed to get PackageManager : " + e.getMessage());
125
+ } catch (JSONException je) {
126
+ Log.e(TAG, "Error creating response JSON", je);
127
+ }
128
+ }
129
+
130
+ return response;
131
+ }
132
+ }
@@ -0,0 +1,218 @@
1
+ /*
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) 2017 Nedim Cholich
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+ */
24
+ package co.frontyard.cordova.plugin.exoplayer;
25
+
26
+ import android.app.*;
27
+ import android.graphics.*;
28
+ import android.util.*;
29
+ import android.view.*;
30
+ import android.widget.*;
31
+
32
+ import com.google.android.exoplayer2.ForwardingPlayer;
33
+ import com.google.android.exoplayer2.ui.*;
34
+ import java.lang.String;
35
+
36
+ import org.json.*;
37
+ import com.squareup.picasso.*;
38
+
39
+ import android.util.Log;
40
+
41
+ public class LayoutProvider {
42
+ public static final String TAG = "LayoutProvider";
43
+
44
+ private enum BUTTON { exo_prev, exo_rew, exo_play, exo_pause, exo_ffwd, exo_next }
45
+
46
+ public static FrameLayout getMainLayout(Activity activity) {
47
+ FrameLayout view = new FrameLayout(activity);
48
+ view.setLayoutParams(new LinearLayout.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT));
49
+ view.setKeepScreenOn(true);
50
+
51
+ return view;
52
+ }
53
+
54
+ public static StyledPlayerView getExoPlayerView(Activity activity, Configuration config) {
55
+ StyledPlayerView view = new StyledPlayerView(activity);
56
+ view.setLayoutParams(new LinearLayout.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT));
57
+ if (config.isAspectRatioFillScreen()) {
58
+ view.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL);
59
+ }
60
+
61
+ view.setShowMultiWindowTimeBar(true);
62
+ view.setControllerHideOnTouch(true);
63
+ view.setControllerShowTimeoutMs(config.getHideTimeout());
64
+
65
+ setupController(view, activity, config.getController());
66
+
67
+ return view;
68
+ }
69
+
70
+ public static void setupController(StyledPlayerView parentView, Activity activity, JSONObject controller) {
71
+ if (null != controller) {
72
+ parentView.setUseController(true);
73
+ setupButtons(parentView, activity, controller);
74
+ setupBar(parentView, activity, controller);
75
+ setupBuffering(parentView, activity, controller);
76
+ }
77
+ else {
78
+ parentView.setUseController(false);
79
+ }
80
+ }
81
+
82
+ private static void setupButtons(StyledPlayerView parentView, Activity activity, JSONObject controller) {
83
+ String packageName = activity.getPackageName();
84
+ String buttonsColor = controller.optString("buttonsColor");
85
+
86
+ JSONObject buttonsConfig = controller.optJSONObject("controlIcons");
87
+ if (null != buttonsConfig) {
88
+ for (BUTTON b : BUTTON.values()) {
89
+ String buttonName = b.name();
90
+ ImageButton imageButton = (ImageButton) findView(parentView, activity, buttonName);
91
+ if (null != imageButton) {
92
+ if (buttonsConfig.has(buttonName)) {
93
+ imageButton.setColorFilter(Color.parseColor("#00000000"));
94
+ String buttonUrl = buttonsConfig.optString(buttonName);
95
+ if (null == buttonUrl || buttonUrl.equals("null")) { // Again, why is this a String "null"?
96
+ // Image is set to null, remove it from view.
97
+ imageButton.setVisibility(View.GONE);
98
+ ((ViewGroup) imageButton.getParent()).removeView(imageButton);
99
+ }
100
+ else {
101
+ // Loading from external source.
102
+ Picasso.with(imageButton.getContext()).load(buttonUrl).into(imageButton);
103
+ }
104
+ }
105
+ else if (null != buttonsColor) {
106
+ // Using default and tinting.
107
+ imageButton.setColorFilter(Color.parseColor(buttonsColor));
108
+ }
109
+ }
110
+ }
111
+ }
112
+ else {
113
+ LinearLayout exoButtons = (LinearLayout) findView(parentView, activity, "exo_buttons");
114
+ exoButtons.setVisibility(View.GONE);
115
+ }
116
+ }
117
+
118
+ private static void setupBar(StyledPlayerView parentView, Activity activity, JSONObject controller) {
119
+ String streamTitle = controller.optString("streamTitle", null);
120
+ String streamDescription = controller.optString("streamDescription", null);
121
+ String streamImage = controller.optString("streamImage", null);
122
+ String textColor = controller.optString("textColor");
123
+
124
+ ImageView imageView = (ImageView) findView(parentView, activity, "exo_image");
125
+ TextView titleView = (TextView) findView(parentView, activity, "exo_title");
126
+ TextView subtitleView = (TextView) findView(parentView, activity, "exo_subtitle");
127
+ View timebarView = findView(parentView, activity, "exo_timebar");
128
+ TextView positionView = (TextView) findView(timebarView, activity, "exo_position");
129
+ TextView durationView = (TextView) findView(timebarView, activity, "exo_duration");
130
+
131
+ if (null != textColor) {
132
+ int intTextColor = Color.parseColor(textColor);
133
+ if (null != titleView) {
134
+ titleView.setTextColor(intTextColor);
135
+ }
136
+ if (null != subtitleView) {
137
+ subtitleView.setTextColor(intTextColor);
138
+ }
139
+ if (null != positionView) {
140
+ positionView.setTextColor(intTextColor);
141
+ }
142
+ if (null != durationView) {
143
+ durationView.setTextColor(intTextColor);
144
+ }
145
+ }
146
+ if(null != streamImage) {
147
+ Picasso.with(imageView.getContext()).load(streamImage).into(imageView);
148
+ }
149
+ if(null != streamTitle) {
150
+ titleView.setText(streamTitle);
151
+ }
152
+ if (null != streamDescription && !streamDescription.equals("null")) { // TODO: Why are we getting string "null" here?
153
+ subtitleView.setText(streamDescription);
154
+ }
155
+ else {
156
+ subtitleView.setVisibility(View.GONE);
157
+ }
158
+ if (controller.optBoolean("hideProgress")) {
159
+ timebarView.setVisibility(View.GONE);
160
+ }
161
+ else {
162
+ if (controller.optBoolean("hidePosition") && null != positionView) {
163
+ positionView.setVisibility(View.GONE);
164
+ ((ViewGroup) positionView.getParent()).removeView(positionView);
165
+ }
166
+ if (controller.optBoolean("hideDuration") && null != durationView) {
167
+ durationView.setVisibility(View.GONE);
168
+ ((ViewGroup) durationView.getParent()).removeView(durationView);
169
+ }
170
+ }
171
+ }
172
+
173
+ private static void setupBuffering(StyledPlayerView parentView, Activity activity, JSONObject controller) {
174
+ String bufferingColor = controller.optString("bufferingColor");
175
+ ProgressBar bufferingBar = (ProgressBar)findView(parentView, activity, "exo_buffering");
176
+ if (null != bufferingBar && null != bufferingColor) {
177
+ bufferingBar.getIndeterminateDrawable().setColorFilter(Color.parseColor(bufferingColor), android.graphics.PorterDuff.Mode.MULTIPLY);
178
+ }
179
+ }
180
+
181
+ public static void setBufferingVisibility(StyledPlayerView parentView, Activity activity, boolean visible) {
182
+ ProgressBar progressBar = (ProgressBar)findView(parentView, activity, "exo_buffering");
183
+ if (null != progressBar) {
184
+ progressBar.setVisibility(visible ? View.VISIBLE : View.GONE);
185
+ }
186
+ }
187
+
188
+ private static View findView(View view, Activity activity, String name) {
189
+ int viewId = activity.getResources().getIdentifier(name, "id", activity.getPackageName());
190
+ return view.findViewById(viewId);
191
+ }
192
+
193
+ public static WindowManager.LayoutParams getDialogLayoutParams(Activity activity, Configuration config, Dialog dialog) {
194
+ WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
195
+ lp.copyFrom(dialog.getWindow().getAttributes());
196
+
197
+ JSONObject dim = config.getDimensions();
198
+ if(null == dim) {
199
+ lp.width = WindowManager.LayoutParams.MATCH_PARENT;
200
+ lp.height = WindowManager.LayoutParams.MATCH_PARENT;
201
+ }
202
+ else {
203
+ DisplayMetrics metrics = activity.getResources().getDisplayMetrics();
204
+ lp.x = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dim.optInt("x", 0), metrics);
205
+ lp.y = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dim.optInt("y", 0), metrics);
206
+ lp.width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dim.optInt("width", WindowManager.LayoutParams.MATCH_PARENT), metrics);
207
+ lp.height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dim.optInt("height", WindowManager.LayoutParams.MATCH_PARENT), metrics);
208
+ }
209
+
210
+ return lp;
211
+ }
212
+
213
+ public static LinearLayout getBackgroundLinearLayout(Activity activity) {
214
+ LinearLayout linearLayout = new LinearLayout(activity);
215
+ linearLayout.setLayoutParams(new LinearLayout.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT));
216
+ return linearLayout;
217
+ }
218
+ }