Мне нужно воспроизвести видео одно за другим, выбрав первое видео.
привет,
у меня был код со сканированием внешнего устройства и получением списка видео. нам нужно выбрать видео для воспроизведения.
мне нужно автоматизировать плеер, чтобы он мог воспроизводить все видео одно за другим.
как я могу это сделать?
package com.list.videolist; import android.app.Activity; import android.content.ContentResolver; import android.content.Context; import android.content.CursorLoader; import android.content.Loader; import android.content.Intent; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.provider.MediaStore; import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.ListView; import android.widget.MediaController; import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener; import android.widget.VideoView; public class VideoActivity extends Activity { private Cursor videocursor; private int video_column_index; ListView videolist; int count; //private VideoView mVideoView; //private MediaController controller; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); System.gc(); // mVideoView = (VideoView) findViewById(R.id.videoView); // mVideoView = new VideoView(getApplicationContext()); //setContentView(mVideoView); //controller = new MediaController(this); // controller.setAnchorView(mVideoView); // controller.setMediaPlayer(mVideoView); setContentView(R.layout.main); init_phone_video_grid(); } private void init_phone_video_grid() { System.gc(); String[] proj = { MediaStore.Video.Media._ID, MediaStore.Video.Media.DATA, MediaStore.Video.Media.DISPLAY_NAME, MediaStore.Video.Media.SIZE }; //alternativie to managedQuery. videocursor = getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,proj,null, null, null); //videocursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, proj, null, null, null); count = videocursor.getCount(); Log.d("count:", String.valueOf(count)); videolist = (ListView) findViewById(R.id.VideoList); videolist.setAdapter(new VideoAdapter(getApplicationContext())); videolist.setOnItemClickListener(videogridlistener); } private OnItemClickListener videogridlistener = new OnItemClickListener() { public void onItemClick(AdapterView parent, View v, int position, long id) { System.gc(); video_column_index = videocursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA); videocursor.moveToPosition(position); String filename = videocursor.getString(video_column_index); Intent intent = new Intent(VideoActivity.this, ViewVideo.class); intent.putExtra("videofilename", filename); startActivity(intent); Log.d("Video Path : ",filename); // mVideoView.setVideoPath(filename); // mVideoView.setMediaController(controller); // mVideoView.requestFocus(); // mVideoView.start(); } }; public class VideoAdapter extends BaseAdapter { private Context vContext; public VideoAdapter(Context c) { vContext = c; } public int getCount() { return count; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { System.gc(); TextView tv = new TextView(vContext.getApplicationContext()); String id = null; if (convertView == null) { video_column_index = videocursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME); videocursor.moveToPosition(position); id = videocursor.getString(video_column_index); // video_column_index = videocursor.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE); // videocursor.moveToPosition(position); // id += " Size(KB):" + videocursor.getString(video_column_index); //ImageView iv = new ImageView(vContext); //ContentResolver crThumb = getContentResolver(); //BitmapFactory.Options options=new BitmapFactory.Options(); //options.inSampleSize = 1; //Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(crThumb, position, MediaStore.Video.Thumbnails.MICRO_KIND, options); //iv.setImageBitmap(curThumb); tv.setText(id); } else tv = (TextView) convertView; return tv; } } }
Эта основная активность называется видеоактивностью.
package com.list.videolist; import android.app.Activity; import android.content.Intent; import android.database.Cursor; import android.media.MediaPlayer; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.provider.MediaStore; import android.util.Log; import android.widget.MediaController; import android.widget.VideoView; public class ViewVideo extends Activity { private String filename; //12/9/2016 -start // int count 0; // String _path; //12/9/2016 -end @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // FrameLayout frame = new FrameLayout(this); System.gc(); Intent i = getIntent(); Bundle extras = i.getExtras(); filename = extras.getString("videofilename"); // VideoView vv = new VideoView(getApplicationContext()); final VideoView vv = new VideoView(this); // final VideoView vv = (VideoView) findViewById(R.id.videoView); //12/9/2016-start // _path = "/mnt/media_rw/usbdisk/"+count+".*"; //vv.setVideoPath(_path); //vv.start(); //12/9/16-end setContentView(vv); //getWindow().setLayout(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.FILL_PARENT); vv.setVideoPath(filename); vv.setMediaController(new MediaController(this)); android.widget.FrameLayout.LayoutParams vvParams = (android.widget.FrameLayout.LayoutParams) vv.getLayoutParams(); vvParams.gravity = 17; //gravity 17 = center horizontal & vertical vvParams.width = 5000; vv.setLayoutParams(vvParams); //setContentView(frame, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); vv.requestFocus(); // Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getAbsolutePath()+"/udisk/videos"); // vv.setVideoURI(uri); vv.start(); // vv.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { // @Override // public void onPrepared(MediaPlayer mediaPlayer) { // mediaPlayer.setLooping(true); // } // }); vv.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { public void onCompletion(MediaPlayer player) { Log.i("VideoView", "onCompletion()"); //for loogping vv.start(); // finish() for closing. finish(); vv.requestFocus(); } }); } }
Что я уже пробовал:
Поиск способов автоматизации процесса