Discussion Forums  >  Uncategorized

Replies: 18    Views: 1758

omeganu
I hate code!
Profile
Posts: 7
Reg: Nov 27, 2010
Minneapolis, MN
70
01/12/11 10:02 PM (15 years ago)

MP4 video. Android browser vs. Custom URL from main menu.

Here is the basic concept... App with videos hosted on an FTP server and accessible by a web page. For example, you launch the Buzztouch app, launch a custom URL (through the main menu) with links to MP4 videos throughout the page, and you can explore them one by one. Here is the challenge... This method worked great for the iPhone! That version is already on iTunes and receiving positive reviews. Nothing to fumble with there. However, the Android version simply won't play a video when you start linking off my custom URL page that I configured in the app. Here is the kicker... I can manually type in the same URL (as mentioned above from the app's main menu) in the Android's native web browser, and successfully link through to my videos (which start playing right away without any issue). However, since I'm going to be selling this app, the Buzztouch feature of conveniently hiding the actual web address from the user is perfect for me....it allows me to have some level of control over people simply jumping to my videos since they're not able to see the actual web address. Here is my question... Is this a limitation to Buzztouch app's web browsing abilities on the Android? I'm guessing there must be something missing when you tap the link to play a video and it simply does nothing...versus it working just fine in the Android's browser.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
01/13/11 12:32 AM (15 years ago)
This is a good question. We hear about random issues with the Android browser, there is no doubt that it is WAY more of pain for us than the Safari Browser which seems to just work. With that said, there is almost always a fix. So... it sounds like the device is totally capable of playing the .mp4 content - cool. Sometimes the codec / compression settings screw things up and videos don't play as expected, regardless of the file extension. Not the case here... So... why won't they play. Additionally, why are you not seeing any errors, messages, app crashes, etc. Strange. I'm digging through some source-code to see what may be an issue.... in the meantime... post a URL for a video that won't play (one that you use in your app) so I can test it.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
01/13/11 12:43 AM (15 years ago)
Lets try this.... make a simple adjustment and see if it works, I'm thinking it will. I can download your project and test further if it doesn't but this could be much quicker (you're in a long line, wink) a) Open up the Android project and find the Screen_CsutomURL.java file. It's in the src / com.yourapp folder b) Scroll down to the public boolean shouldOverrideUrlLoading(WebView view, String url) method c) Look for the note that reads //youtube video. You'll see a little code-snippet that looks at the URL to see if it contains the word youtube.com if it does, it launches the native app to play the youtube video. I'm thinkin we can do the same thing for .mp4 links. If the URL contains .mp4, lets try to launch the native app and see if it plays d) Under the youtube code-snippet (just above where it reads //allow loading of this URL add this //trap .mp4 videos if(url.contains(.mp4)){ useNativeIntent = 1; } Use the tab bar to format the code nicely, not ghetto-code allowed (funny). Recompile and re-test. Tap a link that contains .mp4 and see if it launches the native player. Be sure to report back so I don't wonder about it.
 
Annonymous
Profile
01/13/11 08:57 AM (15 years ago)
Hi David- I added the code snippet you provided....initially I got error messages and then I realized that it wanted quotation marks (.mp4). After getting the error to go away, I ran the simulator and experienced the same thing. URLs load, links directly to MP4 videos do not (consequently they still load in the Android browser...) Here is one of the URLs with a link to a video... http://www.omeganualpha.com/skyway/Skyway_Tour_Twin_Cities/6-g.html (on a side note...if I ever get savvy enough to configure the multi-location map with the correct API key, I'll ultimately have each location link directly to a URL like this one....that's what I've done on the iPhone version and I'm loving it (as are the people buying the app!).....but for now, Android users will just use a non-interactive map with links to these pages throughout the page...no GPS)
 
omeganu
I hate code!
Profile
Posts: 7
Reg: Nov 27, 2010
Minneapolis, MN
70
like
01/13/11 09:01 AM (15 years ago)
Hi David- I added that snippet of code. Apart from Eclipse wanting quotation marks around the .mp4 - (.mp4) - it seemed to accept everything. I ran the simulator but there was no change. Thanks!!
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
01/13/11 10:25 AM (15 years ago)
OK, I added the snippet to a test app, clicking the Watch the Video image / icon, the simulator DOES load the native video player and plays nicely. So, are you sure you have entered ( I copy-n-pasted this snippet from my test project so there are no typos ) //capture .mp4 videos if(url.contains(.mp4)){ useNativeIntent = 1; } If you are, are you sure you re-compiled? After making the source-code change, select the project then choose Clean from the Project Menu. Re-run as an Android App and see what happens.
 
