如何挑选从画廊SD卡的视频文件,并在App查看玩什么呢? [英] how to pick a video file from gallery SDcard and play it in App view?

查看:223
本文介绍了如何挑选从画廊SD卡的视频文件,并在App查看玩什么呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来接从画廊的视频和游戏,但我不能玩,但对于像我得到它作为像i'ad尝试了视频也不过它去一些地方错的,如果一些有任何想法,请帮我家伙。

这是我的code,但它不工作,

 进口android.app.Activity;
进口android.content.Intent;
进口android.database.Cursor;
进口android.net.Uri;
进口android.os.Bundle;
进口android.provider.MediaStore;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.widget.Button;
进口android.widget.VideoView;公共类videoView扩展活动实现OnClickListener {     私人VideoView视频preVIEW;
Button按钮;
私有静态最终诠释SELECT_VIDEO_REQUEST = 1;
    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.videoview);        按钮=(按钮)findViewById(R.id.button1);
        button.setOnClickListener((OnClickListener)本);
}
    公共无效的onClick(视图v){
        如果(V ==按钮){            意向意图=新意图(
                    Intent.ACTION_PICK,
                    android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
        startActivityForResult(意向,SELECT_VIDEO_REQUEST);    }}@覆盖
保护无效的onActivityResult(INT申请code,INT结果code,意图数据){
    super.onActivityResult(要求code,结果code,数据);    如果(要求code == SELECT_VIDEO_REQUEST&放大器;&安培;结果code == RESULT_OK&放大器;&安培;!NULL =数据){
        乌里selectedImage = data.getData();
        的String [] = filePathColumn {MediaStore.Video.Media.DATA};        光标光标= getContentResolver()查询(selectedImage,
                filePathColumn,NULL,NULL,NULL);
        cursor.moveToFirst();        INT参数:columnIndex = cursor.getColumnIndex(filePathColumn [0]);
        字符串picturePath = cursor.getString(参数:columnIndex);
        cursor.close();         视频preVIEW =(VideoView)findViewById(R.id.video preVIEW);
         视频preview.setVideoPath(picturePath);
}
}}


解决方案

下面是用于打开由意向的画廊一个简单的code,然后查看它在这个methos请用它帮助你。

 公共类videoView扩展活动实现OnClickListener {        按钮gallybutton;
           私人光标videocursor;
              私人诠释video_column_index;
              ListView的videolist;
              诠释计数;
        @覆盖
        保护无效的onCreate(捆绑savedInstanceState){
            super.onCreate(savedInstanceState);
            的setContentView(R.layout.videoview);
            gallybutton =(按钮)findViewById(R.id.gally);
            gallybutton.setOnClickListener((OnClickListener)本);        }
            公共无效的onClick(视图v){
          init_phone_video_grid();
    }
      公共无效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};
              videocursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,凸出,NULL,NULL,NULL);
              数= videocursor.getCount();
              videolist =(ListView控件)findViewById(R.id.PhoneVideoList);
              videolist.setAdapter(新VideoAdapter(getApplicationContext()));
              videolist.setOnItemClickListener(videogridlistener);
        }        公共OnItemClickListener videogridlistener =新OnItemClickListener(){
              公共无效onItemClick(适配器视图<>母公司,视图V,INT位置,
    长ID){
                    System.gc()的;
                    video_column_index = videocursor
    .getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
                    videocursor.moveToPosition(位置);
                    字符串文件名= videocursor.getString(video_column_index);
                    意向意图=新意图(videoView.this,gallyVideo.class);
                    intent.putExtra(videofilename,文件名);
                    startActivity(意向);
              }
        };        公共类VideoAdapter延伸BaseAdapter {
              私人语境vContext;              公共VideoAdapter(上下文C){
                    vContext = C;
              }              公众诠释的getCount(){
                    返回计数;
              }              公共对象的getItem(INT位置){
                    返回的位置;
              }              众长getItemId(INT位置){
                    返回的位置;
              }              公共查看getView(INT位置,查看convertView,父母的ViewGroup){
                    System.gc()的;
                    TextView的电视=新的TextView(vContext.getApplicationContext());
                    字符串ID = NULL;
                    如果(convertView == NULL){
                          video_column_index = videocursor
    .getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME);
                          videocursor.moveToPosition(位置);
                          ID = videocursor.getString(video_column_index);
                          video_column_index = videocursor
    .getColumnIndexOrThrow(MediaStore.Video.Media.SIZE);
                          videocursor.moveToPosition(位置);
                          ID + =大小(KB):+ videocursor.getString(video_column_index);
                          tv.setText(ID);
                    }其他
                          电视=(TextView中)convertView;
                    返回电视;
              }
        }}

i've to pick a video from gallery and play it but i can't play it but for image i got it as like that i'ad tried for video also but it goes some where wrong if some have any idea please help me guys.

here is my code but it is not working,

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.VideoView;

public class videoView extends Activity implements OnClickListener {

     private VideoView videoPreview;
Button button;
private static final int SELECT_VIDEO_REQUEST = 1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.videoview);

        button  = (Button) findViewById(R.id.button1);
        button.setOnClickListener((OnClickListener) this);
}
    public void onClick(View v) {
        if(v ==button){

            Intent intent = new Intent(
                    Intent.ACTION_PICK,
                    android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
        startActivityForResult(intent, SELECT_VIDEO_REQUEST);

    }}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == SELECT_VIDEO_REQUEST && resultCode == RESULT_OK && null != data) {
        Uri selectedImage = data.getData();
        String[] filePathColumn = { MediaStore.Video.Media.DATA };

        Cursor cursor = getContentResolver().query(selectedImage,
                filePathColumn, null, null, null);
        cursor.moveToFirst();

        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String picturePath = cursor.getString(columnIndex); 
        cursor.close();

         videoPreview = (VideoView) findViewById(R.id.videoPreview);
         videoPreview.setVideoPath(picturePath);
}
}}

解决方案

Here is a simple code which is used to open the gallery by intent then view it in this methos please use it helpful to you

public class videoView extends Activity implements OnClickListener {

        Button gallybutton;
           private Cursor videocursor;
              private int video_column_index;
              ListView videolist;
              int count;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.videoview);
            gallybutton  = (Button) findViewById(R.id.gally);
            gallybutton.setOnClickListener((OnClickListener) this);

        }
            public void onClick(View v) {


          init_phone_video_grid();
    }
      public 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 };
              videocursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,   proj, null, null, null);
              count = videocursor.getCount();
              videolist = (ListView) findViewById(R.id.PhoneVideoList);
              videolist.setAdapter(new VideoAdapter(getApplicationContext()));
              videolist.setOnItemClickListener(videogridlistener);
        }

        public 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(videoView.this, gallyVideo.class);
                    intent.putExtra("videofilename", filename);
                    startActivity(intent);
              }
        };

        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;
              }

              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);
                          tv.setText(id);
                    } else
                          tv = (TextView) convertView;
                    return tv;
              }
        }

}

这篇关于如何挑选从画廊SD卡的视频文件,并在App查看玩什么呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