Reputation: 1372
I have created a gallery view and I want to display video (like any video link) and I have worked like this
http://mihaifonoage.blogspot.com/2009/09/displaying-images-from-sd-card-in.html
but its display nothing. I spend whole day but no result. Please help me.
Thanks in advance.
Upvotes: 1
Views: 9763
Reputation: 2321
For play video directly from GridView you have to pass video url in following function
public void playVideo(String url){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + url), "video/*");
startActivity(intent);
}
Upvotes: 0
Reputation: 1372
I have got my answer.
I need to create each video thumbnails and display them into gallery like this
Bitmap bm = ThumbnailUtils.createVideoThumbnail(path1.getPath()+"/"+filenames1[position], MediaStore.Images.Thumbnails.MINI_KIND);
and then each video show in the gallery like image.
Upvotes: 4
Reputation: 46963
I am not quite I get what you need, but if you just want to open a single view in a activity maybe a good way to go is using the ACTION_VIEW
intent - the native way to do it.
public void startVideo(String videoAddress){
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(videoAddress), "video/3gpp"); // The Mime type can actually be determined from the file
activity.startActivity(intent);
}
However this intent will prompt your users to choose a player for the video. In most of my cases I found using the VideoView tag more useful - just display the video full screen:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<VideoView
android:id="@+id/video_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" />
</FrameLayout>
If you want to be able to browse between many videos you can implement loading of the new video using gesture detectors:
GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector() {
@Override
public void swipeRight() {
if (currentArticle > 0) {
currentArticle--;
loadPage();
}
}
@Override
public void swipeLeft() {
if (currentArticle == articleList.size()) {
return;
} else {
currentArticle++;
loadPage();
}
}
});
View.OnTouchListener gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
};
Hopefully some of my suggestions will prove useful to you!
Upvotes: 2