Android 要实现这些ListActivity,请在url中显示视频

Android 要实现这些ListActivity,请在url中显示视频,android,video,android-intent,android-listview,Android,Video,Android Intent,Android Listview,我需要实现这些ListActivity.java ListActivity.java: package com.sit.fth.activity; public class ListActivity extends Activity { private ListView lv; private String[] groupArray = {"Category1", "Category2", "Category3"}; private String[][] childAr

我需要实现这些ListActivity.java

ListActivity.java:

package com.sit.fth.activity;

public class ListActivity extends Activity {
    private ListView lv;
    private String[] groupArray = {"Category1", "Category2", "Category3"};
    private String[][] childArray = {{"Test Greater glory Part-3","Greater glory Part-1"},
        {"What does","SundayService ( 19_01_14 )"}, {"Greater glory Part-3", "SundayService ( 19_01_14 )Tamil"}};

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.list1);
        lv = (ListView) findViewById(R.id.listview);

        String[] data = getIntent().getStringArrayExtra("strArray");
        AdapterView.OnItemClickListener clickListener = null;

        // If no data received means this is the first activity
        if (data == null) {
            data = groupArray;
            clickListener = new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
                    Intent intent = new Intent(ListActivity.this, ListActivity.class);
                    intent.putExtra("strArray", childArray[position]);
                    startActivity(intent);
                }
            };
        }

        ArrayAdapter adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, data);

        lv.setAdapter(adapter);
        lv.setTextFilterEnabled(true);
        lv.setOnItemClickListener(clickListener);

     }

}  
<?xml version="1.0" encoding="utf-8"?>
<resources>
 <string name="str_video">VIDEO</string>
<string name="api_host">URL Here</string>

</resources> 
package com.sit.fth.activity;

public class YoutubePlayActivity extends YouTubeFailureRecoveryActivity {
    public static final String DEVELOPER_KEY = "DEVELOPER_KEY_HERE";
    private String videoId;
    private YouTubePlayerView youTubeView;
    private ActionBar actionabar;
    private int position;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);

        setContentView(R.layout.youtube_play);

        position = getIntent().getExtras().getInt("position");

        Bundle bundle = getIntent().getExtras();
        videoId = bundle.getString("videoid");

        FrameLayout frameLayout = (FrameLayout) findViewById(R.id.youtube_view);
        youTubeView = new YouTubePlayerView(this);
        frameLayout.addView(youTubeView);
        youTubeView.initialize(DEVELOPER_KEY, this);

        ((TextView) findViewById(R.id.header_title)).setText(bundle
                .getString("title"));

        actionabar = getActionBar();
        //actionabar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionabar.setDisplayHomeAsUpEnabled(true);

    }

    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider,
            YouTubePlayer player, boolean wasRestored) {
        if (!wasRestored) {
            try {
                if (videoId != null) {
                    // 2GPfZYwYZoQ
                    player.cueVideo(videoId);
                } else {
                    Toast.makeText(getApplicationContext(),
                            "Not a Valid Youtube Video", Toast.LENGTH_SHORT)
                            .show();
                }
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(),
                        "Not a Valid Youtube Video", Toast.LENGTH_SHORT).show();
            }
        }
    }

    @Override
    protected YouTubePlayer.Provider getYouTubePlayerProvider() {
        return youTubeView;
    }
}
package com.example.youtubecatplayer;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
/**
 * Created by Simon on 2014 Jul 08.
 */
public class ListActivity extends Activity {
    // Categories must be pre-set
    private String[] data = {"Category1", "Category2", "Category3"};
    private final String JSONUrl = "http://tfhapp.fathershouse.in/api/video.php";
    private final String TAG_VIDEOS = "videos";
    private final String TAG_CAT = "video_category";
    private final String TAG_URL = "video_url";
    private final String TAG_TITLE = "video_title";

    private List<String> videoTitles = new ArrayList<String>();
    private List<String> videoURLs = new ArrayList<String>();
    private ArrayAdapter adapter;

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.list1);
        ListView listView = (ListView) findViewById(R.id.listview);

        Bundle extras = getIntent().getExtras();
        AdapterView.OnItemClickListener clickListener = null;

        // Category view:
        if (extras == null) {
            clickListener = new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
                    Intent intent = new Intent(ListActivity.this, ListActivity.class);
                    intent.putExtra("categoryName", data[position]);
                    startActivity(intent);
                }
            };
            adapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_1, data);
        }
        else { // Child view
            // Get the category of this child
            String categoryName = extras.getString("categoryName");
            if (categoryName == null)
                finish();

            // Populate list with videos of "categoryName", by looping JSON data
            new JSONParse(categoryName).execute();

            clickListener = new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
                    Intent intent = new Intent(ListActivity.this, YoutubeActivity.class);
                    // Send video url and title to YoutubeActivity
                    intent.putExtra("videoUrl", videoURLs.get(position));
                    intent.putExtra("videoTitle", videoTitles.get(position));
                    startActivity(intent);
                }
            };
            adapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_1, videoTitles);
        }

        listView.setAdapter(adapter);
        listView.setTextFilterEnabled(true);
        listView.setOnItemClickListener(clickListener);
    }

    private class JSONParse extends AsyncTask<String, String, JSONObject> {
        private ProgressDialog pDialog;
        private String categoryName;

        // Constructor // Get the categoryName of which videos will be found
        public JSONParse(String category) {
            this.categoryName = category;
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            // Create a loading dialog when getting the videos
            pDialog = new ProgressDialog(ListActivity.this);
            pDialog.setMessage("Getting Videos...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }
        @Override
        protected JSONObject doInBackground(String... args) {
            JSONParser jParser = new JSONParser();
            // Get JSON from URL
            JSONObject json = jParser.getJSONFromUrl(JSONUrl);
            if (json == null)
                return null;

            try {
                // Get video array
                JSONArray videos = json.getJSONArray(TAG_VIDEOS);

                // Loop all videos
                for (int i=0; i<videos.length(); i++) {
                    JSONObject video = videos.getJSONObject(i);
                    Log.e("JSON:", "cat: "+video.getString(TAG_CAT)+",title: "+video.getString(TAG_TITLE)+", url: "+video.getString(TAG_URL));
                    // Check if video belongs to "categoryName"
                    if (video.getString(TAG_CAT).equals(categoryName)) {
                        addVideo(video);
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return json;
        }

        private void addVideo(JSONObject video) {
            try {
                // Add title and URL to their respective arrays
                videoTitles.add(video.getString(TAG_TITLE));
                videoURLs.add(video.getString(TAG_URL));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        protected void onPostExecute(JSONObject json) {
            // Close the "loading" dialog
            pDialog.dismiss();
            if (json == null) {
                // Do something when there's no internet connection
                // Or there are no videos to be displayed
            }
            else // Let the adapter notify ListView that it has new items
                adapter.notifyDataSetChanged();
        }
    }
}
// Example JSON video item
// {"videoid":"59","video_type":"Youtube","language":"english","date":"08 Jul 2014",
// "video_title":"What does","video_category":"Category2","video_url":"P84FGn49b4A"},
package com.example.youtubecatplayer;

import android.app.ActionBar;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;
/**
 * Created by Simon on 2014 Jul 08.
 */
public class YoutubeActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener{
    public static final String DEVELOPER_KEY = "DEV_KEY";
    private String videoId;
    private ActionBar actionabar;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.youtube_activity);

        Bundle bundle = getIntent().getExtras();
        videoId = bundle.getString("videoUrl");
        this.setTitle(bundle.getString("videoTitle"));
        //((TextView) findViewById(R.id.videoTitle)).setText(bundle.getString("videoTitle"));

        YouTubePlayerView playerView = (YouTubePlayerView)findViewById(R.id.youtubeplayerview);
        playerView.initialize(DEVELOPER_KEY, this);

        actionabar = getActionBar();
        //actionabar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionabar.setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
                                        boolean wasRestored) {
        if (!wasRestored) {
            try {
                if (videoId != null) {
                    // 2GPfZYwYZoQ
                    player.cueVideo(videoId);
                } else {
                    Toast.makeText(getApplicationContext(),
                            "Not a Valid Youtube Video", Toast.LENGTH_SHORT)
                            .show();
                }
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(),
                        "Not a Valid Youtube Video", Toast.LENGTH_SHORT).show();
            }
        }
    }

    @Override
    public void onInitializationFailure(YouTubePlayer.Provider provider,
                                        YouTubeInitializationResult youTubeInitializationResult) {
    }
}
package com.example.youtubecatplayer;
/**
 * Created by Simon on 2014 Jul 08.
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.Charset;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;
public class JSONParser {
    public JSONParser() {
    }

    public JSONObject getJSONFromUrl(String url) {
        InputStream input = null;
        String jsonStr = null;
        JSONObject jsonObj = null;
        try {
            // Make the request
            input = new URL(url).openStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(input,
                    Charset.forName("UTF-8")));
            StringBuilder strBuilder = new StringBuilder();
            int ch;
            while ((ch = reader.read()) != -1)
                strBuilder.append((char) ch);

            input.close();
            jsonStr = strBuilder.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }
        // try parse the string to a JSON object
        try {
            jsonObj = new JSONObject(jsonStr);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }
        // return JSON String
        return jsonObj;
    }
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.simas.myapplication" >
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".ListActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".YoutubeActivity"
            android:label="@string/app_name" >
        </activity>

    </application>

</manifest>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <com.google.android.youtube.player.YouTubePlayerView
        android:id="@+id/youtubeplayerview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>
<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"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".ListActivity">

    <ListView
        android:id="@+id/listview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>
YouTubePlayActivity.java:

package com.sit.fth.activity;

public class ListActivity extends Activity {
    private ListView lv;
    private String[] groupArray = {"Category1", "Category2", "Category3"};
    private String[][] childArray = {{"Test Greater glory Part-3","Greater glory Part-1"},
        {"What does","SundayService ( 19_01_14 )"}, {"Greater glory Part-3", "SundayService ( 19_01_14 )Tamil"}};

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.list1);
        lv = (ListView) findViewById(R.id.listview);

        String[] data = getIntent().getStringArrayExtra("strArray");
        AdapterView.OnItemClickListener clickListener = null;

        // If no data received means this is the first activity
        if (data == null) {
            data = groupArray;
            clickListener = new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
                    Intent intent = new Intent(ListActivity.this, ListActivity.class);
                    intent.putExtra("strArray", childArray[position]);
                    startActivity(intent);
                }
            };
        }

        ArrayAdapter adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, data);

        lv.setAdapter(adapter);
        lv.setTextFilterEnabled(true);
        lv.setOnItemClickListener(clickListener);

     }

}  
<?xml version="1.0" encoding="utf-8"?>
<resources>
 <string name="str_video">VIDEO</string>
<string name="api_host">URL Here</string>

</resources> 
package com.sit.fth.activity;

public class YoutubePlayActivity extends YouTubeFailureRecoveryActivity {
    public static final String DEVELOPER_KEY = "DEVELOPER_KEY_HERE";
    private String videoId;
    private YouTubePlayerView youTubeView;
    private ActionBar actionabar;
    private int position;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);

        setContentView(R.layout.youtube_play);

        position = getIntent().getExtras().getInt("position");

        Bundle bundle = getIntent().getExtras();
        videoId = bundle.getString("videoid");

        FrameLayout frameLayout = (FrameLayout) findViewById(R.id.youtube_view);
        youTubeView = new YouTubePlayerView(this);
        frameLayout.addView(youTubeView);
        youTubeView.initialize(DEVELOPER_KEY, this);

        ((TextView) findViewById(R.id.header_title)).setText(bundle
                .getString("title"));

        actionabar = getActionBar();
        //actionabar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionabar.setDisplayHomeAsUpEnabled(true);

    }

    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider,
            YouTubePlayer player, boolean wasRestored) {
        if (!wasRestored) {
            try {
                if (videoId != null) {
                    // 2GPfZYwYZoQ
                    player.cueVideo(videoId);
                } else {
                    Toast.makeText(getApplicationContext(),
                            "Not a Valid Youtube Video", Toast.LENGTH_SHORT)
                            .show();
                }
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(),
                        "Not a Valid Youtube Video", Toast.LENGTH_SHORT).show();
            }
        }
    }

    @Override
    protected YouTubePlayer.Provider getYouTubePlayerProvider() {
        return youTubeView;
    }
}
package com.example.youtubecatplayer;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
/**
 * Created by Simon on 2014 Jul 08.
 */
public class ListActivity extends Activity {
    // Categories must be pre-set
    private String[] data = {"Category1", "Category2", "Category3"};
    private final String JSONUrl = "http://tfhapp.fathershouse.in/api/video.php";
    private final String TAG_VIDEOS = "videos";
    private final String TAG_CAT = "video_category";
    private final String TAG_URL = "video_url";
    private final String TAG_TITLE = "video_title";

    private List<String> videoTitles = new ArrayList<String>();
    private List<String> videoURLs = new ArrayList<String>();
    private ArrayAdapter adapter;

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.list1);
        ListView listView = (ListView) findViewById(R.id.listview);

        Bundle extras = getIntent().getExtras();
        AdapterView.OnItemClickListener clickListener = null;

        // Category view:
        if (extras == null) {
            clickListener = new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
                    Intent intent = new Intent(ListActivity.this, ListActivity.class);
                    intent.putExtra("categoryName", data[position]);
                    startActivity(intent);
                }
            };
            adapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_1, data);
        }
        else { // Child view
            // Get the category of this child
            String categoryName = extras.getString("categoryName");
            if (categoryName == null)
                finish();

            // Populate list with videos of "categoryName", by looping JSON data
            new JSONParse(categoryName).execute();

            clickListener = new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
                    Intent intent = new Intent(ListActivity.this, YoutubeActivity.class);
                    // Send video url and title to YoutubeActivity
                    intent.putExtra("videoUrl", videoURLs.get(position));
                    intent.putExtra("videoTitle", videoTitles.get(position));
                    startActivity(intent);
                }
            };
            adapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_1, videoTitles);
        }

        listView.setAdapter(adapter);
        listView.setTextFilterEnabled(true);
        listView.setOnItemClickListener(clickListener);
    }

    private class JSONParse extends AsyncTask<String, String, JSONObject> {
        private ProgressDialog pDialog;
        private String categoryName;

        // Constructor // Get the categoryName of which videos will be found
        public JSONParse(String category) {
            this.categoryName = category;
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            // Create a loading dialog when getting the videos
            pDialog = new ProgressDialog(ListActivity.this);
            pDialog.setMessage("Getting Videos...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }
        @Override
        protected JSONObject doInBackground(String... args) {
            JSONParser jParser = new JSONParser();
            // Get JSON from URL
            JSONObject json = jParser.getJSONFromUrl(JSONUrl);
            if (json == null)
                return null;

            try {
                // Get video array
                JSONArray videos = json.getJSONArray(TAG_VIDEOS);

                // Loop all videos
                for (int i=0; i<videos.length(); i++) {
                    JSONObject video = videos.getJSONObject(i);
                    Log.e("JSON:", "cat: "+video.getString(TAG_CAT)+",title: "+video.getString(TAG_TITLE)+", url: "+video.getString(TAG_URL));
                    // Check if video belongs to "categoryName"
                    if (video.getString(TAG_CAT).equals(categoryName)) {
                        addVideo(video);
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return json;
        }

        private void addVideo(JSONObject video) {
            try {
                // Add title and URL to their respective arrays
                videoTitles.add(video.getString(TAG_TITLE));
                videoURLs.add(video.getString(TAG_URL));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        protected void onPostExecute(JSONObject json) {
            // Close the "loading" dialog
            pDialog.dismiss();
            if (json == null) {
                // Do something when there's no internet connection
                // Or there are no videos to be displayed
            }
            else // Let the adapter notify ListView that it has new items
                adapter.notifyDataSetChanged();
        }
    }
}
// Example JSON video item
// {"videoid":"59","video_type":"Youtube","language":"english","date":"08 Jul 2014",
// "video_title":"What does","video_category":"Category2","video_url":"P84FGn49b4A"},
package com.example.youtubecatplayer;

import android.app.ActionBar;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;
/**
 * Created by Simon on 2014 Jul 08.
 */
public class YoutubeActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener{
    public static final String DEVELOPER_KEY = "DEV_KEY";
    private String videoId;
    private ActionBar actionabar;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.youtube_activity);

        Bundle bundle = getIntent().getExtras();
        videoId = bundle.getString("videoUrl");
        this.setTitle(bundle.getString("videoTitle"));
        //((TextView) findViewById(R.id.videoTitle)).setText(bundle.getString("videoTitle"));

        YouTubePlayerView playerView = (YouTubePlayerView)findViewById(R.id.youtubeplayerview);
        playerView.initialize(DEVELOPER_KEY, this);

        actionabar = getActionBar();
        //actionabar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionabar.setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
                                        boolean wasRestored) {
        if (!wasRestored) {
            try {
                if (videoId != null) {
                    // 2GPfZYwYZoQ
                    player.cueVideo(videoId);
                } else {
                    Toast.makeText(getApplicationContext(),
                            "Not a Valid Youtube Video", Toast.LENGTH_SHORT)
                            .show();
                }
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(),
                        "Not a Valid Youtube Video", Toast.LENGTH_SHORT).show();
            }
        }
    }

    @Override
    public void onInitializationFailure(YouTubePlayer.Provider provider,
                                        YouTubeInitializationResult youTubeInitializationResult) {
    }
}
package com.example.youtubecatplayer;
/**
 * Created by Simon on 2014 Jul 08.
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.Charset;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;
public class JSONParser {
    public JSONParser() {
    }

    public JSONObject getJSONFromUrl(String url) {
        InputStream input = null;
        String jsonStr = null;
        JSONObject jsonObj = null;
        try {
            // Make the request
            input = new URL(url).openStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(input,
                    Charset.forName("UTF-8")));
            StringBuilder strBuilder = new StringBuilder();
            int ch;
            while ((ch = reader.read()) != -1)
                strBuilder.append((char) ch);

            input.close();
            jsonStr = strBuilder.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }
        // try parse the string to a JSON object
        try {
            jsonObj = new JSONObject(jsonStr);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }
        // return JSON String
        return jsonObj;
    }
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.simas.myapplication" >
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".ListActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".YoutubeActivity"
            android:label="@string/app_name" >
        </activity>

    </application>

</manifest>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <com.google.android.youtube.player.YouTubePlayerView
        android:id="@+id/youtubeplayerview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>
<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"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".ListActivity">

    <ListView
        android:id="@+id/listview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>

我需要实现
ListActivity.java
类来获取url中显示的视频。

下面是一个列出类别(您提供的)的应用程序。单击某个类别后,它的视频将从
JSON
文件加载,并显示为另一个
ListView

当你点击一个视频时,它的
url和title
被发送到
YoutubeActivity
。YoutubeActivity然后用该视频启动播放器

我相信您想要更复杂的东西,但是您可以很容易地添加其他功能(例如从json获取附加字段)。如果您还想导入类别,则需要另一个json结构,例如
类别数组
->
视频数组

列表活动:

package com.sit.fth.activity;

public class ListActivity extends Activity {
    private ListView lv;
    private String[] groupArray = {"Category1", "Category2", "Category3"};
    private String[][] childArray = {{"Test Greater glory Part-3","Greater glory Part-1"},
        {"What does","SundayService ( 19_01_14 )"}, {"Greater glory Part-3", "SundayService ( 19_01_14 )Tamil"}};

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.list1);
        lv = (ListView) findViewById(R.id.listview);

        String[] data = getIntent().getStringArrayExtra("strArray");
        AdapterView.OnItemClickListener clickListener = null;

        // If no data received means this is the first activity
        if (data == null) {
            data = groupArray;
            clickListener = new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
                    Intent intent = new Intent(ListActivity.this, ListActivity.class);
                    intent.putExtra("strArray", childArray[position]);
                    startActivity(intent);
                }
            };
        }

        ArrayAdapter adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, data);

        lv.setAdapter(adapter);
        lv.setTextFilterEnabled(true);
        lv.setOnItemClickListener(clickListener);

     }

}  
<?xml version="1.0" encoding="utf-8"?>
<resources>
 <string name="str_video">VIDEO</string>
<string name="api_host">URL Here</string>

</resources> 
package com.sit.fth.activity;

public class YoutubePlayActivity extends YouTubeFailureRecoveryActivity {
    public static final String DEVELOPER_KEY = "DEVELOPER_KEY_HERE";
    private String videoId;
    private YouTubePlayerView youTubeView;
    private ActionBar actionabar;
    private int position;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);

        setContentView(R.layout.youtube_play);

        position = getIntent().getExtras().getInt("position");

        Bundle bundle = getIntent().getExtras();
        videoId = bundle.getString("videoid");

        FrameLayout frameLayout = (FrameLayout) findViewById(R.id.youtube_view);
        youTubeView = new YouTubePlayerView(this);
        frameLayout.addView(youTubeView);
        youTubeView.initialize(DEVELOPER_KEY, this);

        ((TextView) findViewById(R.id.header_title)).setText(bundle
                .getString("title"));

        actionabar = getActionBar();
        //actionabar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionabar.setDisplayHomeAsUpEnabled(true);

    }

    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider,
            YouTubePlayer player, boolean wasRestored) {
        if (!wasRestored) {
            try {
                if (videoId != null) {
                    // 2GPfZYwYZoQ
                    player.cueVideo(videoId);
                } else {
                    Toast.makeText(getApplicationContext(),
                            "Not a Valid Youtube Video", Toast.LENGTH_SHORT)
                            .show();
                }
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(),
                        "Not a Valid Youtube Video", Toast.LENGTH_SHORT).show();
            }
        }
    }

    @Override
    protected YouTubePlayer.Provider getYouTubePlayerProvider() {
        return youTubeView;
    }
}
package com.example.youtubecatplayer;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
/**
 * Created by Simon on 2014 Jul 08.
 */
public class ListActivity extends Activity {
    // Categories must be pre-set
    private String[] data = {"Category1", "Category2", "Category3"};
    private final String JSONUrl = "http://tfhapp.fathershouse.in/api/video.php";
    private final String TAG_VIDEOS = "videos";
    private final String TAG_CAT = "video_category";
    private final String TAG_URL = "video_url";
    private final String TAG_TITLE = "video_title";

    private List<String> videoTitles = new ArrayList<String>();
    private List<String> videoURLs = new ArrayList<String>();
    private ArrayAdapter adapter;

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.list1);
        ListView listView = (ListView) findViewById(R.id.listview);

        Bundle extras = getIntent().getExtras();
        AdapterView.OnItemClickListener clickListener = null;

        // Category view:
        if (extras == null) {
            clickListener = new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
                    Intent intent = new Intent(ListActivity.this, ListActivity.class);
                    intent.putExtra("categoryName", data[position]);
                    startActivity(intent);
                }
            };
            adapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_1, data);
        }
        else { // Child view
            // Get the category of this child
            String categoryName = extras.getString("categoryName");
            if (categoryName == null)
                finish();

            // Populate list with videos of "categoryName", by looping JSON data
            new JSONParse(categoryName).execute();

            clickListener = new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
                    Intent intent = new Intent(ListActivity.this, YoutubeActivity.class);
                    // Send video url and title to YoutubeActivity
                    intent.putExtra("videoUrl", videoURLs.get(position));
                    intent.putExtra("videoTitle", videoTitles.get(position));
                    startActivity(intent);
                }
            };
            adapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_1, videoTitles);
        }

        listView.setAdapter(adapter);
        listView.setTextFilterEnabled(true);
        listView.setOnItemClickListener(clickListener);
    }

    private class JSONParse extends AsyncTask<String, String, JSONObject> {
        private ProgressDialog pDialog;
        private String categoryName;

        // Constructor // Get the categoryName of which videos will be found
        public JSONParse(String category) {
            this.categoryName = category;
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            // Create a loading dialog when getting the videos
            pDialog = new ProgressDialog(ListActivity.this);
            pDialog.setMessage("Getting Videos...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }
        @Override
        protected JSONObject doInBackground(String... args) {
            JSONParser jParser = new JSONParser();
            // Get JSON from URL
            JSONObject json = jParser.getJSONFromUrl(JSONUrl);
            if (json == null)
                return null;

            try {
                // Get video array
                JSONArray videos = json.getJSONArray(TAG_VIDEOS);

                // Loop all videos
                for (int i=0; i<videos.length(); i++) {
                    JSONObject video = videos.getJSONObject(i);
                    Log.e("JSON:", "cat: "+video.getString(TAG_CAT)+",title: "+video.getString(TAG_TITLE)+", url: "+video.getString(TAG_URL));
                    // Check if video belongs to "categoryName"
                    if (video.getString(TAG_CAT).equals(categoryName)) {
                        addVideo(video);
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return json;
        }

        private void addVideo(JSONObject video) {
            try {
                // Add title and URL to their respective arrays
                videoTitles.add(video.getString(TAG_TITLE));
                videoURLs.add(video.getString(TAG_URL));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        protected void onPostExecute(JSONObject json) {
            // Close the "loading" dialog
            pDialog.dismiss();
            if (json == null) {
                // Do something when there's no internet connection
                // Or there are no videos to be displayed
            }
            else // Let the adapter notify ListView that it has new items
                adapter.notifyDataSetChanged();
        }
    }
}
// Example JSON video item
// {"videoid":"59","video_type":"Youtube","language":"english","date":"08 Jul 2014",
// "video_title":"What does","video_category":"Category2","video_url":"P84FGn49b4A"},
package com.example.youtubecatplayer;

import android.app.ActionBar;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;
/**
 * Created by Simon on 2014 Jul 08.
 */
public class YoutubeActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener{
    public static final String DEVELOPER_KEY = "DEV_KEY";
    private String videoId;
    private ActionBar actionabar;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.youtube_activity);

        Bundle bundle = getIntent().getExtras();
        videoId = bundle.getString("videoUrl");
        this.setTitle(bundle.getString("videoTitle"));
        //((TextView) findViewById(R.id.videoTitle)).setText(bundle.getString("videoTitle"));

        YouTubePlayerView playerView = (YouTubePlayerView)findViewById(R.id.youtubeplayerview);
        playerView.initialize(DEVELOPER_KEY, this);

        actionabar = getActionBar();
        //actionabar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionabar.setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
                                        boolean wasRestored) {
        if (!wasRestored) {
            try {
                if (videoId != null) {
                    // 2GPfZYwYZoQ
                    player.cueVideo(videoId);
                } else {
                    Toast.makeText(getApplicationContext(),
                            "Not a Valid Youtube Video", Toast.LENGTH_SHORT)
                            .show();
                }
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(),
                        "Not a Valid Youtube Video", Toast.LENGTH_SHORT).show();
            }
        }
    }

    @Override
    public void onInitializationFailure(YouTubePlayer.Provider provider,
                                        YouTubeInitializationResult youTubeInitializationResult) {
    }
}
package com.example.youtubecatplayer;
/**
 * Created by Simon on 2014 Jul 08.
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.Charset;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;
public class JSONParser {
    public JSONParser() {
    }

    public JSONObject getJSONFromUrl(String url) {
        InputStream input = null;
        String jsonStr = null;
        JSONObject jsonObj = null;
        try {
            // Make the request
            input = new URL(url).openStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(input,
                    Charset.forName("UTF-8")));
            StringBuilder strBuilder = new StringBuilder();
            int ch;
            while ((ch = reader.read()) != -1)
                strBuilder.append((char) ch);

            input.close();
            jsonStr = strBuilder.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }
        // try parse the string to a JSON object
        try {
            jsonObj = new JSONObject(jsonStr);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }
        // return JSON String
        return jsonObj;
    }
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.simas.myapplication" >
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".ListActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".YoutubeActivity"
            android:label="@string/app_name" >
        </activity>

    </application>

</manifest>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <com.google.android.youtube.player.YouTubePlayerView
        android:id="@+id/youtubeplayerview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>
<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"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".ListActivity">

    <ListView
        android:id="@+id/listview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>
JSONParser:

package com.sit.fth.activity;

public class ListActivity extends Activity {
    private ListView lv;
    private String[] groupArray = {"Category1", "Category2", "Category3"};
    private String[][] childArray = {{"Test Greater glory Part-3","Greater glory Part-1"},
        {"What does","SundayService ( 19_01_14 )"}, {"Greater glory Part-3", "SundayService ( 19_01_14 )Tamil"}};

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.list1);
        lv = (ListView) findViewById(R.id.listview);

        String[] data = getIntent().getStringArrayExtra("strArray");
        AdapterView.OnItemClickListener clickListener = null;

        // If no data received means this is the first activity
        if (data == null) {
            data = groupArray;
            clickListener = new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
                    Intent intent = new Intent(ListActivity.this, ListActivity.class);
                    intent.putExtra("strArray", childArray[position]);
                    startActivity(intent);
                }
            };
        }

        ArrayAdapter adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, data);

        lv.setAdapter(adapter);
        lv.setTextFilterEnabled(true);
        lv.setOnItemClickListener(clickListener);

     }

}  
<?xml version="1.0" encoding="utf-8"?>
<resources>
 <string name="str_video">VIDEO</string>
<string name="api_host">URL Here</string>

</resources> 
package com.sit.fth.activity;

public class YoutubePlayActivity extends YouTubeFailureRecoveryActivity {
    public static final String DEVELOPER_KEY = "DEVELOPER_KEY_HERE";
    private String videoId;
    private YouTubePlayerView youTubeView;
    private ActionBar actionabar;
    private int position;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);

        setContentView(R.layout.youtube_play);

        position = getIntent().getExtras().getInt("position");

        Bundle bundle = getIntent().getExtras();
        videoId = bundle.getString("videoid");

        FrameLayout frameLayout = (FrameLayout) findViewById(R.id.youtube_view);
        youTubeView = new YouTubePlayerView(this);
        frameLayout.addView(youTubeView);
        youTubeView.initialize(DEVELOPER_KEY, this);

        ((TextView) findViewById(R.id.header_title)).setText(bundle
                .getString("title"));

        actionabar = getActionBar();
        //actionabar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionabar.setDisplayHomeAsUpEnabled(true);

    }

    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider,
            YouTubePlayer player, boolean wasRestored) {
        if (!wasRestored) {
            try {
                if (videoId != null) {
                    // 2GPfZYwYZoQ
                    player.cueVideo(videoId);
                } else {
                    Toast.makeText(getApplicationContext(),
                            "Not a Valid Youtube Video", Toast.LENGTH_SHORT)
                            .show();
                }
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(),
                        "Not a Valid Youtube Video", Toast.LENGTH_SHORT).show();
            }
        }
    }

    @Override
    protected YouTubePlayer.Provider getYouTubePlayerProvider() {
        return youTubeView;
    }
}
package com.example.youtubecatplayer;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
/**
 * Created by Simon on 2014 Jul 08.
 */
public class ListActivity extends Activity {
    // Categories must be pre-set
    private String[] data = {"Category1", "Category2", "Category3"};
    private final String JSONUrl = "http://tfhapp.fathershouse.in/api/video.php";
    private final String TAG_VIDEOS = "videos";
    private final String TAG_CAT = "video_category";
    private final String TAG_URL = "video_url";
    private final String TAG_TITLE = "video_title";

    private List<String> videoTitles = new ArrayList<String>();
    private List<String> videoURLs = new ArrayList<String>();
    private ArrayAdapter adapter;

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.list1);
        ListView listView = (ListView) findViewById(R.id.listview);

        Bundle extras = getIntent().getExtras();
        AdapterView.OnItemClickListener clickListener = null;

        // Category view:
        if (extras == null) {
            clickListener = new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
                    Intent intent = new Intent(ListActivity.this, ListActivity.class);
                    intent.putExtra("categoryName", data[position]);
                    startActivity(intent);
                }
            };
            adapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_1, data);
        }
        else { // Child view
            // Get the category of this child
            String categoryName = extras.getString("categoryName");
            if (categoryName == null)
                finish();

            // Populate list with videos of "categoryName", by looping JSON data
            new JSONParse(categoryName).execute();

            clickListener = new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
                    Intent intent = new Intent(ListActivity.this, YoutubeActivity.class);
                    // Send video url and title to YoutubeActivity
                    intent.putExtra("videoUrl", videoURLs.get(position));
                    intent.putExtra("videoTitle", videoTitles.get(position));
                    startActivity(intent);
                }
            };
            adapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_1, videoTitles);
        }

        listView.setAdapter(adapter);
        listView.setTextFilterEnabled(true);
        listView.setOnItemClickListener(clickListener);
    }

    private class JSONParse extends AsyncTask<String, String, JSONObject> {
        private ProgressDialog pDialog;
        private String categoryName;

        // Constructor // Get the categoryName of which videos will be found
        public JSONParse(String category) {
            this.categoryName = category;
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            // Create a loading dialog when getting the videos
            pDialog = new ProgressDialog(ListActivity.this);
            pDialog.setMessage("Getting Videos...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }
        @Override
        protected JSONObject doInBackground(String... args) {
            JSONParser jParser = new JSONParser();
            // Get JSON from URL
            JSONObject json = jParser.getJSONFromUrl(JSONUrl);
            if (json == null)
                return null;

            try {
                // Get video array
                JSONArray videos = json.getJSONArray(TAG_VIDEOS);

                // Loop all videos
                for (int i=0; i<videos.length(); i++) {
                    JSONObject video = videos.getJSONObject(i);
                    Log.e("JSON:", "cat: "+video.getString(TAG_CAT)+",title: "+video.getString(TAG_TITLE)+", url: "+video.getString(TAG_URL));
                    // Check if video belongs to "categoryName"
                    if (video.getString(TAG_CAT).equals(categoryName)) {
                        addVideo(video);
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return json;
        }

        private void addVideo(JSONObject video) {
            try {
                // Add title and URL to their respective arrays
                videoTitles.add(video.getString(TAG_TITLE));
                videoURLs.add(video.getString(TAG_URL));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        protected void onPostExecute(JSONObject json) {
            // Close the "loading" dialog
            pDialog.dismiss();
            if (json == null) {
                // Do something when there's no internet connection
                // Or there are no videos to be displayed
            }
            else // Let the adapter notify ListView that it has new items
                adapter.notifyDataSetChanged();
        }
    }
}
// Example JSON video item
// {"videoid":"59","video_type":"Youtube","language":"english","date":"08 Jul 2014",
// "video_title":"What does","video_category":"Category2","video_url":"P84FGn49b4A"},
package com.example.youtubecatplayer;

import android.app.ActionBar;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;
/**
 * Created by Simon on 2014 Jul 08.
 */
public class YoutubeActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener{
    public static final String DEVELOPER_KEY = "DEV_KEY";
    private String videoId;
    private ActionBar actionabar;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.youtube_activity);

        Bundle bundle = getIntent().getExtras();
        videoId = bundle.getString("videoUrl");
        this.setTitle(bundle.getString("videoTitle"));
        //((TextView) findViewById(R.id.videoTitle)).setText(bundle.getString("videoTitle"));

        YouTubePlayerView playerView = (YouTubePlayerView)findViewById(R.id.youtubeplayerview);
        playerView.initialize(DEVELOPER_KEY, this);

        actionabar = getActionBar();
        //actionabar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionabar.setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
                                        boolean wasRestored) {
        if (!wasRestored) {
            try {
                if (videoId != null) {
                    // 2GPfZYwYZoQ
                    player.cueVideo(videoId);
                } else {
                    Toast.makeText(getApplicationContext(),
                            "Not a Valid Youtube Video", Toast.LENGTH_SHORT)
                            .show();
                }
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(),
                        "Not a Valid Youtube Video", Toast.LENGTH_SHORT).show();
            }
        }
    }

    @Override
    public void onInitializationFailure(YouTubePlayer.Provider provider,
                                        YouTubeInitializationResult youTubeInitializationResult) {
    }
}
package com.example.youtubecatplayer;
/**
 * Created by Simon on 2014 Jul 08.
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.Charset;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;
public class JSONParser {
    public JSONParser() {
    }

    public JSONObject getJSONFromUrl(String url) {
        InputStream input = null;
        String jsonStr = null;
        JSONObject jsonObj = null;
        try {
            // Make the request
            input = new URL(url).openStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(input,
                    Charset.forName("UTF-8")));
            StringBuilder strBuilder = new StringBuilder();
            int ch;
            while ((ch = reader.read()) != -1)
                strBuilder.append((char) ch);

            input.close();
            jsonStr = strBuilder.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }
        // try parse the string to a JSON object
        try {
            jsonObj = new JSONObject(jsonStr);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }
        // return JSON String
        return jsonObj;
    }
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.simas.myapplication" >
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".ListActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".YoutubeActivity"
            android:label="@string/app_name" >
        </activity>

    </application>

</manifest>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <com.google.android.youtube.player.YouTubePlayerView
        android:id="@+id/youtubeplayerview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>
<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"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".ListActivity">

    <ListView
        android:id="@+id/listview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>
注意:您的AndroidManifest.xml中需要internet权限:

<uses-permission android:name="android.permission.INTERNET" />
youtube\u activity.xml:

package com.sit.fth.activity;

public class ListActivity extends Activity {
    private ListView lv;
    private String[] groupArray = {"Category1", "Category2", "Category3"};
    private String[][] childArray = {{"Test Greater glory Part-3","Greater glory Part-1"},
        {"What does","SundayService ( 19_01_14 )"}, {"Greater glory Part-3", "SundayService ( 19_01_14 )Tamil"}};

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.list1);
        lv = (ListView) findViewById(R.id.listview);

        String[] data = getIntent().getStringArrayExtra("strArray");
        AdapterView.OnItemClickListener clickListener = null;

        // If no data received means this is the first activity
        if (data == null) {
            data = groupArray;
            clickListener = new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
                    Intent intent = new Intent(ListActivity.this, ListActivity.class);
                    intent.putExtra("strArray", childArray[position]);
                    startActivity(intent);
                }
            };
        }

        ArrayAdapter adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, data);

        lv.setAdapter(adapter);
        lv.setTextFilterEnabled(true);
        lv.setOnItemClickListener(clickListener);

     }

}  
<?xml version="1.0" encoding="utf-8"?>
<resources>
 <string name="str_video">VIDEO</string>
<string name="api_host">URL Here</string>

</resources> 
package com.sit.fth.activity;

public class YoutubePlayActivity extends YouTubeFailureRecoveryActivity {
    public static final String DEVELOPER_KEY = "DEVELOPER_KEY_HERE";
    private String videoId;
    private YouTubePlayerView youTubeView;
    private ActionBar actionabar;
    private int position;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);

        setContentView(R.layout.youtube_play);

        position = getIntent().getExtras().getInt("position");

        Bundle bundle = getIntent().getExtras();
        videoId = bundle.getString("videoid");

        FrameLayout frameLayout = (FrameLayout) findViewById(R.id.youtube_view);
        youTubeView = new YouTubePlayerView(this);
        frameLayout.addView(youTubeView);
        youTubeView.initialize(DEVELOPER_KEY, this);

        ((TextView) findViewById(R.id.header_title)).setText(bundle
                .getString("title"));

        actionabar = getActionBar();
        //actionabar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionabar.setDisplayHomeAsUpEnabled(true);

    }

    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider,
            YouTubePlayer player, boolean wasRestored) {
        if (!wasRestored) {
            try {
                if (videoId != null) {
                    // 2GPfZYwYZoQ
                    player.cueVideo(videoId);
                } else {
                    Toast.makeText(getApplicationContext(),
                            "Not a Valid Youtube Video", Toast.LENGTH_SHORT)
                            .show();
                }
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(),
                        "Not a Valid Youtube Video", Toast.LENGTH_SHORT).show();
            }
        }
    }

    @Override
    protected YouTubePlayer.Provider getYouTubePlayerProvider() {
        return youTubeView;
    }
}
package com.example.youtubecatplayer;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
/**
 * Created by Simon on 2014 Jul 08.
 */
public class ListActivity extends Activity {
    // Categories must be pre-set
    private String[] data = {"Category1", "Category2", "Category3"};
    private final String JSONUrl = "http://tfhapp.fathershouse.in/api/video.php";
    private final String TAG_VIDEOS = "videos";
    private final String TAG_CAT = "video_category";
    private final String TAG_URL = "video_url";
    private final String TAG_TITLE = "video_title";

    private List<String> videoTitles = new ArrayList<String>();
    private List<String> videoURLs = new ArrayList<String>();
    private ArrayAdapter adapter;

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.list1);
        ListView listView = (ListView) findViewById(R.id.listview);

        Bundle extras = getIntent().getExtras();
        AdapterView.OnItemClickListener clickListener = null;

        // Category view:
        if (extras == null) {
            clickListener = new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
                    Intent intent = new Intent(ListActivity.this, ListActivity.class);
                    intent.putExtra("categoryName", data[position]);
                    startActivity(intent);
                }
            };
            adapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_1, data);
        }
        else { // Child view
            // Get the category of this child
            String categoryName = extras.getString("categoryName");
            if (categoryName == null)
                finish();

            // Populate list with videos of "categoryName", by looping JSON data
            new JSONParse(categoryName).execute();

            clickListener = new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
                    Intent intent = new Intent(ListActivity.this, YoutubeActivity.class);
                    // Send video url and title to YoutubeActivity
                    intent.putExtra("videoUrl", videoURLs.get(position));
                    intent.putExtra("videoTitle", videoTitles.get(position));
                    startActivity(intent);
                }
            };
            adapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_1, videoTitles);
        }

        listView.setAdapter(adapter);
        listView.setTextFilterEnabled(true);
        listView.setOnItemClickListener(clickListener);
    }

    private class JSONParse extends AsyncTask<String, String, JSONObject> {
        private ProgressDialog pDialog;
        private String categoryName;

        // Constructor // Get the categoryName of which videos will be found
        public JSONParse(String category) {
            this.categoryName = category;
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            // Create a loading dialog when getting the videos
            pDialog = new ProgressDialog(ListActivity.this);
            pDialog.setMessage("Getting Videos...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }
        @Override
        protected JSONObject doInBackground(String... args) {
            JSONParser jParser = new JSONParser();
            // Get JSON from URL
            JSONObject json = jParser.getJSONFromUrl(JSONUrl);
            if (json == null)
                return null;

            try {
                // Get video array
                JSONArray videos = json.getJSONArray(TAG_VIDEOS);

                // Loop all videos
                for (int i=0; i<videos.length(); i++) {
                    JSONObject video = videos.getJSONObject(i);
                    Log.e("JSON:", "cat: "+video.getString(TAG_CAT)+",title: "+video.getString(TAG_TITLE)+", url: "+video.getString(TAG_URL));
                    // Check if video belongs to "categoryName"
                    if (video.getString(TAG_CAT).equals(categoryName)) {
                        addVideo(video);
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return json;
        }

        private void addVideo(JSONObject video) {
            try {
                // Add title and URL to their respective arrays
                videoTitles.add(video.getString(TAG_TITLE));
                videoURLs.add(video.getString(TAG_URL));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        protected void onPostExecute(JSONObject json) {
            // Close the "loading" dialog
            pDialog.dismiss();
            if (json == null) {
                // Do something when there's no internet connection
                // Or there are no videos to be displayed
            }
            else // Let the adapter notify ListView that it has new items
                adapter.notifyDataSetChanged();
        }
    }
}
// Example JSON video item
// {"videoid":"59","video_type":"Youtube","language":"english","date":"08 Jul 2014",
// "video_title":"What does","video_category":"Category2","video_url":"P84FGn49b4A"},
package com.example.youtubecatplayer;

import android.app.ActionBar;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;
/**
 * Created by Simon on 2014 Jul 08.
 */
public class YoutubeActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener{
    public static final String DEVELOPER_KEY = "DEV_KEY";
    private String videoId;
    private ActionBar actionabar;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.youtube_activity);

        Bundle bundle = getIntent().getExtras();
        videoId = bundle.getString("videoUrl");
        this.setTitle(bundle.getString("videoTitle"));
        //((TextView) findViewById(R.id.videoTitle)).setText(bundle.getString("videoTitle"));

        YouTubePlayerView playerView = (YouTubePlayerView)findViewById(R.id.youtubeplayerview);
        playerView.initialize(DEVELOPER_KEY, this);

        actionabar = getActionBar();
        //actionabar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionabar.setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
                                        boolean wasRestored) {
        if (!wasRestored) {
            try {
                if (videoId != null) {
                    // 2GPfZYwYZoQ
                    player.cueVideo(videoId);
                } else {
                    Toast.makeText(getApplicationContext(),
                            "Not a Valid Youtube Video", Toast.LENGTH_SHORT)
                            .show();
                }
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(),
                        "Not a Valid Youtube Video", Toast.LENGTH_SHORT).show();
            }
        }
    }

    @Override
    public void onInitializationFailure(YouTubePlayer.Provider provider,
                                        YouTubeInitializationResult youTubeInitializationResult) {
    }
}
package com.example.youtubecatplayer;
/**
 * Created by Simon on 2014 Jul 08.
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.Charset;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;
public class JSONParser {
    public JSONParser() {
    }

    public JSONObject getJSONFromUrl(String url) {
        InputStream input = null;
        String jsonStr = null;
        JSONObject jsonObj = null;
        try {
            // Make the request
            input = new URL(url).openStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(input,
                    Charset.forName("UTF-8")));
            StringBuilder strBuilder = new StringBuilder();
            int ch;
            while ((ch = reader.read()) != -1)
                strBuilder.append((char) ch);

            input.close();
            jsonStr = strBuilder.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }
        // try parse the string to a JSON object
        try {
            jsonObj = new JSONObject(jsonStr);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }
        // return JSON String
        return jsonObj;
    }
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.simas.myapplication" >
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".ListActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".YoutubeActivity"
            android:label="@string/app_name" >
        </activity>

    </application>

</manifest>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <com.google.android.youtube.player.YouTubePlayerView
        android:id="@+id/youtubeplayerview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>
<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"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".ListActivity">

    <ListView
        android:id="@+id/listview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>

list1.xml:

package com.sit.fth.activity;

public class ListActivity extends Activity {
    private ListView lv;
    private String[] groupArray = {"Category1", "Category2", "Category3"};
    private String[][] childArray = {{"Test Greater glory Part-3","Greater glory Part-1"},
        {"What does","SundayService ( 19_01_14 )"}, {"Greater glory Part-3", "SundayService ( 19_01_14 )Tamil"}};

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.list1);
        lv = (ListView) findViewById(R.id.listview);

        String[] data = getIntent().getStringArrayExtra("strArray");
        AdapterView.OnItemClickListener clickListener = null;

        // If no data received means this is the first activity
        if (data == null) {
            data = groupArray;
            clickListener = new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
                    Intent intent = new Intent(ListActivity.this, ListActivity.class);
                    intent.putExtra("strArray", childArray[position]);
                    startActivity(intent);
                }
            };
        }

        ArrayAdapter adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, data);

        lv.setAdapter(adapter);
        lv.setTextFilterEnabled(true);
        lv.setOnItemClickListener(clickListener);

     }

}  
<?xml version="1.0" encoding="utf-8"?>
<resources>
 <string name="str_video">VIDEO</string>
<string name="api_host">URL Here</string>

</resources> 
package com.sit.fth.activity;

public class YoutubePlayActivity extends YouTubeFailureRecoveryActivity {
    public static final String DEVELOPER_KEY = "DEVELOPER_KEY_HERE";
    private String videoId;
    private YouTubePlayerView youTubeView;
    private ActionBar actionabar;
    private int position;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);

        setContentView(R.layout.youtube_play);

        position = getIntent().getExtras().getInt("position");

        Bundle bundle = getIntent().getExtras();
        videoId = bundle.getString("videoid");

        FrameLayout frameLayout = (FrameLayout) findViewById(R.id.youtube_view);
        youTubeView = new YouTubePlayerView(this);
        frameLayout.addView(youTubeView);
        youTubeView.initialize(DEVELOPER_KEY, this);

        ((TextView) findViewById(R.id.header_title)).setText(bundle
                .getString("title"));

        actionabar = getActionBar();
        //actionabar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionabar.setDisplayHomeAsUpEnabled(true);

    }

    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider,
            YouTubePlayer player, boolean wasRestored) {
        if (!wasRestored) {
            try {
                if (videoId != null) {
                    // 2GPfZYwYZoQ
                    player.cueVideo(videoId);
                } else {
                    Toast.makeText(getApplicationContext(),
                            "Not a Valid Youtube Video", Toast.LENGTH_SHORT)
                            .show();
                }
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(),
                        "Not a Valid Youtube Video", Toast.LENGTH_SHORT).show();
            }
        }
    }

    @Override
    protected YouTubePlayer.Provider getYouTubePlayerProvider() {
        return youTubeView;
    }
}
package com.example.youtubecatplayer;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
/**
 * Created by Simon on 2014 Jul 08.
 */
public class ListActivity extends Activity {
    // Categories must be pre-set
    private String[] data = {"Category1", "Category2", "Category3"};
    private final String JSONUrl = "http://tfhapp.fathershouse.in/api/video.php";
    private final String TAG_VIDEOS = "videos";
    private final String TAG_CAT = "video_category";
    private final String TAG_URL = "video_url";
    private final String TAG_TITLE = "video_title";

    private List<String> videoTitles = new ArrayList<String>();
    private List<String> videoURLs = new ArrayList<String>();
    private ArrayAdapter adapter;

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.list1);
        ListView listView = (ListView) findViewById(R.id.listview);

        Bundle extras = getIntent().getExtras();
        AdapterView.OnItemClickListener clickListener = null;

        // Category view:
        if (extras == null) {
            clickListener = new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
                    Intent intent = new Intent(ListActivity.this, ListActivity.class);
                    intent.putExtra("categoryName", data[position]);
                    startActivity(intent);
                }
            };
            adapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_1, data);
        }
        else { // Child view
            // Get the category of this child
            String categoryName = extras.getString("categoryName");
            if (categoryName == null)
                finish();

            // Populate list with videos of "categoryName", by looping JSON data
            new JSONParse(categoryName).execute();

            clickListener = new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
                    Intent intent = new Intent(ListActivity.this, YoutubeActivity.class);
                    // Send video url and title to YoutubeActivity
                    intent.putExtra("videoUrl", videoURLs.get(position));
                    intent.putExtra("videoTitle", videoTitles.get(position));
                    startActivity(intent);
                }
            };
            adapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_1, videoTitles);
        }

        listView.setAdapter(adapter);
        listView.setTextFilterEnabled(true);
        listView.setOnItemClickListener(clickListener);
    }

    private class JSONParse extends AsyncTask<String, String, JSONObject> {
        private ProgressDialog pDialog;
        private String categoryName;

        // Constructor // Get the categoryName of which videos will be found
        public JSONParse(String category) {
            this.categoryName = category;
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            // Create a loading dialog when getting the videos
            pDialog = new ProgressDialog(ListActivity.this);
            pDialog.setMessage("Getting Videos...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }
        @Override
        protected JSONObject doInBackground(String... args) {
            JSONParser jParser = new JSONParser();
            // Get JSON from URL
            JSONObject json = jParser.getJSONFromUrl(JSONUrl);
            if (json == null)
                return null;

            try {
                // Get video array
                JSONArray videos = json.getJSONArray(TAG_VIDEOS);

                // Loop all videos
                for (int i=0; i<videos.length(); i++) {
                    JSONObject video = videos.getJSONObject(i);
                    Log.e("JSON:", "cat: "+video.getString(TAG_CAT)+",title: "+video.getString(TAG_TITLE)+", url: "+video.getString(TAG_URL));
                    // Check if video belongs to "categoryName"
                    if (video.getString(TAG_CAT).equals(categoryName)) {
                        addVideo(video);
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return json;
        }

        private void addVideo(JSONObject video) {
            try {
                // Add title and URL to their respective arrays
                videoTitles.add(video.getString(TAG_TITLE));
                videoURLs.add(video.getString(TAG_URL));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        protected void onPostExecute(JSONObject json) {
            // Close the "loading" dialog
            pDialog.dismiss();
            if (json == null) {
                // Do something when there's no internet connection
                // Or there are no videos to be displayed
            }
            else // Let the adapter notify ListView that it has new items
                adapter.notifyDataSetChanged();
        }
    }
}
// Example JSON video item
// {"videoid":"59","video_type":"Youtube","language":"english","date":"08 Jul 2014",
// "video_title":"What does","video_category":"Category2","video_url":"P84FGn49b4A"},
package com.example.youtubecatplayer;

import android.app.ActionBar;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;
/**
 * Created by Simon on 2014 Jul 08.
 */
public class YoutubeActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener{
    public static final String DEVELOPER_KEY = "DEV_KEY";
    private String videoId;
    private ActionBar actionabar;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.youtube_activity);

        Bundle bundle = getIntent().getExtras();
        videoId = bundle.getString("videoUrl");
        this.setTitle(bundle.getString("videoTitle"));
        //((TextView) findViewById(R.id.videoTitle)).setText(bundle.getString("videoTitle"));

        YouTubePlayerView playerView = (YouTubePlayerView)findViewById(R.id.youtubeplayerview);
        playerView.initialize(DEVELOPER_KEY, this);

        actionabar = getActionBar();
        //actionabar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionabar.setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
                                        boolean wasRestored) {
        if (!wasRestored) {
            try {
                if (videoId != null) {
                    // 2GPfZYwYZoQ
                    player.cueVideo(videoId);
                } else {
                    Toast.makeText(getApplicationContext(),
                            "Not a Valid Youtube Video", Toast.LENGTH_SHORT)
                            .show();
                }
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(),
                        "Not a Valid Youtube Video", Toast.LENGTH_SHORT).show();
            }
        }
    }

    @Override
    public void onInitializationFailure(YouTubePlayer.Provider provider,
                                        YouTubeInitializationResult youTubeInitializationResult) {
    }
}
package com.example.youtubecatplayer;
/**
 * Created by Simon on 2014 Jul 08.
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.Charset;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;
public class JSONParser {
    public JSONParser() {
    }

    public JSONObject getJSONFromUrl(String url) {
        InputStream input = null;
        String jsonStr = null;
        JSONObject jsonObj = null;
        try {
            // Make the request
            input = new URL(url).openStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(input,
                    Charset.forName("UTF-8")));
            StringBuilder strBuilder = new StringBuilder();
            int ch;
            while ((ch = reader.read()) != -1)
                strBuilder.append((char) ch);

            input.close();
            jsonStr = strBuilder.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }
        // try parse the string to a JSON object
        try {
            jsonObj = new JSONObject(jsonStr);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }
        // return JSON String
        return jsonObj;
    }
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.simas.myapplication" >
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".ListActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".YoutubeActivity"
            android:label="@string/app_name" >
        </activity>

    </application>

</manifest>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <com.google.android.youtube.player.YouTubePlayerView
        android:id="@+id/youtubeplayerview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>
<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"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".ListActivity">

    <ListView
        android:id="@+id/listview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>


不要忘记更改开发人员密钥,否则您将看到播放器初始化问题。

问题出在哪里?如何展示?它不会启动吗?如果我在listView中单击该
测试Greater Glory part-3
,它将无法从json?@Marcacierno读取值。视频必须从这些同名的php链接加载
测试Greater Glory part-3
。因此,当用户选择类别时,clickListener将为空,你不知道如何从这里实现其他东西?@Marcacierno是的,我没有主意。我是一个android初学者。这就是为什么我为这些设置了奖金。我理解这一点:用户加入活动1,其中显示所有类别,然后在点击类别后,它将打开视频列表(在应用程序内部编码,而不是来自json)它在视频中单击,因此您应该打开YouTubePlay活动并播放视频,对吗?当使用视频类时?我将从Implemental Parcelable to video开始,并将此对象传递给YoutubePlayActivity,该活动将具有所需的所有信息。然后,可以使用第二个适配器来代替它,以便我们知道要复制哪个对象在我实现您的代码之前,请转到活动。我通常会获取视频。首先,我没有获取ListView。这是我的问题。没有更多的视频片段,我跳过了它。ListActivity显示类别,单击一次视频,然后单击一次转到YouTube播放活动以显示视频。加入并解释您的问题进一步。我尝试了很多方法来回答你的问题,但都没有显示ListView。输出在“视频”选项卡中显示一个空白屏幕。@Stephen我更新了我的答案,重新测试并确认它有效。Simon,我很高兴。你帮助了我。而且你是一个好人。冷静点,为我写更多代码。没有任何语言可以表达。