How to play a video file in android?

后端 未结 6 1818
有刺的猬
有刺的猬 2020-12-29 08:03

I am placed video MP4 to my domain space. I have its public URL, Now i want to play it in my android app; but don\'t know how can I do this. I used following code which is n

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-29 08:23

    You should do it in onResume, because in onCreate VideoView does not knows its size and can't create properly surface to display video.

    public class MPlayer extends Activity{
    
    VideoView videoView;
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.playvideo);
        videoView = new VideoView(MPlayer.this);
        videoView.setMediaController(new MediaController(this));
        LinearLayout l = (LinearLayout)findViewById(R.id.mplayer);
        l.addView(videoView);
       }
    
        @Override
        protected void onResume() {
            super.onResume();
    videoView.setVideoURI(Uri.parse("http://www.semanticdevlab.com/abc.mp4"));
            videoView.start();
    }
    

提交回复
热议问题