Kakey
Kakey

Reputation: 4024

VideoVIew issue on android

I am working on video player in android.when i created surface holder in on create method ,it did not create.but when i created the surface holder in button onclick method,its created

My coding is,

preview=(VideoView)findViewById(R.id.surface);
    preview.setEnabled(true);
    preview.bringToFront();
    holder=preview.getHolder();
    holder.setFixedSize(400, 400);

    mp=new MediaPlayer(); 
    mp.setDataSource("path");
    mp.setDisplay(holder);
    mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mp.setOnBufferingUpdateListener(playerActivity.this);
    mp.setOnPreparedListener(playerActivity.this);
    mp.prepare();
    mp.start();

Upvotes: 1

Views: 2200

Answers (1)

Mathias Conradt
Mathias Conradt

Reputation: 28665

mp.prepare();
mp.start();

prepare() is asynchronous, which means, it might not be finished when you already call the mp.start. What do you mean by 'surface not created'? Do you just mean the video doesn't play? Anyway, you should use an MediaPlayer.OnPreparedListener and start the media in onPrepared().

Upvotes: 1

Related Questions