Android: - 视频播放器

时间:2017-07-04 19:53:43

标签: android

我制作了一个视频播放器应用程序,可以在运行时选择视频播放。选择视频后,会出现无法播放视频的错误。this is the error message

public class MainActivity extends AppCompatActivity {
VideoView videoView;
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    button= (Button) findViewById(R.id.button);
    videoView= (VideoView) findViewById(R.id.videoView);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent galleryIntent=new Intent();
            galleryIntent.setType("video/*");
            galleryIntent.setAction(galleryIntent.ACTION_GET_CONTENT);                
startActivityForResult(Intent.createChooser(galleryIntent,"Select 
Video"),9);
}
    });}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent 
data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode==9 && resultCode==RESULT_OK)
    {
        Uri videoUri=data.getData();
        videoView.setVideoURI(videoUri);
        videoView.start();}}}

`

1 个答案:

答案 0 :(得分:0)

1)尝试通过调用此setOnPreparedListener添加OnPreparedListener,并从onPrepared回调开始播放。

2)用ExoPlayer替换VideoView和MediaPlayer。它比默认播放器更稳定,也基于默认的Android组件,所以它很轻。