How to make a VideoView Preview UI in Android? - android

So I'm a beginner in android and I've been trying to experiment media related elements of Android. So far, I was able to display video, but I saw Viber and some other similar apps have some slick way of displaying video like below, wherein when tapped will open an app viewer wherein images/videos of app can be seen there:
Here is my code, it starts video immediately... I tried the .seekTo(100), ..seekTo(0) option but both gives me a black screen.
Uri uri = Uri.parse(mVideoFileName);
mVideoMessageView.setVideoURI(uri);
mediaC.setAnchorView(mVideoMessageView);
mVideoMessageView.start();
I wonder, how they made an overlay of a play button on the video, duration, and even timestamp and have a snapshot of it. Any advice would greatly be appreciated.
Thanks a lot.

int id = **"The Video's ID"**
ImageView iv = (ImageView ) convertView.findViewById(R.id.imagePreview);
ContentResolver crThumb = getContentResolver();
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 1;
Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(crThumb, id, MediaStore.Video.Thumbnails.MICRO_KIND, options);
iv.setImageBitmap(curThumb);
Also you can use Glide for this
Glide
.with( context )
.load( Uri.fromFile( new File( filePath ) ) )
.into( imageViewGifAsBitmap );

Related

How to get frame of stream video link with Glide

in my android TV application, at start i want to show a frame of my each stream links. my current solution is using LoaderManager and the problem of this technique is to it's too slow(application crashed).
FFmpegMediaMetadataRetriever to load and set video stream link.
this.retriever = new FFmpegMediaMetadataRetriever();
Bitmap bitmap = null;
retriever.setDataSource(this.mSelectedStream.getStreamUrl());
bitmap = retriever.getFrameAtTime();
drawable = new BitmapDrawable(bitmap);
retriever.release();
i found this thread that explain that glide can used to load image from video links.
BitmapPool bitmapPool = Glide.get(getApplicationContext()).getBitmapPool();
int microSecond = 6000000;// 6th second as an example
VideoBitmapDecoder videoBitmapDecoder = new VideoBitmapDecoder(microSecond);
FileDescriptorBitmapDecoder fileDescriptorBitmapDecoder = new FileDescriptorBitmapDecoder(videoBitmapDecoder, bitmapPool, DecodeFormat.PREFER_ARGB_8888);
Glide.with(getApplicationContext())
.load(yourUri)
.asBitmap()
.override(50,50)// Example
.videoDecoder(fileDescriptorBitmapDecoder)
.into(yourImageView);
but when i used above code i get "cannot access from outside of package" error for VideoBitmapDecoder.
exmaple link = "http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8"
any idea?
thanks
I've used this snippet to get thumb nail out of video frames. Try it
Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(media_url,
MediaStore.Images.Thumbnails.MINI_KIND);
BitmapDrawable BD = new BitmapDrawable(thumbnail);
videoView.setBackgroundDrawable(BD);

Android: Receive HTML page through intent

I have enabled My App for the share via options in the HTML page. Now, I am trying to store the HTML page from where this was triggered in my sdcard. For this purpose, I was trying to use the intent contents.
I used the following for images and It worked like charm..
Uri imageUri = (Uri) shareintent.getParcelableExtra(Intent.EXTRA_STREAM);
Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
ContentResolver cr = getContentResolver();
InputStream is = cr.openInputStream(uri);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = false;
Bitmap imageBitmap = BitmapFactory.decodeStream(is ,null, options);
Please can you give me an hint of how to save the HTML page in my sdcard?
within a WebView (a layout which allows opening webpages within your application...among other things) and using HttpClient.execute() or HttpClient.get() should do the trick for you.

Get cover picture by song

Is it possible to get a cover picture by song and not by album.
Because I have one self combined album with songs and they all have different cover pictures.
But when I want to query them I always get the same picture returned.
String[] ARG_STRING = {MediaStore.Audio.Media.ALBUM_ID};
...
String albumCover = _cursor.getString(_cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));
...
MusicUtils.getArtwork(this, -1, Integer.parseInt(albumID));
So i would like to know how it's possible to get an cover image of an song.
I know MusicUtils supports getArtwork by SongId, but what ID should I use because MediaStore.Audio.Media._ID is not working.
I'm not familiar with MusicUtils, however, you should be able to get the cover art from the file itself by using MediaMetadataRetriever. Here is a brief code snippet showing how to use it. The uri referenced is the content uri for the file you want to retrieve the art for.
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
byte[] rawArt;
Bitmap art;
BitmapFactory.Options bfo=new BitmapFactory.Options();
mmr.setDataSource(getApplicationContext(), uri);
rawArt = mmr.getEmbeddedPicture();
// if rawArt is null then no cover art is embedded in the file or is not
// recognized as such.
if (null != rawArt)
art = BitmapFactory.decodeByteArray(rawArt, 0, rawArt.length, bfo);
// Code that uses the cover art retrieved below.

how to get video thumb nail from raw folder video on android

