0

我尝试从我的代码创建 ViedoView,但是当我运行它时,我没有看到任何创建的视图。我将视频的路径保存在我的数据库中,然后尝试显示它。我对 ImageView 及其作品尝试了同样的事情,所以我想我忘记了 VideoView 中的某些内容。

我的代码:

    private void getUserVideo() {

        Intent intentToPlayVideo = new Intent(Intent.ACTION_VIEW);
        intentToPlayVideo.setType("video/*");
        intentToPlayVideo.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(intentToPlayVideo, SELECT_VIDEO);
    }


    public void onActivityResult(int requestCode, int resultCode, 
           Intent imageReturnedIntent) {
        super.onActivityResult(requestCode, resultCode, imageReturnedIntent); 

        switch(requestCode) { 
        case SELECT_PHOTO:
            if(resultCode == RESULT_OK){  
                Uri selectedImage = imageReturnedIntent.getData();
                String[] filePathColumn = {MediaStore.Images.Media.DATA};

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

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

                extras = getIntent().getExtras();
                String s = extras.getString("date");

               DataBaseMain data = new DataBaseMain(this);
               data.open();
               data.putWorkOutPic(filePath, s);
               data.close();   
               recreate();
            }   

        case SELECT_VIDEO:
        {
            if(resultCode == RESULT_OK){ 
            Uri vid = imageReturnedIntent.getData();
            String videoPath = getRealPathFromURI(vid);

            extras = getIntent().getExtras();
            String s = extras.getString("date");

           DataBaseMain data = new DataBaseMain(this);
           data.open();
           data.putWorkOutVideo(videoPath, s);
           data.close();   
           recreate();
            }
        } 
     }
}


public String getRealPathFromURI(Uri contentUri) {
        String[] proj = { MediaStore.Images.Media.DATA };
        Cursor cursor = managedQuery(contentUri, proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    }


    private void addVideos() {

        extras = getIntent().getExtras();
        String s = extras.getString("date");

        DataBaseMain data = new DataBaseMain(this);
        data.open();
        videos = data.getWorkOutVideo(s);
        data.close();

        if(videos == null || videos.length < 1)
        return;

        LinearLayout linear = (LinearLayout) findViewById(R.id.dateMain);
        LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);

        for(int i = 0; i < videos.length; i++){

            VideoView video = new VideoView(this);
            video.setVideoPath(videos[i]);
            video.setLayoutParams(lp);
            video.setId(i+50);
            video.setOnLongClickListener(new OnLongClickListener() {
                public boolean onLongClick(View arg0) {

                    selectedVideo = arg0.getId();
                    onButtonClickEvent(arg0);

                    return true;   
                }
            });
            linear.addView(video);
        }           
    }
4

1 回答 1

0

查看Youtube Player这基本上是一个 youtube 播放器,但请参阅setupView此文件中的方法,它以编程方式创建代码,您可以知道哪里出错了

于 2013-05-16T06:13:08.887 回答