1

我的 UI 有一个按钮和一个 videoview。当我们单击按钮时,转到 Gallery Video,当我们在 Video Gallery 中选择一个视频时,它会返回我的 UI,videoview 将显示被选中的视频..我使用如下代码但它没有'不显示视频:(

public class VideoGalleryActivity extends Activity {
/** Called when the activity is first created. */
Button button;
VideoView videoView;
private static final int PICK_FROM_GALLERY=1;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    button=(Button)findViewById(R.id.button);
    videoView=(VideoView)findViewById(R.id.videoview);

    button.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent();

            intent.setType("video/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);

            startActivityForResult(Intent.createChooser(intent, "Complete action using"),PICK_FROM_GALLERY);
        }
    })  ;      
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (resultCode != RESULT_OK) return;

    if (requestCode == PICK_FROM_GALLERY) {
        Uri mVideoURI = data.getData();  
        videoView.setVideoURI(mVideoURI);
    }

}
4

1 回答 1

1

您必须让 videoview 从添加videoview.start();. 代码:

public void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (resultCode != RESULT_OK) return;

    if (requestCode == PICK_FROM_GALLERY) {
        Uri mVideoURI = data.getData();  
        videoView.setVideoURI(mVideoURI);
        videoview.start();   //edited
    }

}
于 2013-03-05T12:43:08.263 回答