android - I want to display multiple video in listview using video but not able to do this -


this code.

public class mainactivity extends activity {     listview list;     public arraylist<string> videolist;     public customlistadapter adapter;     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         list =(listview)findviewbyid(r.id.list);         videolist = new arraylist<string>();         videolist.add("https://www.youtube.com/watch?v=zgfi7wngzle");         videolist.add("https://www.youtube.com/watch?v=zgfi7wngzle");         videolist.add("https://www.youtube.com/watch?v=zgfi7wngzle");         videolist.add("http://www.youtube.com/watch?v=ddlwpl53pvq#sthash.fw5etdfb.dpuf");         log.d("size of videolist:",""+ videolist.size());         adapter = new customlistadapter(mainactivity.this, videolist);         list.setadapter(adapter);     }     public class customlistadapter extends baseadapter {         private activity activity;         private layoutinflater inflater;         private arraylist<string> videolist;          public customlistadapter(activity activity, arraylist<string> videolist) {             this.activity = activity;             this.videolist = videolist;         }          @override         public int getcount() {             return videolist.size();         }          @override         public object getitem(int location) {             return videolist.get(location);         }          @override         public long getitemid(int position) {             return position;         }          @override         public view getview(int position, view convertview, viewgroup parent) {              if (inflater == null)                 inflater = (layoutinflater) activity                         .getsystemservice(context.layout_inflater_service);             if (convertview == null)                 convertview = inflater.inflate(r.layout.list_row, null);                videoview video = (videoview)convertview.findviewbyid(r.id.video_view);              video.setvideopath(videolist.get(position));              video.start();              return convertview;         }      }     } 

activity_main.xml

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context=".mainactivity" >      <listview         android:id="@+id/list"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:divider="@color/list_divider"         android:dividerheight="1dp"         android:listselector="@drawable/list_row_selector" />  </relativelayout> 

list_raw.xml

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:background="@drawable/list_row_selector"     android:padding="8dp" >      <!-- thumbnail image -->       <videoview         android:id="@+id/video_view"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_gravity="center" />   </relativelayout> 

i can't video , no error display in logcat thenb issue? added internet permission in manifest or permission or other settting required?

try setting videouri instead of videopath , check again,

videoview video = (videoview)convertview.findviewbyid(r.id.video_view); mediacontroller mediacontroller = new mediacontroller(this);  mediacontroller.setanchorview(video); video.setmediacontroller(mediacontroller); video.setvideouri(uri.parse(videolist.get(position))); video.start(); 

update: if planning use video's youtube best way using official youtube api. check here,

android youtube app play video intent

how play youtube video in android app


Comments