How to create a videoThumbnail for remote file? - android

I am trying to create a video thumbnail for a file :
1- the file is located on YouTube.
2- I would start an implicit intent for Andriod OS to play this file using:
Intent intent= new Intent(Intent.ACTION_VIEW, Uri.parse(youTubeVideoWebPath));
startActivity(intent);
where
String youTubeVideoWebPath = "http://www.youtube.com/watch?feature=player_detailpage&v=OZJalBmtGnQ";
after searching some posts on the forum, I found it could be either:
1- VideoView and set its background with the Thumbnail that I will extract from the video Or
2- ImageView which sets its source/background with the extracted Thumbnail
when an item (whether VideoView or ImageView) is clicked, I will send the previous mentioned intent.
since I am not going to control playing the video by my application, I guess that it is better to use ImageView, right?
Secondly,
I would like to create a video Thumbnail for that remote file so what is the best/easiest way to do that?
For me, after doing more search on the forum, I found the following method:
Bitmap thumbAsBitmap = ThumbnailUtils.createVideoThumbnail(filePath, MediaStore.Video.Thumbnails.MINI_KIND);
But it always returns null, I dont know why although that I passed it:
filePath: the web path of the file mentioned above
second argument: not sure whether it should be MediaStore.Video.Thumbnails.MINI_KIND or
MediaStore.Images.Thumbnails.MINI_KIND?
I can only find posts related to extracting VideoThumbnail from files saved in internal/external memory, nothing related to remote files such as my case.

Why not fetch YouTube thumbnail? It looks quite simple. Once you got video URL, like this:
https://www.youtube.com/watch?v=dRpFF5Dm-k0
you extract video ID (which in this case is dRpFF5Dm-k0) and your thumbnail is at:
http://i1.ytimg.com/vi/<VIDEOID>/default.jpg
so in this case:
http://i1.ytimg.com/vi/dRpFF5Dm-k0/default.jpg
Not sure if that works for any video (I just found that out to answer your question), but at least it is a good start :)

Related

Google Drive Custom Thumbnail for Standard MIME Type

