Hello,I'm new to here.. I've created a simple app using YouTube API it contains a collections of list item if any one touch the list item then it'll redirect you into youtube for particular video.Now the thing is I want to add youtube thumbnail with list item of list view. Is there any way to add image there ? Please any one shed some light on this question ?
Activity Main xml
="1.0"="utf-8"
<LinearLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.vinothvino.shortfilmy.MainActivity">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listView"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
<com.google.android.youtube.player.YouTubeThumbnailView
android:id="@+id/youtube_thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp">
</com.google.android.youtube.player.YouTubeThumbnailView>
</LinearLayout>
YouTubeView xml
="1.0"="utf-8"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".YouTubeView">
<com.google.android.youtube.player.YouTubeThumbnailView
android:id="@+id/youtube_thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp">
</com.google.android.youtube.player.YouTubeThumbnailView>
<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/youtube_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
ListView
="1.0"="utf-8"
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listviewadapter"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="25dip"
android:textSize="16dip"
android:textStyle="bold" >
</TextView>
MainActivity
package com.example.vinothvino.shortfilmy;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity {
ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] shortFilms = {"Mudhal Kanave","A Cute Love story","Ennai Saaithaale","Friend ah Figure ah",
"Perfect You","Aparam","Yaaro Ivan","Honey Money Romantic Thriller"};
listView = (ListView) findViewById(R.id.listView);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.list_view,shortFilms);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
int itemPos = position;
String itemVal = (String)listView.getItemAtPosition(itemPos);
switch (itemPos){
case 0:
Intent i = new Intent(getApplicationContext(),YouTubeView.class);
i.putExtra("value1","rk7NYXql2dc");
startActivity(i);
Toast.makeText(getApplicationContext(),itemVal,Toast.LENGTH_SHORT).show();
break;
case 1:
Intent i1 = new Intent(getApplicationContext(),YouTubeView.class);
i1.putExtra("value1", "j1lc8p8NFNw");
startActivity(i1);
Toast.makeText(getApplicationContext(),itemVal,Toast.LENGTH_SHORT).show();
break;
case 2:
Intent i2 = new Intent(getApplicationContext(),YouTubeView.class);
i2.putExtra("value1","8au0FflDO-I");
startActivity(i2);
Toast.makeText(getApplicationContext(),itemVal,Toast.LENGTH_SHORT).show();
break;
case 3:
Intent i3 = new Intent(getApplicationContext(),YouTubeView.class);
i3.putExtra("value1","9daIXm6lSTc");
startActivity(i3);
Toast.makeText(getApplicationContext(),itemVal,Toast.LENGTH_SHORT).show();
break;
case 4:
Intent i4 = new Intent(getApplicationContext(),YouTubeView.class);
i4.putExtra("value1","s3s838owcOY");
startActivity(i4);
Toast.makeText(getApplicationContext(),itemVal,Toast.LENGTH_SHORT).show();
break;
case 5:
Intent i5 = new Intent(getApplicationContext(),YouTubeView.class);
i5.putExtra("value1","RIMsCCMy80E");
startActivity(i5);
Toast.makeText(getApplicationContext(),itemVal,Toast.LENGTH_SHORT).show();
break;
case 6:
Intent i6 = new Intent(getApplicationContext(),YouTubeView.class);
i6.putExtra("value1","LE5M3YYe_cE");
startActivity(i6);
Toast.makeText(getApplicationContext(),itemVal,Toast.LENGTH_SHORT).show();
break;
case 7:
Intent i7 = new Intent(getApplicationContext(),YouTubeView.class);
i7.putExtra("value1","yjpQ4qVd7Os");
startActivity(i7);
Toast.makeText(getApplicationContext(),itemVal,Toast.LENGTH_SHORT).show();
break;
default:
Toast.makeText(getApplicationContext(),"Sorry!!! There is no video",Toast.LENGTH_SHORT).show();
}
}
});
}
}
YouTubeView
package com.example.vinothvino.shortfilmy;
import android.os.Bundle;
import android.content.Intent;
import android.widget.Toast;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;
import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubePlayer.Provider;
import com.google.android.youtube.player.YouTubePlayer.PlaybackEventListener;
import com.google.android.youtube.player.YouTubePlayer.PlayerStateChangeListener;
import com.google.android.youtube.player.YouTubeThumbnailLoader;
import com.google.android.youtube.player.YouTubeThumbnailView;
import com.google.android.youtube.player.YouTubeThumbnailLoader.ErrorReason;
public class YouTubeView extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener{
public static final int RECOVER_REQUEST = 1;
private YouTubePlayerView youTubeView;
private YouTubeThumbnailView youTubeThumbnailView;
private YouTubeThumbnailLoader youTubeThumbnailLoader;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.youtube_view);
youTubeView = (YouTubePlayerView)findViewById(R.id.youtube_view);
youTubeView.initialize(Config.API_KEY,this);
}
public void onInitializationSuccess(Provider provider,YouTubePlayer player,boolean wasRestored) {
Bundle videoIdFromMainActiviy = getIntent().getExtras();
String videoID = videoIdFromMainActiviy.getString("value1");
player.setPlaybackEventListener(myPlaybackEvent);
player.setPlayerStateChangeListener(myPlayerState);
if (!wasRestored) {
player.cueVideo(videoID);
}
}
private PlaybackEventListener myPlaybackEvent = new PlaybackEventListener() {
@Override
public void onPlaying() {
Toast.makeText(getApplicationContext(),"Playing...",Toast.LENGTH_SHORT).show();
}
@Override
public void onPaused() {
Toast.makeText(getApplicationContext(),"Paused...",Toast.LENGTH_SHORT).show();
}
@Override
public void onStopped() {
Toast.makeText(getApplicationContext(),"Stopped...",Toast.LENGTH_SHORT).show();
}
@Override
public void onBuffering(boolean b) {
}
@Override
public void onSeekTo(int i) {
}
};
private PlayerStateChangeListener myPlayerState = new PlayerStateChangeListener() {
@Override
public void onLoading() {
Toast.makeText(getApplicationContext(),"Please be patient... ",Toast.LENGTH_SHORT).show();
}
@Override
public void onLoaded(String s) {
}
@Override
public void onAdStarted() {
Toast.makeText(getApplicationContext(),"Ayyayooo Add vandhuteyyy",Toast.LENGTH_LONG).show();
}
@Override
public void onVideoStarted() {
Toast.makeText(getApplicationContext(),"Video started",Toast.LENGTH_LONG).show();
}
@Override
public void onVideoEnded() {
Toast.makeText(getApplicationContext(),"See some other videos",Toast.LENGTH_LONG).show();
}
@Override
public void onError(YouTubePlayer.ErrorReason errorReason) {
}
};
public void onInitializationFailure(Provider provider,YouTubeInitializationResult errorReason){
if (errorReason.isUserRecoverableError()){
errorReason.getErrorDialog(this,RECOVER_REQUEST).show();
}else {
String error = String.format(getString(R.string.error), errorReason.toString());
Toast.makeText(this,error,Toast.LENGTH_LONG).show();
}
}
protected void onActivityResult(int requestcode, int resultcode, Intent data){
if (requestcode==RECOVER_REQUEST){
getYoutubePlayerProvider().initialize(Config.API_KEY,this);
}
}
protected Provider getYoutubePlayerProvider(){
return youTubeView;
}
}
Please help me.. Thanks in advanced
|