in my app i need to display video thumb nail which is stored in res/raw folder. i searched regard it. i get the following code.
int id = **"The Video's ID"**
ImageView iv = (ImageView ) convertView.findViewById(R.id.imagePreview);
ContentResolver crThumb = getContentResolver();
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 1;
Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(crThumb, id, MediaStore.Video.Thumbnails.MICRO_KIND, options);
iv.setImageBitmap(curThumb);
by this code i get video thumb nail from sdcard. but video from res/raw folder it does not show video thumb nail. i tried long time but i could not find solution. i tried in the following way.
I create an array and store the resource id (Ex: int[] videoid={R.raw.vi1,...}) and place the id in MediaStore.Video.Thumbnails.getThumbnail(crThumb, videoid[position], MediaStore.Video.Thumbnails.MICRO_KIND, options);.
please help me. thanks in advance.
You can try to get some frame out of your video just like this:
Uri videoURI = Uri.parse("android.resource://" + getPackageName() +"/"
+R.raw.cashword_video);
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(this, videoURI);
Bitmap bitmap = retriever
.getFrameAtTime(100000,MediaMetadataRetriever.OPTION_PREVIOUS_SYNC);
Drawable drawable = new BitmapDrawable(getResources(), bitmap);
Video on res/raw folder of your application aren't managed by Android Media Content Provider, so you cannot obtain their thumbnail from it.
Alternatively, you can try to save them as normal file in your SD and, then, ask to media provider for thumbnail or create it directly via ThumbnailUtils.createVideoThumbnail class (only Android 2.2 or above)
Use Android Glide Library for that
In Project Gradle
repositories {
mavenCentral()
google()
}
In app Gradle
dependencies {
implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
}
Use below code in you activity
Glide.with(this).load(R.raw.demo).diskCacheStrategy(NONE).into(imageView);
Glide.with(this).load("file:///android_asset/demo.mp4").diskCacheStrategy(NONE).into(imageView);
Glide.with(this).load("android.resource://" + context.getPackageName() + "/raw/demo").diskCacheStrategy(NONE).into(imageView);

cover art on android

I am developing a sort of media player for android. The question is how can i get the cover art of audio file on android.
For example the default android media player shows album covers when listing albums, how can i get this artworks.
Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id);
ContentResolver res = context.getContentResolver();
InputStream in = res.openInputStream(uri);
Bitmap artwork = BitmapFactory.decodeStream(in);
More complete sample code can be found in Android Music player source here https://github.com/android/platform_packages_apps_music/blob/master/src/com/android/music/MusicUtils.java method getArtworkQuick.
You can use
MediaMetadataRetriever
class and get track info i.e. Title,Artist,Album,Image
Bitmap GetImage(String filepath) //filepath is path of music file
{
Bitmap image;
MediaMetadataRetriever mData=new MediaMetadataRetriever();
mData.setDataSource(filePath);
try{
byte art[]=mData.getEmbeddedPicture();
image=BitmapFactory.decodeByteArray(art, 0, art.length);
}
catch(Exception e)
{
image=null;
}
return image;
}
I don't know why everybody is making it so complicated you can use Glide to achieve this in simplest and efficient way with just 1 line of code
Declare this path in App Constants -
final public static Uri sArtworkUri = Uri
.parse("content://media/external/audio/albumart");
Get Image Uri using Album ID
Uri uri = ContentUris.withAppendedId(PlayerConstants.sArtworkUri,
listOfAlbums.get(position).getAlbumID());
Now simply display album art using uri :-
Glide.with(context).load(uri).placeholder(R.drawable.art_default).error(R.drawable.art_default)
.crossFade().centerCrop().into(holder.albumImage);
Glide will handle caching, scaling and lazy loading of images for you.
Hope it help somebody.
Here i can attach one function that is return album art from media store .
Here in function we just have to pass the album_id which we get from Media store .
public Bitmap getAlbumart(Long album_id)
{
Bitmap bm = null;
try
{
final Uri sArtworkUri = Uri
.parse("content://media/external/audio/albumart");
Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id);
ParcelFileDescriptor pfd = context.getContentResolver()
.openFileDescriptor(uri, "r");
if (pfd != null)
{
FileDescriptor fd = pfd.getFileDescriptor();
bm = BitmapFactory.decodeFileDescriptor(fd);
}
} catch (Exception e) {
}
return bm;
}
Based on your comments to others, it seems like your question is less about Android and more about how to get album art in general. Perhaps this article on retrieving album art from Amazon will be helpful. Once you have a local copy and store it as Nick has suggested, I believe you should be able to retrieve it the way Fudgey suggested.
Android only recognizes files named "AlbumArt.jpg" as Album Covers. Just put the pictures with that name in the album folder and you'll be fine..
I don't know if you read that google is making Stackoverflow the official Android app development Q&A medium but for beginner questions... Now, I know nothing about developing in andriod, but a quick search of the Android Developers site, I found this:
MediaStore.Audio.AlbumColumns
Hopefully it'll help.

Categories

Resources