I have yet another pesky question for people who understand how Google Drive SDK works. On Android platform, I am creating my own custom thumbnails for JPEG image files ( thumbnail is a reduced JPG of the most important detail of the parent image ), The size is a bit non-standard - 384 x 128px, but well within limits stated in the documentation. So, the code goes like this:
// thumbnail
String myThumb = "test.tnl";
Thumbnail tn = new Thumbnail();
tn.setMimeType("image/jpeg");
tn.setImage(Base64.encodeBase64String(myThumb.getBytes()));
// define meta-data
File body = new File();
body.setTitle("test.jpg");
body.setDescription("bla bla");
body.setMimeType("image/jpeg");
body.setThumbnail(tn);
File gooFl = drvSvc.files()
.insert(body, new FileContent("image/jpeg", new java.io.File(test.jpg)))
.execute();
and executes flawlessly (there are more 'body' elements I don't list here) and everything works like a charm. But when I download the image, my thumbnail is gone, replaced by standard Google thumbnail - s220 type.
I did notice the documentation statement:
As with indexable text, Drive automatically generates thumbnails for many common file types. For shortcuts and other file types Drive can not render, you can provide a thumbnail image generated by your application.
Reading it ambiguously, I was hoping that by supplying my own thumbnail to a known MIME type, I will keep Google Drive from generating its standard one, but it probably is not the case. So the question remains. Is there a solution to my problem? Having custom thumbnails for standard "image/jpeg" MIME types? Or is there a work-around, perhaps another custom field I can stick some 10Kb of binary data in? I need the thumbnails in my Android viewer - another app.
Thank you, sean
Google Drive will only use custom thumbnails for non-standard MIME types, so you can't override the one for jpeg. Your app can use a custom file property to store and read proprietary data:
https://developers.google.com/drive/properties

android send email with an image screenshot created but not saved

I want to make a screenshot of the screen without saving the image, now I do this to make a screenshot:
View view = webView.getRootView();
view.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
result = new PluginResult(PluginResult.Status.OK);
And to attach the image to the email:
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///INFINITA-PL.png"));
I do not know how to do it without path.
The EXTRA_STREAM value has to be a Uri that can be opened by the Email process. If you don't want to save it as a file and pass that along you will need to implement a ContentProvider to make it accessible. In general this is pretty messy to do: I can echo the comments in that question (I struggled for awhile to do it without hitting the file system before giving up).
You're probably better served using a File and moving on to the rest of your app.

Load image from sdcard into html

Hi I have implemented an android web server and I am serving html pages on the fly, based on the uri requested.
When I try to include images from my sdcard they are not showing up on the html page. I have the requisite permissions in the manifest. I have tried looking around but, most of the examples involve images within webview. I am using the following code to get path to the .png files on the sdcard.
String file_icon=Environment.getExternalStorageDirectory().getAbsolutePath()+"/file_icon.png";
String folder_icon=Environment.getExternalStorageDirectory().getAbsolutePath()+"/folder_icon.png";
and I am writing to the outputstream using the following
writer.write("<tr><td><input type=\"checkbox\" name=\""+files.toString()+"\" value=\"file\"/></td><td><img src=\""+file_icon+"\"/>"+files.toString()+"</tr>");
writer.write("<tr><td><input type=\"checkbox\" name=\""+files.toString()+"\" value=\"file\"/></td><td><img src=\""+folder_icon+"\"/>"+files.toString()+"</tr>");
When I fire up the emulator and visit the page I see no images.
screen http://img820.imageshack.us/img820/7973/capturekuw.png
Any ideas or pointers in the right direction would be greatly appreciated.Thanks.
After looking around I found out that I needed to implement a ContentProvider and override the openFile() method.
http://www.techjini.com/blog/2009/01/10/android-tip-1-contentprovider-accessing-local-file-system-from-webview-showing-image-in-webview-using-content/

How to add image to android app?? I reached till Imageview class but could not figure out further

I am very new to Android development.
I am trying to add an image to my Android application by code. I found this, but it is showing some drag and drop way to do it.
I want to do it by coding in my onCreate method.
I managed to do this:
ImageView iv = new ImageView(this);
But could not figure out how to set the image-uri.
I tried the following:
iv.setImageURI(#"C:\Users\SONY\Downloads\slide.butcher.home.jpg");
with and without # but I think I need to pass an URI.
I tried to create an object of android.net.Uri, but it seems it can not be instantiated.
See the uri you have tried is wrong it is located on your local file system.. Instead try to push the image on the device's sdcard with the help of DDMS of eclipse..
Suppose you have pushed it on /sdcard/your_image.jpg. then in your code set your image path as
imageView.setImageUri (Uri.parse("/sdcard/your_image.jpg"));
I m sure you will get it...
ImageView iv = (ImageView)findViewById(v);
iv.setImageResource(R.drawable.image);
iv.setImageURI(#"C:\Users\SONY\Downloads\slide.butcher.home.jpg");
You are trying pass Uri of image which is stored on your Computer!!!!
Copy that file on your device SD Card.
Suppose you copied it under /sdcard/home.jpg
Then use below code to display it in ImageView.
imageView.setImageUri(Uri.parse("/sdcard/home.jpg"));

Android Photo Viewer Demo

I've been trying to figure out how to display a photo on Android. I can create an ImageView and display a picture, but the functionality is limited (no zoom, pan or share). Is there a demo or tutorial with code out there on how to do this? I've been searching all week with no luck.
Thanks.
P.S.> Please No Snark!
Maybe I don't understand how to create a uri correctly or how to make my resource available to the viewer. I have a resource ID, R.drawable.opal, I'm using to display different minerals and gems for a science project. If the student clicks the small sample photo, then I want to bring up a bigger and better viewer for the photo to allow them to compare to their collected rock.
Unless you really need to build your own you should probably just use the gallery's viewer. Send it the picture by using the view intent like so:
Intent viewImageIntent = new Intent(android.content.Intent.ACTION_VIEW, uri);
startActivity(viewImageIntent);
Replace "uri" with the image's uri of course. Writing your own viewer is really involved and would include threading, physics calculations and handling touch inputs.

Categories

Resources