How to Play Video on OnCreate Method?
<p>How to Play Video on OnCreate Method? I Used Following code for that.But The Video is Not Played.If i used this Code on Click Event of Button then This is Worked.</p>

<p>My OnCreate Method:-</p>

<pre><code>@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);      
    getWindow().setFormat(PixelFormat.UNKNOWN);
    surfaceView = (SurfaceView) findViewById(R.id.surfaceview);
    surfaceHolder = surfaceView.getHolder();
    surfaceHolder.addCallback(this);
    surfaceHolder.setFixedSize(176, 144);
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    mediaPlayer = new MediaPlayer();
    mediaPlayer.isLooping();
    playvideo();
}
</code></pre>

<p>My PlayVideo Function:-</p>

<pre><code>public void playvideo() {
    String stringPath = "/sdcard/video.mp4";

    if (mediaPlayer.isPlaying()) {
        mediaPlayer.reset();
    }

    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setDisplay(surfaceHolder);

    try {
        mediaPlayer.setDataSource(stringPath);
        mediaPlayer.prepare();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    mediaPlayer.start();
}
</code></pre>

<p>Thanks in Advance.</p>
