2012-03-13 184 views
0

我無法播放來自SD卡的視頻文件。 - 我正在播放來自SD卡的特定視頻文件。 - 同時從列表中選擇視頻,它不會播放視頻。 - 我傳遞給videoView類的意圖是無法讀取。SD卡視頻不播放?

public class AndroidThumbnailList extends ListActivity{ 

String[] videoFileList = { 
     "/sdcard/Periodontal/Perio-Probling.mp4", 
     "/sdcard/Periodontal/Inlays.mp4" 
     /* "/sdcard/Video/Onlays.mp4", 
     "/sdcard/Video/Root Canal Treatment.mp4", 
     "/sdcard/Video/crown4.mp4", 
     "/sdcard/Video/crown5.mp4", 
     "/sdcard/Video/crown6.mp4", 
     "/sdcard/Video/crown7.mp4"*/ 
}; 

public class MyThumbnaildapter extends ArrayAdapter<String>{ 

    public MyThumbnaildapter(Context context, int textViewResourceId, 
      String[] objects) { 
     super(context, textViewResourceId, objects); 
     // TODO Auto-generated constructor stub 
    } 

    @Override 
    public View getView(final int position, View convertView, ViewGroup parent) { 
     // TODO Auto-generated method stub 

     View row = convertView; 
     if(row==null){ 
      LayoutInflater inflater=getLayoutInflater(); 
      row=inflater.inflate(R.layout.row, parent, false); 
     } 


     row.setOnClickListener(new OnClickListener() { 

      public void onClick(View arg0) { 
       if(position==0) 
       { 
        Intent intent = new Intent(AndroidThumbnailList.this, ViewVideo.class); 
        intent.putExtra("videofilename", videoFileList); 
        startActivity(intent); 

       } 
        /*if(position==1) 
       { 

      Intent intent = new Intent(mContext, PeriodontalCare.class); 
      mContext.startActivity(intent);       


       } 
         if(position==2) 
       { 
        Intent i = new Intent(mContext, CosmeticCare.class); 

        mContext.startActivity(i); 

       }*/ 
      } 
     }); 
     TextView textfilePath = (TextView)row.findViewById(R.id.FilePath); 
     textfilePath.setText(videoFileList[position]); 

     ImageView imageThumbnail = (ImageView)row.findViewById(R.id.Thumbnail); 

     Bitmap bmThumbnail; 
     bmThumbnail = ThumbnailUtils.createVideoThumbnail(videoFileList[position], Thumbnails.MICRO_KIND); 
     imageThumbnail.setImageBitmap(bmThumbnail); 

     return row; 
    } 

} 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setListAdapter(new MyThumbnaildapter(AndroidThumbnailList.this, R.layout.row, videoFileList)); 
} 

}

我VideoView類:

public class ViewVideo extends Activity { 
    private String videoFileList; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     // setContentView(R.layout.videofile); 

     // mVideoView = (VideoView) findViewById(R.id.surface_view); 



     System.gc(); 
     Intent i = getIntent(); 
     Bundle extras = i.getExtras(); 
     videoFileList = extras.getString("videofilename"); 
     VideoView vv = new VideoView(getApplicationContext()); 
     setContentView(vv); 
     vv.setVideoPath(videoFileList); 
     vv.setMediaController(new MediaController(this)); 
     vv.requestFocus(); 
     vv.start(); 
    } 

}

+0

不會對電網項目使用onClickListener。使用網格視圖提供的onItemSelected(或其他)。因爲你的行對象被重用。 – njzk2 2012-03-13 09:25:52

回答

1
  1. 你不應該創建一個新VideoView,但得到的VideoView使用findViewById

    setContentView(R.layout.videofile); 
    VideoView vv = (VideoView) findViewById(R.id.surface_view); 
    // rest of the calls on vv 
    
  2. 您不應該使用硬編碼的視頻文件路徑,因爲它可能會在不同設備之間切換。相反,使用類似的東西。

    Environment.getExternalStorageDirectory().getAbsolutePath() + "/Periodontal/Perio-Probling.mp4" 
    
+0

嗨Binyamin,感謝您的答覆 - Environment.getExternalStorageDirectory()。getAbsolutePath()+「/Periodontal/Perio-Probling.mp4」 - 我只能讀取單個文件,如果我想讀取多個文件? – Chandu 2012-03-13 10:15:52

+0

這只是一個示例,用於演示方法的用法,在需要時使用它(或創建一個包含方法結果的String變量) – MByD 2012-03-13 10:19:53