My application created with Android Studio shows black screen when playing videos from Facebook and YouTube
I am developing an application in Android Studio which allows opening Facebook and YouTube accounts, everything works fine, but when trying to play a video a black screen appears and only the audio is heard.
What can I do? I've tried everything but nothing works.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
my_context = container.getContext();
rootView = inflater.inflate(R.layout.fragment_web, container, false);
preferences = PreferenceManager.getDefaultSharedPreferences(my_context);
String type = getArguments().getString("type");
String url = getArguments().getString("url");
webView = (WebView) rootView.findViewById(R.id.webView);
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
--------------- SWIPE CONTAINER ---------------
swipeContainer = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeContainer);
// Setup refresh listener which triggers new data loading
swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
webView.reload();
}
});
// Configure the refreshing colors
swipeContainer.setColorSchemeResources(android.R.color.holo_blue_bright,
android.R.color.holo_green_light,
android.R.color.holo_orange_light,
android.R.color.holo_red_light);
------------------ WEBVIEW SETTINGS --------------------
WebSettings webSettings = webView.getSettings();
// GET PREFERENCES
if (preferences.getBoolean("pref_webview_cache", true)) {
enableHTML5AppCache();
}
if (preferences.getBoolean("pref_webview_javascript", true)) {
webSettings.setJavaScriptEnabled(true);
webView.addJavascriptInterface(new WebAppInterface(my_context), "WebAppInterface"
-------------------- LOADER ------------------------
pd = new ProgressDialog(my_context);
pd.setMessage("Please wait Loading...");
loader = preferences.getString("pref_webview_loader_list", "dialog");
if (loader.equals("pull")) {
swipeContainer.setRefreshing(true);
} else if (loader.equals("dialog")) {
pd.show();
} else if (loader.equals("never")) {
Log.d("WebView", "No Loader selected");
}
webView.setWebViewClient(new MyWebViewClient());
webView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setSupportZoom(true);
// ---------------- LOADING CONTENT -----------------
if (type.equals("file")) {
webView.loadUrl("file:///android_asset/" + url);
} else if (type.equals("url")) {
webView.loadUrl(url);
}
return rootView;
}
public Boolean canGoBack() {
return webView.canGoBack();
}
public void GoBack() {
webView.goBack();
}
private void enableHTML5AppCache() {
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setAppCachePath("/data/data/" + getActivity().getPackageName() + "/cache");
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND);
webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
if (Build.VERSION.SDK_INT >= 21) {
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
}
if (android.os.Build.VERSION.SDK_INT < 16) {
webView.setBackgroundColor(0x00000000);
} else {
webView.setBackgroundColor(Color.argb(1, 0, 0, 0));
}
webView.setWebViewClient(new WebViewClient() {
/* @Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
view.loadUrl(request.getUrl().toString());
}
return super.shouldOverrideUrlLoading(view, String.valueOf(request));
} */
@Override
public void onPageStarted(WebView webview, String url, Bitmap favicon) {
super.onPageStarted(webview, url, favicon);
webview.setVisibility(View.INVISIBLE);
}
@Override
public void onPageFinished(WebView webview, String url) {
webview.setVisibility(View.VISIBLE);
super.onPageFinished(webview, url);
}
});
webView.setWebChromeClient(new WebChromeClient());
webView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; T-Mobile myTouch Q Build/HuaweiU8730) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1");
// webView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; Android 4.4.2; DASH 5.0+ Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.93 Mobile Safari/537.36");
}
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
if (loader.equals("pull")) {
swipeContainer.setRefreshing(true);
} else if (loader.equals("dialog")) {
if (!pd.isShowing()) {
pd.show();
}
} else if (loader.equals("never")) {
Log.d("WebView", "No Loader selected");
}
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
if (pd.isShowing()) {
pd.dismiss();
}
if (swipeContainer.isRefreshing()) {
swipeContainer.setRefreshing(false);
}
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
webView.loadUrl("file:///android_asset/" + getString(R.string.error_page));
}
}
public class WebAppInterface {
Context mContext;
/**
* Instantiate the interface and set the context
*/
WebAppInterface(Context c) {
mContext = c;
}
// -------------------------------- SHOW TOAST ---------------------------------------
@JavascriptInterface
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
// -------------------------------- START VIBRATE MP3 ---------------------------------------
@JavascriptInterface
public void vibrate(int milliseconds) {
Vibrator v = (Vibrator) my_context.getSystemService(Context.VIBRATOR_SERVICE);
// Vibrate for 500 milliseconds
v.vibrate(milliseconds);
}
// -------------------------------- START PLAY MP3 ---------------------------------------
@JavascriptInterface
public void playSound() {
// mp = MediaPlayer.create(my_context, R.raw.demo);
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
mp.release();
}
});
mp.start();
}
// -------------------------------- STOP PLAY MP3 ---------------------------------------
@JavascriptInterface
public void stopSound() {
if (mp.isPlaying()) {
mp.stop();
}
}
// -------------------------------- CREATE NOTIFICATION ---------------------------------------
@JavascriptInterface
public void newNotification(String title, String message) {
mNotificationManager = (NotificationManager) my_context.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(my_context, 0, new Intent(my_context, MainActivity.class), 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(my_context)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(message))
.setContentText(message);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(1, mBuilder.build());
}
// -------------------------------- GET DATA ACCOUNT FROM DEVICE ---------------------------------------
@JavascriptInterface
public void snakBar(String message) {
Snackbar.make(rootView, message, Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
}
}
android facebook android-studio video
add a comment |
I am developing an application in Android Studio which allows opening Facebook and YouTube accounts, everything works fine, but when trying to play a video a black screen appears and only the audio is heard.
What can I do? I've tried everything but nothing works.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
my_context = container.getContext();
rootView = inflater.inflate(R.layout.fragment_web, container, false);
preferences = PreferenceManager.getDefaultSharedPreferences(my_context);
String type = getArguments().getString("type");
String url = getArguments().getString("url");
webView = (WebView) rootView.findViewById(R.id.webView);
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
--------------- SWIPE CONTAINER ---------------
swipeContainer = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeContainer);
// Setup refresh listener which triggers new data loading
swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
webView.reload();
}
});
// Configure the refreshing colors
swipeContainer.setColorSchemeResources(android.R.color.holo_blue_bright,
android.R.color.holo_green_light,
android.R.color.holo_orange_light,
android.R.color.holo_red_light);
------------------ WEBVIEW SETTINGS --------------------
WebSettings webSettings = webView.getSettings();
// GET PREFERENCES
if (preferences.getBoolean("pref_webview_cache", true)) {
enableHTML5AppCache();
}
if (preferences.getBoolean("pref_webview_javascript", true)) {
webSettings.setJavaScriptEnabled(true);
webView.addJavascriptInterface(new WebAppInterface(my_context), "WebAppInterface"
-------------------- LOADER ------------------------
pd = new ProgressDialog(my_context);
pd.setMessage("Please wait Loading...");
loader = preferences.getString("pref_webview_loader_list", "dialog");
if (loader.equals("pull")) {
swipeContainer.setRefreshing(true);
} else if (loader.equals("dialog")) {
pd.show();
} else if (loader.equals("never")) {
Log.d("WebView", "No Loader selected");
}
webView.setWebViewClient(new MyWebViewClient());
webView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setSupportZoom(true);
// ---------------- LOADING CONTENT -----------------
if (type.equals("file")) {
webView.loadUrl("file:///android_asset/" + url);
} else if (type.equals("url")) {
webView.loadUrl(url);
}
return rootView;
}
public Boolean canGoBack() {
return webView.canGoBack();
}
public void GoBack() {
webView.goBack();
}
private void enableHTML5AppCache() {
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setAppCachePath("/data/data/" + getActivity().getPackageName() + "/cache");
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND);
webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
if (Build.VERSION.SDK_INT >= 21) {
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
}
if (android.os.Build.VERSION.SDK_INT < 16) {
webView.setBackgroundColor(0x00000000);
} else {
webView.setBackgroundColor(Color.argb(1, 0, 0, 0));
}
webView.setWebViewClient(new WebViewClient() {
/* @Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
view.loadUrl(request.getUrl().toString());
}
return super.shouldOverrideUrlLoading(view, String.valueOf(request));
} */
@Override
public void onPageStarted(WebView webview, String url, Bitmap favicon) {
super.onPageStarted(webview, url, favicon);
webview.setVisibility(View.INVISIBLE);
}
@Override
public void onPageFinished(WebView webview, String url) {
webview.setVisibility(View.VISIBLE);
super.onPageFinished(webview, url);
}
});
webView.setWebChromeClient(new WebChromeClient());
webView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; T-Mobile myTouch Q Build/HuaweiU8730) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1");
// webView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; Android 4.4.2; DASH 5.0+ Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.93 Mobile Safari/537.36");
}
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
if (loader.equals("pull")) {
swipeContainer.setRefreshing(true);
} else if (loader.equals("dialog")) {
if (!pd.isShowing()) {
pd.show();
}
} else if (loader.equals("never")) {
Log.d("WebView", "No Loader selected");
}
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
if (pd.isShowing()) {
pd.dismiss();
}
if (swipeContainer.isRefreshing()) {
swipeContainer.setRefreshing(false);
}
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
webView.loadUrl("file:///android_asset/" + getString(R.string.error_page));
}
}
public class WebAppInterface {
Context mContext;
/**
* Instantiate the interface and set the context
*/
WebAppInterface(Context c) {
mContext = c;
}
// -------------------------------- SHOW TOAST ---------------------------------------
@JavascriptInterface
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
// -------------------------------- START VIBRATE MP3 ---------------------------------------
@JavascriptInterface
public void vibrate(int milliseconds) {
Vibrator v = (Vibrator) my_context.getSystemService(Context.VIBRATOR_SERVICE);
// Vibrate for 500 milliseconds
v.vibrate(milliseconds);
}
// -------------------------------- START PLAY MP3 ---------------------------------------
@JavascriptInterface
public void playSound() {
// mp = MediaPlayer.create(my_context, R.raw.demo);
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
mp.release();
}
});
mp.start();
}
// -------------------------------- STOP PLAY MP3 ---------------------------------------
@JavascriptInterface
public void stopSound() {
if (mp.isPlaying()) {
mp.stop();
}
}
// -------------------------------- CREATE NOTIFICATION ---------------------------------------
@JavascriptInterface
public void newNotification(String title, String message) {
mNotificationManager = (NotificationManager) my_context.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(my_context, 0, new Intent(my_context, MainActivity.class), 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(my_context)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(message))
.setContentText(message);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(1, mBuilder.build());
}
// -------------------------------- GET DATA ACCOUNT FROM DEVICE ---------------------------------------
@JavascriptInterface
public void snakBar(String message) {
Snackbar.make(rootView, message, Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
}
}
android facebook android-studio video
add a comment |
I am developing an application in Android Studio which allows opening Facebook and YouTube accounts, everything works fine, but when trying to play a video a black screen appears and only the audio is heard.
What can I do? I've tried everything but nothing works.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
my_context = container.getContext();
rootView = inflater.inflate(R.layout.fragment_web, container, false);
preferences = PreferenceManager.getDefaultSharedPreferences(my_context);
String type = getArguments().getString("type");
String url = getArguments().getString("url");
webView = (WebView) rootView.findViewById(R.id.webView);
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
--------------- SWIPE CONTAINER ---------------
swipeContainer = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeContainer);
// Setup refresh listener which triggers new data loading
swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
webView.reload();
}
});
// Configure the refreshing colors
swipeContainer.setColorSchemeResources(android.R.color.holo_blue_bright,
android.R.color.holo_green_light,
android.R.color.holo_orange_light,
android.R.color.holo_red_light);
------------------ WEBVIEW SETTINGS --------------------
WebSettings webSettings = webView.getSettings();
// GET PREFERENCES
if (preferences.getBoolean("pref_webview_cache", true)) {
enableHTML5AppCache();
}
if (preferences.getBoolean("pref_webview_javascript", true)) {
webSettings.setJavaScriptEnabled(true);
webView.addJavascriptInterface(new WebAppInterface(my_context), "WebAppInterface"
-------------------- LOADER ------------------------
pd = new ProgressDialog(my_context);
pd.setMessage("Please wait Loading...");
loader = preferences.getString("pref_webview_loader_list", "dialog");
if (loader.equals("pull")) {
swipeContainer.setRefreshing(true);
} else if (loader.equals("dialog")) {
pd.show();
} else if (loader.equals("never")) {
Log.d("WebView", "No Loader selected");
}
webView.setWebViewClient(new MyWebViewClient());
webView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setSupportZoom(true);
// ---------------- LOADING CONTENT -----------------
if (type.equals("file")) {
webView.loadUrl("file:///android_asset/" + url);
} else if (type.equals("url")) {
webView.loadUrl(url);
}
return rootView;
}
public Boolean canGoBack() {
return webView.canGoBack();
}
public void GoBack() {
webView.goBack();
}
private void enableHTML5AppCache() {
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setAppCachePath("/data/data/" + getActivity().getPackageName() + "/cache");
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND);
webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
if (Build.VERSION.SDK_INT >= 21) {
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
}
if (android.os.Build.VERSION.SDK_INT < 16) {
webView.setBackgroundColor(0x00000000);
} else {
webView.setBackgroundColor(Color.argb(1, 0, 0, 0));
}
webView.setWebViewClient(new WebViewClient() {
/* @Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
view.loadUrl(request.getUrl().toString());
}
return super.shouldOverrideUrlLoading(view, String.valueOf(request));
} */
@Override
public void onPageStarted(WebView webview, String url, Bitmap favicon) {
super.onPageStarted(webview, url, favicon);
webview.setVisibility(View.INVISIBLE);
}
@Override
public void onPageFinished(WebView webview, String url) {
webview.setVisibility(View.VISIBLE);
super.onPageFinished(webview, url);
}
});
webView.setWebChromeClient(new WebChromeClient());
webView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; T-Mobile myTouch Q Build/HuaweiU8730) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1");
// webView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; Android 4.4.2; DASH 5.0+ Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.93 Mobile Safari/537.36");
}
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
if (loader.equals("pull")) {
swipeContainer.setRefreshing(true);
} else if (loader.equals("dialog")) {
if (!pd.isShowing()) {
pd.show();
}
} else if (loader.equals("never")) {
Log.d("WebView", "No Loader selected");
}
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
if (pd.isShowing()) {
pd.dismiss();
}
if (swipeContainer.isRefreshing()) {
swipeContainer.setRefreshing(false);
}
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
webView.loadUrl("file:///android_asset/" + getString(R.string.error_page));
}
}
public class WebAppInterface {
Context mContext;
/**
* Instantiate the interface and set the context
*/
WebAppInterface(Context c) {
mContext = c;
}
// -------------------------------- SHOW TOAST ---------------------------------------
@JavascriptInterface
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
// -------------------------------- START VIBRATE MP3 ---------------------------------------
@JavascriptInterface
public void vibrate(int milliseconds) {
Vibrator v = (Vibrator) my_context.getSystemService(Context.VIBRATOR_SERVICE);
// Vibrate for 500 milliseconds
v.vibrate(milliseconds);
}
// -------------------------------- START PLAY MP3 ---------------------------------------
@JavascriptInterface
public void playSound() {
// mp = MediaPlayer.create(my_context, R.raw.demo);
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
mp.release();
}
});
mp.start();
}
// -------------------------------- STOP PLAY MP3 ---------------------------------------
@JavascriptInterface
public void stopSound() {
if (mp.isPlaying()) {
mp.stop();
}
}
// -------------------------------- CREATE NOTIFICATION ---------------------------------------
@JavascriptInterface
public void newNotification(String title, String message) {
mNotificationManager = (NotificationManager) my_context.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(my_context, 0, new Intent(my_context, MainActivity.class), 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(my_context)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(message))
.setContentText(message);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(1, mBuilder.build());
}
// -------------------------------- GET DATA ACCOUNT FROM DEVICE ---------------------------------------
@JavascriptInterface
public void snakBar(String message) {
Snackbar.make(rootView, message, Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
}
}
android facebook android-studio video
I am developing an application in Android Studio which allows opening Facebook and YouTube accounts, everything works fine, but when trying to play a video a black screen appears and only the audio is heard.
What can I do? I've tried everything but nothing works.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
my_context = container.getContext();
rootView = inflater.inflate(R.layout.fragment_web, container, false);
preferences = PreferenceManager.getDefaultSharedPreferences(my_context);
String type = getArguments().getString("type");
String url = getArguments().getString("url");
webView = (WebView) rootView.findViewById(R.id.webView);
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
--------------- SWIPE CONTAINER ---------------
swipeContainer = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeContainer);
// Setup refresh listener which triggers new data loading
swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
webView.reload();
}
});
// Configure the refreshing colors
swipeContainer.setColorSchemeResources(android.R.color.holo_blue_bright,
android.R.color.holo_green_light,
android.R.color.holo_orange_light,
android.R.color.holo_red_light);
------------------ WEBVIEW SETTINGS --------------------
WebSettings webSettings = webView.getSettings();
// GET PREFERENCES
if (preferences.getBoolean("pref_webview_cache", true)) {
enableHTML5AppCache();
}
if (preferences.getBoolean("pref_webview_javascript", true)) {
webSettings.setJavaScriptEnabled(true);
webView.addJavascriptInterface(new WebAppInterface(my_context), "WebAppInterface"
-------------------- LOADER ------------------------
pd = new ProgressDialog(my_context);
pd.setMessage("Please wait Loading...");
loader = preferences.getString("pref_webview_loader_list", "dialog");
if (loader.equals("pull")) {
swipeContainer.setRefreshing(true);
} else if (loader.equals("dialog")) {
pd.show();
} else if (loader.equals("never")) {
Log.d("WebView", "No Loader selected");
}
webView.setWebViewClient(new MyWebViewClient());
webView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setSupportZoom(true);
// ---------------- LOADING CONTENT -----------------
if (type.equals("file")) {
webView.loadUrl("file:///android_asset/" + url);
} else if (type.equals("url")) {
webView.loadUrl(url);
}
return rootView;
}
public Boolean canGoBack() {
return webView.canGoBack();
}
public void GoBack() {
webView.goBack();
}
private void enableHTML5AppCache() {
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setAppCachePath("/data/data/" + getActivity().getPackageName() + "/cache");
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND);
webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
if (Build.VERSION.SDK_INT >= 21) {
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
}
if (android.os.Build.VERSION.SDK_INT < 16) {
webView.setBackgroundColor(0x00000000);
} else {
webView.setBackgroundColor(Color.argb(1, 0, 0, 0));
}
webView.setWebViewClient(new WebViewClient() {
/* @Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
view.loadUrl(request.getUrl().toString());
}
return super.shouldOverrideUrlLoading(view, String.valueOf(request));
} */
@Override
public void onPageStarted(WebView webview, String url, Bitmap favicon) {
super.onPageStarted(webview, url, favicon);
webview.setVisibility(View.INVISIBLE);
}
@Override
public void onPageFinished(WebView webview, String url) {
webview.setVisibility(View.VISIBLE);
super.onPageFinished(webview, url);
}
});
webView.setWebChromeClient(new WebChromeClient());
webView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; T-Mobile myTouch Q Build/HuaweiU8730) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1");
// webView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; Android 4.4.2; DASH 5.0+ Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.93 Mobile Safari/537.36");
}
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
if (loader.equals("pull")) {
swipeContainer.setRefreshing(true);
} else if (loader.equals("dialog")) {
if (!pd.isShowing()) {
pd.show();
}
} else if (loader.equals("never")) {
Log.d("WebView", "No Loader selected");
}
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
if (pd.isShowing()) {
pd.dismiss();
}
if (swipeContainer.isRefreshing()) {
swipeContainer.setRefreshing(false);
}
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
webView.loadUrl("file:///android_asset/" + getString(R.string.error_page));
}
}
public class WebAppInterface {
Context mContext;
/**
* Instantiate the interface and set the context
*/
WebAppInterface(Context c) {
mContext = c;
}
// -------------------------------- SHOW TOAST ---------------------------------------
@JavascriptInterface
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
// -------------------------------- START VIBRATE MP3 ---------------------------------------
@JavascriptInterface
public void vibrate(int milliseconds) {
Vibrator v = (Vibrator) my_context.getSystemService(Context.VIBRATOR_SERVICE);
// Vibrate for 500 milliseconds
v.vibrate(milliseconds);
}
// -------------------------------- START PLAY MP3 ---------------------------------------
@JavascriptInterface
public void playSound() {
// mp = MediaPlayer.create(my_context, R.raw.demo);
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
mp.release();
}
});
mp.start();
}
// -------------------------------- STOP PLAY MP3 ---------------------------------------
@JavascriptInterface
public void stopSound() {
if (mp.isPlaying()) {
mp.stop();
}
}
// -------------------------------- CREATE NOTIFICATION ---------------------------------------
@JavascriptInterface
public void newNotification(String title, String message) {
mNotificationManager = (NotificationManager) my_context.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(my_context, 0, new Intent(my_context, MainActivity.class), 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(my_context)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(message))
.setContentText(message);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(1, mBuilder.build());
}
// -------------------------------- GET DATA ACCOUNT FROM DEVICE ---------------------------------------
@JavascriptInterface
public void snakBar(String message) {
Snackbar.make(rootView, message, Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
}
}
android facebook android-studio video
android facebook android-studio video
asked Nov 22 at 18:35
Leo
61
61
add a comment |
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436542%2fmy-application-created-with-android-studio-shows-black-screen-when-playing-video%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436542%2fmy-application-created-with-android-studio-shows-black-screen-when-playing-video%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown