How to destroy all webviews in RecyclerView? - audio

I have 5 audio which i pass in adapter and in onbind i load that url in webview, when i press the back button the audio not stoped, i destry the webview but it work on the last webview item position..
I have list of 5 sound cloud embedded url which i pass in adapter.
meditationFavSCAdapter = new MeditationFavSCAdapter(FavMeditationActivity.this, favMeditationList, this);
recyclerMeditationfav.setAdapter(meditationFavSCAdapter);
if(favMeditationList.size() > 0) {
for(int i=0;i<favMeditationAPI.getData().size();i++) {
favMeditationList.add(favMeditationAPI.getData().get(i));
}
}
meditationFavSCAdapter.notifyDataSetChanged();
In recyclerview item i declare webview(xml item). And in Onbind method i load that url in webview.
videoWebView.getSettings().setJavaScriptEnabled(true);
videoWebView.getSettings().setCacheMode( WebSettings.LOAD_DEFAULT );
videoWebView.getSettings().setLoadWithOverviewMode(true);
videoWebView.getSettings().setUseWideViewPort(false);
videoWebView.getSettings().setUserAgentString("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36");
//Load Url
videoWebView.loadData(favMeditationList.get(position).getEmbedCode(), "text/html" , "utf-8" );
For Destroy Webview
public void destroyWebView() {
if(videoWebView != null) {
videoWebView.loadUrl("");
videoWebView.loadData("", "text/html" , "utf-8" );
videoWebView.clearHistory();
// NOTE: clears RAM cache, if you pass true, it will also clear the disk cache.
// Probably not a great idea to pass true if you have other WebViews still alive.
videoWebView.clearCache(true);
// Loading a blank page is optional, but will ensure that the WebView isn't doing anything when you destroy it.
videoWebView.loadUrl("about:blank");
videoWebView.onPause();
videoWebView.removeAllViews();
videoWebView.destroy();
// Null out the reference so that you don't end up re-using it.
videoWebView = null;
}
}
I call this function when user press Back Button
#Override
public void onBackPressed() {
meditationFavSCAdapter.destroyWebView();
super.onBackPressed();
}
But this code destroy the last webview in the recycler.
So when i play the first webview audio and press back button the audio still play in background whereas when i play the last audio (webview) it stop when backpressed is called.
So i need to destroy all webview in recyclerview.
But i don't know how...

Related

com.google.android.youtube.player.youtubeplayerview modestbranding is disabled or hide in android

google youtube player using
#Override
public void onInitializationSuccess(Provider arg0, YouTubePlayer player,
boolean restored) {
// TODO Auto-generated method stub
player.setFullscreenControlFlags(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_ORIENTATION);
//This flag tells the player to automatically enter fullscreen when in landscape. Since we don't have
//landscape layout for this activity, this is a good way to allow the user rotate the video player.
player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE);
if(!restored){ //lnIEn0kWdhY
player.cueVideo(getIntent().getStringExtra("VIDEO_ID"));
//player.cueVideo("lnIEn0kWdhY");
//player.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT);
}
else {
Log.e("dd","dff");
}
}
Use the minimal video player style to hide the youtube icon. But it will show only timer bar play/pause controls.
player.setPlayerStyle(YouTubePlayer.PlayerStyle.MINIMAL);

UIWebView doesn't load pages properly

I'm pretty new to Xamarin and iOS and I am putting together a small POC app to learn.
The app uses a view with a UIWebView in it. I intend to load local web files into it and then manipulate those with a mix of JavaScript and C# (JS bridge) but the UIWebView doesn't function properly. It simply doesn't load the pages. If I uninstall the app and then re-install and run it it often load the web page successfully but in subsequent sessions the web page usually doesn't load, leaving the web view as a white empty area. Just to be sure I have tried to load well known web pages, such as xamarin.com or apple.com. Again, the first time I run it the pages load but in subsequent sessions they don't. The behavior is the same on a physical device (an iPhone 5) and on the simulator.
Are there considerations as to how the UIWebView needs to be used? The ViewController hosting it is a sub view of a SlideoutNavigationController.
I have very little experience with UIWebView so any hints are greatly appreciated.
Thanks
EDIT:
The code that loads the web view:
WebView.LoadFinished += (object sender, EventArgs e) =>
{
UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; System.Diagnostics.Debug.WriteLine("Web page was loaded");
};
WebView.LoadError += (object sender, UIWebErrorArgs e) =>
{
UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; System.Diagnostics.Debug.WriteLine(e);
};
WebView.ShouldStartLoad += (UIWebView webView, NSUrlRequest request, UIWebViewNavigationType navigationType) =>
{
return true;
};
WebView.Layer.BorderColor = UIColor.Red.CGColor;
WebView.Layer.BorderWidth = 10;
WebView.LoadRequest(new NSUrlRequest(new NSUrl("http://www.apple.com")));
UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;
WebView.ScalesPageToFit = true;
Note: The ShouldStartLoad event handler is the only one that gets invoked.
This is what the iOS simulator looks like after page (failed to) load:
Figured it out. It turned out loading WebView with (extremely light) HTML content, such as a HTML string, actually required more time than fetching my own objects from a web service. When the data returned by the web service became available WebView still hadn't completed its loading of the web page. So, as my client code got the web service result there was no web page to decorate and the code got in the way of WebViews normal load operation.
This code fixed the sync problem:
private ManualResetEvent _syncLoadWebPage = new ManualResetEvent(false);
private void loadEmptyWebPage()
{
const string EmptyHtml =
"<html><head></head><body style=\"background: aquamarine\"><H1>EMPTY PAGE</H1></body></html>";
WebView.LoadFinished += (sender, e) => webPageReady();
WebView.LoadStarted += (sender, e) => UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;
WebView.LoadHtmlString(EmptyHtml, new NSUrl(AppDelegate.Current.Data.Web.LocalWebRoot, true));
WebView.ScalesPageToFit = true;
}
private void webPageReady()
{
_syncLoadWebPage.Set();
}
void whenWebPageIsReady(Action callback)
{
Task.Factory.StartNew(() =>
{
_syncLoadWebPage.WaitOne();
callback();
});
}
void bindMapFile()
{
whenWebPageIsReady(() =>
{
UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;
var snap = new Snap(new WebViewImpl(WebView));
snap.Image(Model.MapFilePath, "map", 0, 0, Model.MapSize.Width, Model.MapSize.Height);
// todo Decorate stuff with map here ...
});
}
All I had to do was to wait for the web page to finish loading and everything seems to work. I simply drew the wrong conclusions from what I saw.
Silly, really.

Codenameone Webbrowser issue

I am trying to display a webpage from codenameone application. It works fine in Iphone but not in andriod mobile.
public void showLoginForm()
{
final Form loginForm = new Form("Login");
loginForm.setUIID("Form1");
loginForm.setLayout(new BorderLayout());
loginForm.setScrollable(false);
try
{
WebBrowser browser = new WebBrowser()
{
//Overrides onStart and onLoad methods to load progress bars for page transitions.
};
browser.setURL(appsGlobalSettings.get(URL_KEY));
loginForm.addComponent(BorderLayout.CENTER,browser);
loginForm.show();
}
catch(Exception e)
{
e.printStackTrace();
}
}
Check your URL. I suggest removing the override code and placing Google.com hardcoded as a URL and proceeding from there. Since it doesn't work in the simulator either make sure you are using Java 7 with JavaFX enabled, with that case it should show a browser and should work for a proper web address.
Shai...It took some time to collect device logs.
But even that is intriguing.
I tried in two ways
No overridden methods in WebBrowser class and http://www.google.co.in as URL.
public void showLoginForm()
{
InfiniteProgress inf = new InfiniteProgress();
Dialog progress = inf.showInifiniteBlocking();
final Form loginForm = new Form("Login");
loginForm.setUIID("Form1");
loginForm.setLayout(new BorderLayout());
try
{
//Log.p("Inside showLoginForm method");
WebBrowser browser = new WebBrowser()
{
};
//browser.setURL(appsGlobalSettings.get(URL_KEY));
browser.setURL("http://www.google.co.in");
//Log.p("Set Broswer url");
loginForm.addComponent(BorderLayout.CENTER,browser);
//Log.sendLog();
loginForm.show();
}
catch(Exception e)
{
e.printStackTrace();
//Log.p(e.toString());
}
}
Result - the same blank screen.
Same code with added Log.p and Log.send() statements.
Result - it works fine
Is this due to some race condition?

Playing YouTube video in iPhone only app - loss of controls

The code below is used to put a small WebView on a View so that the user can tap it and the video opens in full screen mode and plays. All that works, but after 4 seconds of play the controls disappear and will not reappear (tapping, rotating...). Once the video finishes, the controls reappear and the 'Done' button becomes available. However once the WebView is disposed of and a new view loaded, that new view is unresponsive for up to 6 minutes.
[Preserve (AllMembers=true)]
public class YouTubeViewer : UIWebView
{
public static AppDelegate appDelegate = (AppDelegate) UIApplication.SharedApplication.Delegate;
public YouTubeViewer(string url, RectangleF frame)
{
Log.WriteLog("loading YouTubeView");
appDelegate.firstViewing = true;
this.UserInteractionEnabled = true;
this.BackgroundColor = UIColor.Clear;
this.Frame = frame;
string youTubeVideoHTML = #"<object width=""{1}"" height=""{2}""><param name=""movie""
value=""{0}""></param><embed
src=""{0}"" type=""application/x-shockwave-flash""
width=""{1}"" height=""{2}""</embed></object>";
string html = string.Format(youTubeVideoHTML, url, frame.Size.Width, frame.Size.Height);
this.LoadHtmlString(html, null);
}
}
Here is how the WebView is disposed of:
public void RemoveWebView(UIWebView inView)
{
try
{
Log.WriteLog("RemoveWebView");
NSUrlCache.SharedCache.RemoveAllCachedResponses();
NSUrlCache.SharedCache.DiskCapacity = 0;
NSUrlCache.SharedCache.MemoryCapacity = 0;
inView.LoadHtmlString("",null);
inView.EvaluateJavascript("var body=document.getElementsByTagName('body')[0];body.style.backgroundColor=(body.style.backgroundColor=='')?'white':'';");
inView.EvaluateJavascript("document.open();document.close()");
inView.StopLoading();
inView.Delegate = null;
inView.RemoveFromSuperview();
inView.Dispose();
}
catch(Exception ex)
{
Log.LogError("RemoveWebView",ex);
}
}
Thanks,
Rick
I talked to Xamarin and they suggested removing the override for orientation management in the AppDelegate.
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations(UIApplication application, UIWindow forWindow)
{ /*... code ...*/ }
After I removed this override my application worked as expected when loading YouTube videos.
This resolved the issue for me. You can still control supported orientations via individual ViewController overrides and globally via the Info.plist file.
https://github.com/nishanil/YouTubePlayeriOS
Hope this sample helps you. It worked well for me.

How to get live camera preview in Windows Phone 8

I want to create an application in Windows phone8. In this application i want to show live camera preview with different effect in multiple frame using C# in Windows phone 8. please give me a solution
To use the camera in Windows phone 8 you need to use the PhotoCamera object. Best to create this object on your OnNavigatedTo like so:
protected override void OnNavigatedTo (System.Windows.Navigation.NavigationEventArgs e)
{
if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary) == true)
{
cam = new PhotoCamera(CameraType.Primary);
cam.CaptureImageAvailable += new EventHandler<Microsoft.Devices.ContentReadyEventArgs>(cam_CaptureImageAvailable);
viewfinderBrush.SetSource(cam);
}
else
{
txtMessage.Text = "A Camera is not available on this device."; }
}
}
// dispose when we leave
protected override void OnNavigatingFrom (System.Windows.Navigation.NavigatingCancelEventArgs e)
{
if (cam != null)
{
cam.Dispose();
}
}
To actually capture the image from the camera you can then call the CaptureImage method on the cam object.

Resources