views:

80

answers:

1

I am trying to play a video through my application.

public class VideoScreen extends Activity {
public MediaPlayer videoMediaPlayer = new MediaPlayer();

public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.videoscreen); 
    SurfaceView demoVideo = (SurfaceView) findViewById(R.id.demoVideo);
    SurfaceHolder videoHolder = demoVideo.getHolder();
    videoMediaPlayer = MediaPlayer.create(this, R.raw.help);
    videoMediaPlayer.setDisplay(videoHolder);
    videoMediaPlayer.setLooping(false);
    videoMediaPlayer.setScreenOnWhilePlaying(true);
    videoMediaPlayer.start();
    }
}

XML File:

<?xml version="1.0" encoding="utf-8"?>      
   <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent" android:layout_height="fill_parent">
    <SurfaceView android:id="@+id/demoVideo" 
       android:layout_width="wrap_content" 
        android:layout_height="wrap_content"></SurfaceView> 
   </FrameLayout>

I can hear only sound, but no video.

But, when I try to play this video separately through file manager. It is playing perfectly. Where I am wrong?

Please help.

A: 

I managed to play the video on my phone as well as simulator using VideoView

The changes done were:

Java File:

public class VideoScreen extends Activity {
   public void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.videoscreen); 
        Uri raw_uri=Uri.parse("android.resource://com.binary/"+R.raw.myvideo);
        VideoView videoView=(VideoView)findViewById(R.id.demoVideo);
        videoView.setVideoURI(raw_uri); 
        videoView.setMediaController(new MediaController(this)); 
        videoView.setOnCompletionListener(videoOverListener);
        videoView.start(); 
        videoView.requestFocus();
  }
}

XML File:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
    <VideoView android:id="@+id/demoVideo"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
    </VideoView>
</FrameLayout>

Hope this helps.

Pria