Comment faire pour lire la Vidéo Dans une ListView dans Android
Je veux lire une vidéo dans mon application. J'ai créé un custom ListView
avec VideoView
. Le VideoView
affiche correctement mais le problème est que quand je suis en déplacement affichage de la liste VideoView
changé sa position. Ce n'est pas en regardant bien dans mon application. Mon exigence est que quand on clique sur button
vidéo devrait commencer joué dans cette zone de liste afficher uniquement. Comment pourrais-je y parvenir?
Voici le code de l'affichage VideoView
dans ListView
:
public class MyVideoAdapter extends BaseAdapter {
Context context;
String a[];
LayoutInflater inflate;
VideoView vv;
ImageButton img;
public MyVideoAdapter(Context context, String[] a) {
this.context = context;
this.a = a;
inflate = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return a.length;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (convertView == null)
v = inflate.inflate(R.layout.row, null);
img = (ImageButton) v.findViewById(R.id.imageButton1);
String ans = a[position];
if (ans.equals("one")) {
vv = (VideoView) v.findViewById(R.id.VideoView);
MediaController mc = new MediaController(context);
mc.setAnchorView(vv);
mc.setMediaPlayer(vv);
//Uri uri=Uri.parse("https://www.dropbox.com/s/d5blvemu8yse38s/kesari.mp4");
//vv.setMediaController(mc);
String path = "android.resource://com.example.wealthcreation/raw/kesari";
vv.setVideoURI(Uri.parse(path));
img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TODO Auto-generated method stub
img.setVisibility(View.INVISIBLE);
vv.start();
}
});
//img.setImageResource(R.drawable.k1);
//ImageButton img=(ImageButton)v.findViewById(R.id.imageButton1);
//Button btn1=(Button)v.findViewById(R.id.btnplay);
/*
img.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
vv.setVisibility(View.VISIBLE);
img.setVisibility(View.GONE);
MediaController mc = new MediaController(context);
mc.setAnchorView(vv);
mc.setMediaPlayer(vv);
//Uri uri=Uri.parse("https://www.dropbox.com/s/d5blvemu8yse38s/kesari.mp4");
vv.setMediaController(mc);
String path = "android.resource://com.example.wealthcreation/raw/kesari";
vv.setVideoURI(Uri.parse(path));
vv.start();
String videoId = "CUuBdtsQx6U";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:"
+ videoId));
intent.putExtra("VIDEO_ID", videoId);
context.startActivity(intent);
//Toast.makeText(context, "Hii",Toast.LENGTH_LONG).show();
//this intent define an action and and parse the url
//context.startActivity(new
//Intent(Intent.ACTION_VIEW,Uri.parse("http://www.youtube.com/watch?v=CUuBdtsQx6U")));
/*
WebView webview = new WebView(context);
String htmlString = "<html> <body> <embed src=\"youtube link\"; type=application/x-shockwave-flash width="
+ widthOfDevice
+ " height="
+ heightOfDevice
+ "> </embed> </body> </html>";
webview.loadData(htmlString, "text/html", "UTF-8");
try
{
MediaPlayer mp = new MediaPlayer();
mp.setDataSource("http://www.youtube.com/watch?v=CUuBdtsQx6U");
mp.prepare();
mp.start();
}
catch (Exception e)
{
Log.d("videos", "", e);
}
}
});
*/
}
if (ans.equals("two"))
{
/*
img.setImageResource(R.drawable.k2);
Button btn2 = (Button) v.findViewById(R.id.btnplay);
btn2.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Toast.makeText(context, "Hii", Toast.LENGTH_LONG).show();
//context.startActivity(new
//Intent(Intent.ACTION_VIEW,Uri.parse("http://www.youtube.com/watch?v=f6fmZFDE5EA")));
//this intent define an action and and parse the url
//context.startActivity(new
//Intent(Intent.ACTION_VIEW,Uri.parse("http://www.youtube.com/watch?v=CUuBdtsQx6U")));
String videoId = "f6fmZFDE5EA";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:"
+ videoId));
intent.putExtra("VIDEO_ID", videoId);
context.startActivity(intent);
//context.startActivity(new
//Intent(Intent.ACTION_VIEW,Uri.parse("http://www.youtube.com/watch?feature=player_detailpage&v=f6fmZFDE5EA")));
}
});
*/
}
if (ans.equals("three"))
{
/*
Button btn3 = (Button) v.findViewById(R.id.btnplay);
btn3.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
String videoId = "f6fmZFDE5EA";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:"
+ videoId));
intent.putExtra("VIDEO_ID", videoId);
context.startActivity(intent);
//Toast.makeText(context, "three",Toast.LENGTH_LONG).show();
//context.startActivity(new
//Intent(Intent.ACTION_VIEW,Uri.parse("http://www.youtube.com/watch?v=f6fmZFDE5EA")));
//this intent define an action and and parse the url
//context.startActivity(new
//Intent(Intent.ACTION_VIEW,Uri.parse("http://www.youtube.com/watch?v=CUuBdtsQx6U")));
}
});
*/
}
if (ans.equals("four"))
{
/*
img.setImageResource(R.drawable.k4);
Button btn4 = (Button) v.findViewById(R.id.btnplay);
btn4.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
String videoId = "VBMuzOrVD18";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:"
+ videoId));
intent.putExtra("VIDEO_ID", videoId);
context.startActivity(intent);
//Toast.makeText(context, "four",Toast.LENGTH_LONG).show();
//context.startActivity(new
//Intent(Intent.ACTION_VIEW,Uri.parse("http://www.youtube.com/watch?v=VBMuzOrVD18")));
//this intent define an action and and parse the url
//context.startActivity(new
//Intent(Intent.ACTION_VIEW,Uri.parse("http://www.youtube.com/watch?v=CUuBdtsQx6U")));
}
});
*/
}
if (ans.equals("fifth"))
{
/*
img.setImageResource(R.drawable.k5);
Button btn5 = (Button) v.findViewById(R.id.btnplay);
btn5.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
String videoId = "-UlSAYhHqqc";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:"
+ videoId));
intent.putExtra("VIDEO_ID", videoId);
context.startActivity(intent);
//Toast.makeText(context, "fith",Toast.LENGTH_LONG).show();
//context.startActivity(new
//Intent(Intent.ACTION_VIEW,Uri.parse("http://www.youtube.com/watch?v=-UlSAYhHqqc")));
//this intent define an action and and parse the url
//context.startActivity(new
//Intent(Intent.ACTION_VIEW,Uri.parse("http://www.youtube.com/watch?v=CUuBdtsQx6U")));
}
});
*/
}
return v;
}
}
- Vérifier la vue de son recyclage. Vous avez déjà fait des choses de base, ce lien va vous aider android.amberfog.com/?p=296 . Assurez-vous également d'utiliser un titulaire de modèle.
- svp quelqu'un peut m'aider à résoudre mes problèmes
- Utilisation TextureView pour lire la vidéo dans une ListView au lieu SurfaceView.
- Veuillez voir mon commentaire ici: stackoverflow.com/a/34927190/1748464 Il y a une bibliothèque, vous pouvez utiliser
InformationsquelleAutor Deepak Borade | 2013-12-31
Vous devez vous connecter pour publier un commentaire.
Dans votre cas,Vous avez déjà analyser vos données en format XML, de sorte difinately vous avez pour stocker toutes vos données dans la table de hachage Arraylist avec une touche particulière à votre url de la Vidéo.
Maintenant, que peut faire, Si vous avez besoin d'ouvrir la Vidéo sur l'Élément, Cliquez sur de ListView, alors vous pouvez récupérer l'url de la vidéo dans la Chaîne
Maintenant passer à ce myUrl à l'Activité suivante et définissez cette Chaîne comme un
Maintenant dans votre prochaine Activité de la récupérer comme un
Pour plus de référence pour le streaming vidéo ... vous pouvez vérifier l'url suivante:
http://developer.samsung.com/android/technical-docs/Android-Media-Streaming-Tutorial
vous pouvez même vérifier ma réponse à l'
Comment puis-je lire la Vidéo dans une ListView comme Instagram et Vine?
J'étais perplexe avec ce trop jusqu'à ce que j'ai trouvé ce post:
https://stackoverflow.com/a/6832598/3367142
En court de définir un arrière-plan transparent pour votre VideoView
android:background="#0000"