java - VideoView unable to open content from internel storage -
i have following code:
try { myvideoview.setmediacontroller(mediacontrols); file mydir = getdir("mydir", context.mode_private); myvideoview.setvideopath(mydir.getpath()+"/filename.3gp"); } catch (exception e) { log.e("error", e.getmessage()); e.printstacktrace(); } myvideoview.requestfocus(); myvideoview.setonpreparedlistener(new onpreparedlistener() { // close progress bar , play video public void onprepared(mediaplayer mp) { progressdialog.dismiss(); myvideoview.seekto(position); if (position == 0) { myvideoview.start(); } else { myvideoview.pause(); } } });
within oncreate() method. problem throws ioexception, , says unable open content
. works perfect if use myvideoview.setvideouri(path/to/server)
instead of myvideoview.setvideopath(path/to/local/storage)
. permissions @ manifest.xml
fine, , not says file not found or something. says unable open it. not video format problem either, because same video when play server. if useful info, have activity in background (same app), , videoview activity in foreground. thank you!
hi use play internal video
public class mainactivity extends activity { private cursor videocursor; private int video_column_index; listview videolist; int count; string[] thumbcolumns = { mediastore.video.thumbnails.data, mediastore.video.thumbnails.video_id }; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); init_phone_video_grid(); } @suppresswarnings("deprecation") private void init_phone_video_grid() { system.gc(); string[] proj = { mediastore.video.media._id, mediastore.video.media.data, mediastore.video.media.display_name, mediastore.video.media.size }; videocursor = managedquery(mediastore.video.media.external_content_uri, proj, null, null, null); count = videocursor.getcount(); videolist = (listview) findviewbyid(r.id.phonevideolist); videolist.setadapter(new videoadapter(getapplicationcontext())); videolist.setonitemclicklistener(videogridlistener); } private onitemclicklistener videogridlistener = new onitemclicklistener() { public void onitemclick(adapterview parent, view v, int position, long id) { system.gc(); video_column_index = videocursor.getcolumnindexorthrow(mediastore.video.media.data); videocursor.movetoposition(position); string filename = videocursor.getstring(video_column_index); intent intent = new intent(mainactivity.this, viewvideo.class); intent.putextra("videofilename", filename); startactivity(intent); } }; public class videoadapter extends baseadapter { private context vcontext; public videoadapter(context c) { vcontext = c; } public int getcount() { return count; } public object getitem(int position) { return position; } public long getitemid(int position) { return position; } public view getview(int position, view convertview, viewgroup parent) { system.gc(); viewholder holder; string id = null; convertview = null; if (convertview == null) { convertview = layoutinflater.from(vcontext).inflate(r.layout.listitem, parent, false); holder = new viewholder(); holder.txttitle = (textview) convertview.findviewbyid(r.id.txttitle); holder.txtsize = (textview) convertview.findviewbyid(r.id.txtsize); holder.thumbimage = (imageview) convertview.findviewbyid(r.id.imgicon); video_column_index = videocursor.getcolumnindexorthrow(mediastore.video.media.display_name); videocursor.movetoposition(position); id = videocursor.getstring(video_column_index); video_column_index = videocursor.getcolumnindexorthrow(mediastore.video.media.size); videocursor.movetoposition(position); // id += " size(kb):" + // videocursor.getstring(video_column_index); holder.txttitle.settext(id); holder.txtsize.settext(" size(kb):" + videocursor.getstring(video_column_index)); string[] proj = { mediastore.video.media._id, mediastore.video.media.display_name, mediastore.video.media.data }; @suppresswarnings("deprecation") cursor cursor = managedquery(mediastore.video.media.external_content_uri, proj, mediastore.video.media.display_name + "=?", new string[] { id }, null); cursor.movetofirst(); long ids = cursor.getlong(cursor.getcolumnindex(mediastore.video.media._id)); contentresolver crthumb = getcontentresolver(); bitmapfactory.options options = new bitmapfactory.options(); options.insamplesize = 1; bitmap curthumb = mediastore.video.thumbnails.getthumbnail(crthumb, ids, mediastore.video.thumbnails.micro_kind, options); holder.thumbimage.setimagebitmap(curthumb); curthumb = null; } /* * else holder = (viewholder) convertview.gettag(); */ return convertview; } } static class viewholder { textview txttitle; textview txtsize; imageview thumbimage; }
}
and video view class here
public class viewvideo extends activity { private string filename; videoview vv; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); system.gc(); intent = getintent(); bundle extras = i.getextras(); filename = extras.getstring("videofilename"); // vv = new videoview(getapplicationcontext()); setcontentview(r.layout.activity_main); vv = (videoview) findviewbyid(r.id.videoview); vv.setvideopath(filename); vv.setmediacontroller(new mediacontroller(this)); vv.requestfocus(); vv.start(); }
}
and xml part here
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <linearlayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="0.5" > <linearlayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="0.5" android:background="#242425" android:gravity="center" android:orientation="vertical" > <videoview android:id="@+id/videoview" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> </linearlayout> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="0.5" > <linearlayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="0.5" android:background="@android:color/white" android:gravity="center" android:orientation="vertical" > <listview android:id="@+id/phonevideolist" android:layout_width="match_parent" android:layout_height="match_parent" android:divider="@android:color/darker_gray" android:cachecolorhint="#00000000" android:dividerheight="2dp"></listview> </linearlayout> </linearlayout> </linearlayout>
Comments
Post a Comment