I am using the new Youtube API for Android. I managed to use the API to display a specific playlist (using a ListView), and after clicking on a video in the list, I can play that specific video.
My question is that. How can I get information about a specific video? Information such as the name of the video and the number of views. I tried searching on YoutubeThumbnailView / loader, YoutubePlayerView, YoutubePlayer, but no luck.
here is the code for the main activity, let me know if you need more information.
Any help would be greatly appreciated.
public class MainActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener, YouTubeThumbnailView.OnInitializedListener{ private final static String PLAY_LIST_ID = "XXX"; private final static String DEV_KEY = "XXX"; private YouTubeThumbnailView thumbnailView; private YouTubeThumbnailLoader loader; private ArrayList<HashMap<String, YouTubeVideo>> arrayList; private ListView listView; private SpecialAdapter adapter; private int counter; private YouTubePlayerView playerView; private YouTubePlayer player; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String[] keys = new String[]{"key"}; int[] values = new int[]{R.id.imageView1}; arrayList = new ArrayList<HashMap<String, YouTubeVideo>>(); setContentView(R.layout.activity_main); listView = (ListView)findViewById(R.id.listView1); listView.setOnItemClickListener(new onListClickListener()); playerView = (YouTubePlayerView)findViewById(R.id.player); thumbnailView = new YouTubeThumbnailView(this); thumbnailView.initialize(DEV_KEY, this); playerView.initialize(DEV_KEY, this); adapter = new SpecialAdapter(this, arrayList, R.layout.row_layout, keys, values); } class onListClickListener implements OnItemClickListener{ @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { playerView.setVisibility(View.VISIBLE); player.cueVideo(arrayList.get(arg2).get("key").videoID); } } @Override public void onInitializationSuccess(YouTubeThumbnailView arg0, YouTubeThumbnailLoader arg1) { loader = arg1; loader.setPlaylist(PLAY_LIST_ID); loader.setOnThumbnailLoadedListener(new OnThumbnailLoadedListener() { @Override public void onThumbnailLoaded(YouTubeThumbnailView arg0, String videoId) { HashMap<String, YouTubeVideo> map; ImageView imageView; if(loader.hasNext()){ map = new HashMap<String, YouTubeVideo>(); imageView = new ImageView(MainActivity.this); imageView.setImageDrawable(arg0.getDrawable()); map.put("key", new YouTubeVideo(imageView, videoId)); arrayList.add(map); loader.next(); }else { map = new HashMap<String, YouTubeVideo>(); imageView = new ImageView(MainActivity.this); imageView.setImageDrawable(arg0.getDrawable()); map.put("key", new YouTubeVideo(imageView, videoId)); arrayList.add(map); listView.setAdapter(adapter); } } @Override public void onThumbnailError(YouTubeThumbnailView arg0, ErrorReason arg1) { } }); } @Override public void onInitializationFailure(YouTubeThumbnailView arg0, YouTubeInitializationResult arg1) { } @Override public boolean onCreateOptionsMenu(Menu menu) {
}
source share