Zoid66
Lost but trying
Profile
Posts: 176
Reg: Oct 26, 2010
USA
1,760
like
01/13/11 11:11 AM (15 years ago)
I am using the above and works if the url to the mp4 off the custom url menu. NOW if you add a link that takes you to a page where you then have to click a link (In the WebView) to the mp4: THIS does not work. I think this is all part of a slew of items that will need addressed in the next release. Such as, emails, and phone numbers.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
01/13/11 12:18 PM (15 years ago)
I am clicking a link in a web-page. I built an app and created a CustomURL screen using the url provided. It displays a web-page with a Button / Image to play the movie. It's a link to a URL that ends with .mp4. After making the adjustment in the Custom_URL.java file, and asked the app to use the native browser when links contain contain .mp4, it worked. I did this in the simuator and an actual device. The movie loads in the native browser after clicking the link in the web-page. Not sure where else to go from here on this one...
 
omeganu
I hate code!
Profile
Posts: 7
Reg: Nov 27, 2010
Minneapolis, MN
70
like
01/13/11 12:34 PM (15 years ago)
I was ultimately able to get the video to load from within the Buzztouch app...and consequently I am doing it from a link that takes me to a web page with a map on it and subsequently to another web page with the link to the video. When the video has completed, the screen hangs there with no navigation or ability to return back to the page it was loaded from. Is there something I can add to the code that directs the app to return to the previous screen when the video has completed playing?
 
omeganu
I hate code!
Profile
Posts: 7
Reg: Nov 27, 2010
Minneapolis, MN
70
like
01/13/11 12:43 PM (15 years ago)
Thank you for your efforts by the way...I can only imagine the countless directions you are getting pulled in with this service! I'm sure I'm not the first to say that what you're doing is very appreciated.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
01/13/11 01:13 PM (15 years ago)
Thanks... you're right...plenty to do ;-) Did you get it to work? Something's not making sense. Mac / PC / Device type? Have you tried it on an actual device?
 
omeganu
I hate code!
Profile
Posts: 7
Reg: Nov 27, 2010
Minneapolis, MN
70
like
01/13/11 01:21 PM (15 years ago)
Just got it to work on a device. Off to market I go. Thanks again for you help.
 
Zoid66
Lost but trying
Profile
Posts: 176
Reg: Oct 26, 2010
USA
1,760
like
01/14/11 07:25 AM (15 years ago)
Okay I went back and looked at my code: What you did works for mp4: I thought that was one I added already but 'forgot that one'. By default Android WebView does not handle email, phone, and a slew of other things: Adding the below will allow the phone use the click button calls, emails etc from a webpage. If you have a few minutes i tested with http://m.espn.go.com/wireless/help/ and there is a call button: It works but when you go back to the app the CUSTOM URL page is left in a error... (Not as clean but better then not launching the phone dialer) etc.. I think CustomHTML would need some code as well to handle such events. I don't see any let phone decide intent in that class. //youtube video if(url.contains(youtube.com)){ useNativeIntent = 1; } //capture .mp4 videos if(url.contains(.mp4)){ useNativeIntent = 1; } //capture market applications if(url.contains(market://)){ useNativeIntent = 1; } //capture tel numbers if(url.contains(tel:)){ useNativeIntent = 1; } //capture email numbers if(url.contains(mailto:)){ useNativeIntent = 1; } //capture mp3 numbers if(url.contains(.mp3)){ useNativeIntent = 1; } //capture mp3 numbers if(url.contains(.mp)){ useNativeIntent = 1; } //allow loading of this URL if(useNativeIntent == 0){ //showProgress(Loading..,This may take a moment if you have a slow internet connection.); loadBrowser(url); return true; }
 
Kazuko
Aspiring developer
Profile
Posts: 4
Reg: Jun 03, 2011
San Francisco
40
like
06/03/11 01:54 AM (14 years ago)
I attempted your solution however was returned the error useNativeIntent cannot be resolved to a variable
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
06/03/11 01:58 AM (14 years ago)
Hi in San Fran. This is an old post and I'll need to get my head around it again ;-) It sounds like you have a simple syntax error or something. If you want, email the file you chagned to info 'at' buzztouch.com so I can get a look. I'll return it with some comments.
 
