2013-05-16 61 views
0

我嘗試從我的代碼創建ViedoView,但是當我運行它時,我沒有看到任何創建的視圖。 我將視頻的路徑保存在我的數據庫中,然後嘗試顯示它。 我嘗試與ImageView及其作品相同的東西,所以我想我忘了VideoView中的東西。從代碼創建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); 
     }   
    } 

回答

0

Youtube Player這基本上是一個YouTube播放器,但看到該文件setupView方法,它正在創建的代碼編程,你可以有想法,你要去哪裏錯了

+0

感謝幫助。我看着他們的代碼,看起來像我的。很奇怪...... – tomer

+0

雖然這可能在理論上回答這個問題,但最好在這裏包含答案的基本部分,並提供供參考的鏈接。 –