开发者

Android: Cannot see video on HTC Hero 1.5

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 dem开发者_开发知识库oVideo = (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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