This is my 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 get video and no any error display in logcat thenb what is the issue? I added Internet permission in manifest is any or permission or any other settting is required?