0

I am working with JSON. I want to display the video link and its image and its description from Json file in custom listview and when this Video link is clicked it should play a video. [the videos are stored in Server and its link are given in JSON file].

I am able to get the image and description from JSON file but got stuck in Getting Video link. Can you please help me out in this. I searched a lot on this on Google but failed to get information on videos to get from JSON file. but there are lot of examples on getting video's from YouTube.

Should we write any extra code to get video from jSON As we write image loader to get images! If so Can anybody share what i can do and how to display and play.

Thanks a lot in advance.

My SingleItem view:

 public class SingleItemView extends Activity{
     // Declare Variables

   ImageLoader imageLoader = new ImageLoader(this);

   @Override
   public void onCreate(Bundle savedInstanceState) {
      // Capture position and set results to the ImageView
       // Passes  images URL into ImageLoader.class
       imageLoader.DisplayImage(imageLocation, imgflag);

}

}

My Base adapter:

     // Capture ListView item click
     itemView.setOnClickListener(new OnClickListener() {

     @Override
    public void onClick(View arg0) {
     // Get the position
    resultp = data.get(position);
  Intent intent = new Intent(context, SingleItemView.class);


 // Start SingleItemView Class
 context.startActivity(intent);

    }
 });
  return itemView;
Sankar V
  • 4,794
  • 3
  • 38
  • 56
user2028018
  • 5
  • 2
  • 5
  • show your code and json data. – Piyush Mar 07 '14 at 05:35
  • Hi Piyush, There are no error in my code and Json File. I am able to Display Images and its discription perfectly without any prb but not video. Can you please tell me the steps to follow or any link to refer to get the video. Thanks – user2028018 Mar 07 '14 at 06:15
  • Want to play in youtube player or VideoView? – Piyush Mar 07 '14 at 06:18
  • VideoView only ... Can we take the files from Json and play in Video View ? Actually my client have there videos in there server not in Youtube and they will be adding more videos lateron – user2028018 Mar 07 '14 at 06:19
  • Refer this http://androidcodeexamples.blogspot.in/2011/08/how-to-play-mp4-video-in-android-using.html ,http://stackoverflow.com/questions/11195238/video-from-url-in-videoview, http://stackoverflow.com/questions/2620049/how-to-play-video-from-url – Piyush Mar 07 '14 at 06:22
  • Thanks Piyush, But i have more videos in that Json File which link i have to give in String link = ""..... i am getting confused. – user2028018 Mar 07 '14 at 06:27

1 Answers1

0

You are parse your data in JSON 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(myUrl);
  videoView.setVideoURI(video);
Piyush
  • 18,895
  • 5
  • 32
  • 63
  • Here KeyOfVideoUrlHere means Json Url ? and if i am not wrong i have to pass setOnClickListener(new OnClickListener()) in base adapter class? sorry .. please help me as we pass for images and also i already passed for images... – user2028018 Mar 07 '14 at 06:39
  • you have to show me something so i can help you properly otherwise how can i do? – Piyush Mar 07 '14 at 06:51
  • Sorry i uploaded now ... can you guide me now – user2028018 Mar 07 '14 at 06:56
  • it contains aaa : videolocation: " http....." Imagelocation: "http..."Description:..." for 4 times means 4 files but they will be updating more later On ... Actually Json File is confidential ... can't sare....Sorry – user2028018 Mar 07 '14 at 07:01
  • Thanks... But which Video location as i told you there are currently 4 files and they will be adding more later on – user2028018 Mar 07 '14 at 07:05
  • Ya..thats not problem is so many video url can be added from server it will be displayed perfectly. – Piyush Mar 07 '14 at 07:06
  • Yeh i have given my Json plese chek and also can you please tell me where to add Onclick and pass the function – user2028018 Mar 07 '14 at 07:10
  • @user2028018 Wel come.. Glad to help you!! – Piyush Mar 07 '14 at 07:18
  • If i click on the image then the application is getting closed :( I don't want to do anything with tat image. How to come across it. – user2028018 Mar 08 '14 at 00:12