在Android中将视频播放到listview中

时间:2013-12-05 00:43:54

标签: android listview android-videoview

这里有点奇怪,我正在尝试从列表视图播放视频,但问题是videoView甚至没有放在列表中。陌生人的一部分是我设法做了两次没有任何问题,但现在不能...而且我删除了以前的脚本... 脚本:

public class Dadapt extends BaseAdapter {
public int play = 0;

long timeWhenStopped = 0;

private String SOURCE = "source track";
// Declare Variables
Context context;
LayoutInflater inflater;
LayoutInflater flat;
ArrayList<HashMap<String, String>> data;
ImageLoader imageLoader;
LoaderImage conteloader;
Audio_load audio_load;
ImageView im;
VideoView video;
AlertDialog.Builder builder;
HashMap<String, String> resultp = new HashMap<String, String>();
AQuery aq;

MediaController mc;

public Dadapt(Context context, ArrayList<HashMap<String, String>> arraylist) {
    this.context = context;
    data = arraylist;
    mc = new MediaController(context);
    video = new VideoView(context);
    imageLoader = new ImageLoader(context);
    aq = new AQuery(context);
    builder = new AlertDialog.Builder(context);
    // TODO Auto-generated constructor stub
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return data.size();
}

@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    final TextView friend;
    final String type, vids;
    final LinearLayout lin;
    final ImageView avatar;
    final TextView name;
    final Button mess;
    final VideoView vid;
    inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View itemView = inflater.inflate(R.layout.event_list, parent, false);
    resultp = data.get(position);
    vid = (VideoView)itemView.findViewById(R.id.deo);
    type = resultp.get(Me.TYPE);
    vids ="http://xxxxxxx.com/" + resultp.get(Me.MEDIA);
    lin = (LinearLayout) itemView.findViewById(R.id.near);
    avatar = (ImageView) itemView.findViewById(R.id.event_pic);

    if (type.equalsIgnoreCase("video")) {
        mc.setMediaPlayer(vid);
        vid.setMediaController(mc);
        vid.setVideoPath(vids);
        vid.start();

    } else {
        imageLoader.DisplayImage3(
                "http://xxxxxxxx/" + resultp.get(Me.MEDIA), avatar);
    }

    friend = (TextView) itemView.findViewById(R.id.event_title);
    friend.setText(resultp.get(Me.NAME));
    name = (TextView) itemView.findViewById(R.id.event_descr);
    name.setText(resultp.get(Me.DESCRIPTION));

    return itemView;
}

}

我做错了什么?最奇怪的部分是我之前做过两次,所以也许我在这里做了一个小错误......

就像视频视图根本没有显示

修改

这里是XML代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:background="@android:drawable/toast_frame"
android:orientation="vertical"
android:padding="5dp" >

<LinearLayout
    android:id="@+id/near"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:orientation="vertical"
    android:padding="5dp"
    android:paddingTop="0dp" >

    <ImageView
        android:id="@+id/event_pic"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="0dp" />

    <VideoView
        android:id="@+id/deo"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <TextView
        android:id="@+id/event_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#777777"
        android:textStyle="italic" />

    <TextView
        android:id="@+id/event_descr"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:textAlignment="inherit" />

    <Button
        android:id="@+id/event_go"
        style="?android:attr/borderlessButtonStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/show_me"
        android:textColor="#777777" />

</LinearLayout>

我在logcat上看到:     12-04 21:12:51.980:D / AbsListView(10157):调用unregisterIRListener()

1 个答案:

答案 0 :(得分:2)

好吧,在挖掘之后,看起来你只是不能把一个videoView放在一个listView中,所以我做了一个litle技巧,我只是把一个gridView只用了一个列就可以了。