Android 视频(从URL中提取)不';尝试将它们放置在带有阵列适配器的列表视图中时,不显示
我试图制作一个列表视图,显示来自URL的视频,但我得到的只是一个空白屏幕 下面是VideoPlayerActivity.javaAndroid 视频(从URL中提取)不';尝试将它们放置在带有阵列适配器的列表视图中时,不显示,android,android-listview,android-videoview,Android,Android Listview,Android Videoview,我试图制作一个列表视图,显示来自URL的视频,但我得到的只是一个空白屏幕 下面是VideoPlayerActivity.java package com.example.nikhilbuduma.giflistview; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.media.MediaPlayer; import andro
package com.example.nikhilbuduma.giflistview;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;
import java.util.ArrayList;
public class VideoPlayerActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_player);
final ListView listview = (ListView) findViewById(R.id.listview);
String[] urls = new String[] {"http://download.wavetlan.com/SVV/Media/HTTP/H264/Talkinghead_Media/H264_test1_Talkinghead_mp4_480x360.mp4"};
final StableArrayAdapter adapter = new StableArrayAdapter(this, urls);
listview.setAdapter(adapter);
}
private class StableArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] values;
public StableArrayAdapter(Context context, String[] values){
super(context, R.layout.movie_cell, values);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.movie_cell, parent, false);
final VideoView videoView =(VideoView)rowView.findViewById(R.id.videoView);
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
videoView.start(); //need to make transition seamless.
}
});
videoView.setVideoURI(Uri.parse(values[position]));
videoView.requestFocus();
videoView.start();
return rowView;
}
}
}
使用
ImageView
获取视频的缩略图,而不是VideoView
@Override
public View getView(int position, View convertView, ViewGroup parent) {
...
Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(values[position],
MediaStore.Video.Thumbnails.MICRO_KIND);
imageView.setImageBitmap(thumbnail);
...
}
这似乎不起作用,缩略图没有显示出来。我认为我写的代码有更深层次的问题?
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<VideoView android:id="@+id/videoView"
android:layout_height="wrap_content"
android:layout_width="fill_parent"/>
</RelativeLayout>
01-07 20:45:50.741 2367-2367/com.example.nikhilbuduma.giflistview I/art﹕ Not late-enabling -Xcheck:jni (already on)
01-07 20:45:50.855 2367-2382/com.example.nikhilbuduma.giflistview D/OpenGLRenderer﹕ Render dirty regions requested: true
01-07 20:45:50.857 2367-2367/com.example.nikhilbuduma.giflistview D/﹕ HostConnection::get() New Host Connection established 0xae0f3d30, tid 2367
01-07 20:45:50.865 2367-2367/com.example.nikhilbuduma.giflistview D/Atlas﹕ Validating map...
01-07 20:45:50.929 2367-2382/com.example.nikhilbuduma.giflistview D/﹕ HostConnection::get() New Host Connection established 0xa6c4a040, tid 2382
01-07 20:45:50.946 2367-2382/com.example.nikhilbuduma.giflistview I/OpenGLRenderer﹕ Initialized EGL, version 1.4
01-07 20:45:50.972 2367-2382/com.example.nikhilbuduma.giflistview D/OpenGLRenderer﹕ Enabling debug mode 0
01-07 20:45:51.028 2367-2382/com.example.nikhilbuduma.giflistview W/EGL_emulation﹕ eglSurfaceAttrib not implemented
01-07 20:45:51.028 2367-2382/com.example.nikhilbuduma.giflistview W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xae0e88e0, error=EGL_SUCCESS
01-07 20:45:51.623 2367-2382/com.example.nikhilbuduma.giflistview W/EGL_emulation﹕ eglSurfaceAttrib not implemented
01-07 20:45:51.623 2367-2382/com.example.nikhilbuduma.giflistview W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xae0e88e0, error=EGL_SUCCESS
@Override
public View getView(int position, View convertView, ViewGroup parent) {
...
Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(values[position],
MediaStore.Video.Thumbnails.MICRO_KIND);
imageView.setImageBitmap(thumbnail);
...
}