I am making an app which has two activities ie MainActivity with a listview and second activity is a Video View.I use xml to populate listview and am successful I also stored video Url in a xml.What i need is I would like to play that videos from xml on VideoView when user click on corresponding listview list.How can i accomplish this?

有帮助吗?

解决方案

You are parse your data in XML format so obviously you have store your all data in HashMap Arraylist with particular key for your Video url.

Now, what can do, If you need to open Video on Item Click of ListView then you can retrieve your video url in String like

String  myUrl = urHashMaparraylist.get(position).get("videolocation");

Now pass this myUrl to next Activity and just set this String as a

 Uri video = Uri.parse(myUrl);
 videoView.setVideoURI(video);

EDIT:

  listView.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view,
            int position, long id) {

        String  myUrl = urHashMaparraylist.get(position).get("videolocation");
        Intent n = new Intent(YourActivityName.this , NewActivityName.class);
        n.putExtra("videolocation",myUrl);
        startActivity(n);

    }

});

Now in your next Activity retrieve it as a

Intent n = getIntent();
String url = n.getStringExtra("videolocation");

Now you can set this string to your VideoView as a

Uri video = Uri.parse(url);
videoView.setVideoURI(video);

其他提示

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top