android - How can i play a video selected from the sd card? -



android - How can i play a video selected from the sd card? -

public class videodemo extends activity { private videoview video; private mediacontroller ctlr; file clip=new file(environment.getexternalstoragedirectory(); { if (clip.exists()) { video=(videoview)findviewbyid(r.id.videogrdview); video.setvideopath(clip.getabsolutepath()); ctlr=new mediacontroller(this); ctlr.setmediaplayer(video); video.setmediacontroller(ctlr); video.requestfocus(); video.start(); } }}; }

}

so i've got videogrdview of videos on sd card display in separate activity, need know how click video grid , have play through media player. help appreciated.

public class menus extends activity { //set constants mediastore query, , show videos private final static uri media_external_content_uri = mediastore.video.media.external_content_uri; private final static string _id = mediastore.video.media._id; private final static string media_data = mediastore.video.media.data; //flag 1 used images selection private gridview _gallery; private cursor _cursor; private int _columnindex; private int[] _videosid; private uri _contenturi; protected context _context; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); _context = getapplicationcontext(); _gallery = (gridview) findviewbyid(r.id.videogrdvw); //set default external/sdcard uri _contenturi = media_external_content_uri; //initialize videos uri //showtoast(_contenturi.getpath()); initvideosid(); //set gallery adapter setgalleryadapter(); } private void setgalleryadapter() { _gallery.setadapter(new videogalleryadapter(_context)); _gallery.setonitemclicklistener(_itemclicklis); } private adapterview.onitemclicklistener _itemclicklis = new onitemclicklistener() { public void onitemclick(adapterview<?> parent, view v, int position, long id) { // want info location of file string [] proj={media_data}; // request our cursor 1 time again _cursor = managedquery(_contenturi, proj, // columns homecoming null, // clause; rows homecoming (all rows) null, // clause selection arguments (none) null); // order-by clause (ascending name) // want column index info uri int count = _cursor.getcount(); // _cursor.movetofirst(); // _columnindex = _cursor.getcolumnindex(media_data); // lets move selected item in cursor _cursor.movetoposition(position); startactivity(new intent("com.ave")); } }; private void initvideosid() { seek { //here set string array of thumbnail id column want string [] proj={_id}; // create cursor pointing external thumbnail store _cursor = managedquery(_contenturi, proj, // columns homecoming null, // clause; rows homecoming (all rows) null, // clause selection arguments (none) null); // order-by clause (ascending name) int count= _cursor.getcount(); // column index of thumbnail id _columnindex = _cursor.getcolumnindex(_id); //initialize _videosid = new int[count]; //move position first element _cursor.movetofirst(); for(int i=0;i<count;i++) { int id = _cursor.getint(_columnindex); // _videosid[i]= id; // _cursor.movetonext(); // } }catch(exception ex) { } } // private class videogalleryadapter extends baseadapter { public videogalleryadapter(context c) { _context = c; } public int getcount() { homecoming _videosid.length; } public object getitem(int position) { homecoming position; } public long getitemid(int position) { homecoming position; } public view getview(int position, view convertview, viewgroup parent) { imageview imgvw= new imageview(_context);; seek { if(convertview!=null) { imgvw= (imageview) convertview; } imgvw.setimagebitmap(getimage(_videosid[position])); imgvw.setlayoutparams(new gridview.layoutparams(96, 96)); imgvw.setpadding(8, 8, 8, 8); } catch(exception ex) { system.out.println("startactivity:getview()-135: ex " + ex.getclass() +", "+ ex.getmessage()); } homecoming imgvw; } // create thumbnail on fly private bitmap getimage(int id) { bitmap thumb = mediastore.video.thumbnails.getthumbnail( getcontentresolver(), id, mediastore.video.thumbnails.micro_kind, null); homecoming thumb; } }

}

gallery, pretty much works same way listview. within onitemclick method, should able know specific item clicked. uri/absolute path item, , pass on info next activity.

in videodemo class, extract uri/path , set videoview.

android video android-activity sd-card

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -