2015-02-03 1 views
2

30 초까지 비디오를 제어하려면 어떻게해야합니까? 그렇지 않으면 토스트/팝업을 표시하십시오. onActivityResult에 비디오 경로를 가져올 수 있으며 비디오를 실행할 수는 있지만 재생 시간을 가져올 수 없습니다.갤러리에서 비디오 선택 : 최대 30 초까지만 비디오를 선택해야합니다.

case Utils.REQUEST_CODE_GALLERY_VIDEO: 

     if (resultCode == Activity.RESULT_OK) { 
      Uri selectedVieo = data.getData(); 
      String[] filePathColumn = { MediaStore.Video.Media.DATA }; 

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

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

      try { 
       if (filePath != null) { 
        runVideo(filePath); 
       } 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 

답변

1

case Utils.REQUEST_CODE_GALLERY_VIDEO: 

     if (resultCode == Activity.RESULT_OK) { 
      Uri selectedVieo = data.getData(); 
      String[] filePathColumn = { MediaStore.Video.Media.DATA }; 

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

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

      try { 
       if (filePath != null) { 

        MediaPlayer mp = MediaPlayer.create(this, Uri.parse(filePath)); 
        int duration = mp.getDuration(); 
        mp.release(); 

        if((duration/1000) > 30){ 
         // Show Your Messages       
        }else{ 
         runVideo(filePath); 
        } 
       } 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
도움이 희망을보십시오 : 어떤 제안은 아래에있는 내 코드입니다
관련 문제