如何修改我的 VideoView 中显示的控件?

发布于 2024-11-25 06:06:22 字数 1281 浏览 0 评论 0原文

我有一个由简单 MediaController 控制的 VideoView,我想修改其控件。目前,它显示了一个搜索栏、快进和快退按钮以及播放/暂停。我想将其范围缩小到仅具有播放和暂停按钮,因为我正在播放的流或多或少是实时的。如何修改现有的控件?这是我当前在 onCreate 中的代码:

this.setContentView(R.layout.videoplayer);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

this.videoView = (VideoView)this.findViewById(R.id.videoview);
this.mediaController = new MediaController(this);
this.mediaController.setAnchorView(this.videoView);

Uri uri = Uri.parse(this.getIntent().getStringExtra("uri"));

this.videoView.setMediaController(this.mediaController);
this.videoView.setVideoURI(uri);

this.videoView.setOnPreparedListener(new OnPreparedListener() {
    @Override public void onPrepared(MediaPlayer mp) {
        findViewById(R.id.video_loading_spinner).setVisibility(View.GONE);
    }
});

this.videoView.setOnErrorListener(new OnErrorListener() {
    @Override public boolean onError(MediaPlayer mp, int what, int extra) {
        showDialog(VIDEO_FAILED);
        return true;
    }
});

//this.videoView.setOnCompletionListener(new OnCompletionListener() {
//  @Override public void onCompletion(MediaPlayer mp) {
//      showDialog(VIDEO_COMPLETE);
//  }
//});

this.videoView.start();

I have a VideoView controlled by a simple MediaController that I'd like to modify the controls for. Currently, it shows a seek bar, fast-forward and rewind buttons, and play/pause. I'd like to narrow this down to simply having play and pause buttons, as the stream I'm playing is more or less live. How can I modify the controls present? This is my current code in onCreate:

this.setContentView(R.layout.videoplayer);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

this.videoView = (VideoView)this.findViewById(R.id.videoview);
this.mediaController = new MediaController(this);
this.mediaController.setAnchorView(this.videoView);

Uri uri = Uri.parse(this.getIntent().getStringExtra("uri"));

this.videoView.setMediaController(this.mediaController);
this.videoView.setVideoURI(uri);

this.videoView.setOnPreparedListener(new OnPreparedListener() {
    @Override public void onPrepared(MediaPlayer mp) {
        findViewById(R.id.video_loading_spinner).setVisibility(View.GONE);
    }
});

this.videoView.setOnErrorListener(new OnErrorListener() {
    @Override public boolean onError(MediaPlayer mp, int what, int extra) {
        showDialog(VIDEO_FAILED);
        return true;
    }
});

//this.videoView.setOnCompletionListener(new OnCompletionListener() {
//  @Override public void onCompletion(MediaPlayer mp) {
//      showDialog(VIDEO_COMPLETE);
//  }
//});

this.videoView.start();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不必了 2024-12-02 06:06:22

您无法修改 MediaController 中存在的控件,但您可以创建自己的控制器并使用它来代替 MediaController。我在这个古老的项目中做到了这一点。

You cannot modify the controls that are present in MediaController, but you can create your own controller and use that instead of MediaController. I did that in this ancient project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文