0

晚上好,我有以下问题。我想在 VideoView 中播放视频格式 * .3gp。我尝试使用此代码:

  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.mylay);
  VideoView videoHolder = new VideoView(this);
  videoHolder = (VideoView) findViewById(R.id.videoView1);
  Uri video = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.asd);
  videoHolder.setVideoURI(video);
  videoHolder.setOnPreparedListener(new OnPreparedListener() {
   public void onPrepared(MediaPlayer mp) {
        mp.start();
        mp.setLooping(true);
   }
  });
}

在模拟器和 HTC Desire S 上一切正常。但是有一个中国平板电脑 Onda V972,每次都给我一个“播放视频时出错”:

06-19 18:34:18.890: W/AudioSystem(25145): AudioFlinger server died!
06-19 18:34:18.890: W/IMediaDeathNotifier(25145): media server died
06-19 18:34:18.890: E/MediaPlayer(25145): error (100, 0)
06-19 18:34:18.890: E/MediaPlayer(25145): Error (100,0)
06-19 18:34:18.890: D/VideoView(25145): Error: 100,0

请告诉我这个问题是否可以解决。太感谢了。也许还有另一种方法可以将视频文件加载到 VideoView 中?

更新 21.06:

刚刚更新了我的平板电脑的固件,现在视频正在播放但没有循环播放。我已经尝试了以下代码,但结果是一样的 - HTC 和模拟器运行良好,但平板电脑没有循环播放视频。我也试过 *.mp4 ,都一样:

VideoView videoHolder = new VideoView(this);
videoHolder = (VideoView) findViewById(R.id.videoView1);
// videoHolder.setMediaController(new MediaController(this));
Uri video = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.asd);
videoHolder.setVideoURI(video);
// setContentView(videoHolder);

videoHolder.setOnPreparedListener(new OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mp) {
        mp.setLooping(true);
        mp.start();
    }
});

videoHolder
        .setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                mp.mp.seekTo(0);
                mp.start();
            }

        });

问题是 - 如何让视频在所有设备上循环播放?

4

1 回答 1

0

尝试使用媒体控制器设置视频视图

public class HelloInterruptVideoStream extends Activity
{
    private String path = "http://dl.dropbox.com/u/145894/t/rabbits.3gp";
    private VideoView videoview;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        videoview = (VideoView)findViewById(R.id.surface_view);

        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

        videoview.setVideoURI(Uri.parse(path));
        videoview.setMediaController(new MediaController(this));
        videoview.requestFocus();
        videoview.start();

    }
}
于 2013-06-20T13:18:05.627 回答