Android:在HTC Hero 1.5上看不到视频

时间:2010-08-12 09:53:46

标签: android video media-player surfaceview

我正在尝试通过我的应用程序播放视频。

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文件:

<?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>

我只能听到声音,但没有视频。

但是,当我尝试通过文件管理器单独播放此视频时。它打得很完美。哪里错了?

请帮忙。

1 个答案:

答案 0 :(得分:0)

我设法使用 VideoView

在手机和模拟器上播放视频

所做的改变是:

Java文件:

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文件:

<?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>

希望这有帮助。