Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SurfaceView blank when play video usinng mediaplayer

This is My code but when I start the mediaplayer it have only the sound come out and the surface have nothing shown . Why?

I have no idea on this. Do you have some code help me to learn with this.

    videoV = (SurfaceView) findViewById(R.id.SurfaceView1);
    sh = videoV.getHolder();

    File path = Environment.getExternalStorageDirectory();
    File file = new File(path, "sample2.mp4");

    sh.addCallback(this);     
    mp = new MediaPlayer();
    mp.setDataSource(file.getAbsolutePath());
    mp.setDisplay(sh);
    mp.prepare();
    mp.start();
like image 399
user829821 Avatar asked Jul 08 '11 07:07

user829821


1 Answers

Try to add after

sh.addCallback(this);

this

sh.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

In my case it was helpful.

like image 83
Gennady Avatar answered Oct 27 '22 01:10

Gennady