Kazuko
Aspiring developer
Profile
Posts: 4
Reg: Jun 03, 2011
San Francisco
40
like
06/03/11 02:04 AM (14 years ago)
I am going to post my code so you can have a go at it. I believe what the other forum members are looking for as am I, is to allow this in webview. As you can tell, I've tried everything! I heard that you were the mastermind so please, help me Obi One Kanobi, you're my only hope. package com.AFMoB.GoogleJapan101; import android.app.Activity; import android.os.Bundle; import android.view.KeyEvent; import android.view.Menu; import android.webkit.WebView; import android.webkit.WebViewClient; import android.webkit.WebSettings; import android.view.MenuItem; public class GoogleJapan101 extends Activity { /* Called when the activity is first created. */ public WebView webView; //DECLARE webview variable outside of onCreate function so we can access it in other functions (menu) @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); webView = (WebView) findViewById(R.id.webview); // Create an instance of WebView and set it to the layout component created with id webview in main.xml WebView webView = (WebView)findViewById(R.id.webview); WebSettings webSettings = webView.getSettings(); // Fetches the WebSettings import WebViewClient webViewClient = new WebViewClient(); // Enabling mp4 webView.setWebViewClient(webViewClient); // Enabling mp4 webSettings.setPluginsEnabled(true); // Allows plugins to run which are normally disabled in webView webView.getSettings().setBuiltInZoomControls(true); // Allows the Android built in zoom control webView.getSettings().setSaveFormData(true); webView.getSettings().setLoadsImagesAutomatically(true); webView.getSettings().setPluginsEnabled(true); webView.getSettings().setLoadsImagesAutomatically(true); webView.getSettings().setSupportMultipleWindows(true); webView.getSettings().setPluginsEnabled(true); webView.getSettings().setLightTouchEnabled(true); webView.getSettings().setAllowFileAccess(true); // To allow file downloads/streams such as mp4, mpeg, and 3gp files webView.getSettings().setJavaScriptEnabled(true); // Enables HTML Javascript to run in webview webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); webView.getSettings().setSupportZoom(true); // Support the zoom feature webView.getSettings().setSavePassword(true); // Allow users to save passwords in forms webView.setWebViewClient(new WebViewClient() { // Opens web links clicked by user in the webview @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { // Handle the error } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); webView.loadUrl(http://www.google.com/search?tbs=vid:1&source=mog%gl=us&q=japan%20earthquake%20-youtube); // Modify the URL for webview here } public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); // Add menu items, second value is the id, use this in the onCreateOptionsMenu menu.add(0, 1, 0, Back); menu.add(0, 2, 0, Refresh); menu.add(0, 3, 0, Forward); return true; // End of menu configuration } public boolean onOptionsItemSelected(MenuItem item){ // Called when you tap a menu item switch (item.getItemId()){ case 1: //If the ID equals 1, go back webView.goBack(); return true; case 2 : //If the ID equals 2, refresh webView.reload(); return true; case 3: //If the ID equals 3, go forward webView.goForward(); return true; } return false; } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // Enables browsing to previous pages with the hardware back button if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) { // Check if the key event was the BACK key and if there's history webView.goBack(); return true; } // If it wasn't the BACK key or there's no web page history, bubble up to the default // system behavior (probably exit the activity) return super.onKeyDown(keyCode, event); } }
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
06/03/11 02:10 AM (14 years ago)
Obi One Kanobi - laughing. What file is this from? The name of the file in the buzztouch project. It does not look like Screen_CustomHTML.java, the file this discussion was talking about. If it's not that file, give a little explanation of what you're trying to do.
 
Kazuko
Aspiring developer
Profile
Posts: 4
Reg: Jun 03, 2011
San Francisco
40
like
06/03/11 02:27 AM (14 years ago)
I am attempting to create a webapp in webview that can open audio and video files if necessary.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
06/03/11 02:32 AM (14 years ago)
Ah....OK, makes sense. I can't offer any help using the code you pasted because the forum removes lots of syntax. However, I can offer this. You'll need to implement to intercept all the clicks in the HTML. So, if a user clicks a link with a .MP3, or .MOV or any other file you want to open in a different window, you can. The method is called: public boolean shouldOverrideUrlLoading(WebView view, String url) You'll need to create that method, then analyze the URL being clicked to then decide what to do with it. Google for Android WebView or something. I can't do any troubleshooting on your source-code, only on source-code created with a buzztouch app.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.