播放器在播放在线视频时会消耗太多数据

发布于 2025-01-30 18:37:17 字数 1459 浏览 3 评论 0原文

我正在制作一个从URL播放视频的应用程序。我正在使用埃法赛车,但是我注意到,当我在范围内播放在线视频时,它会消耗太多数据。例如,当我播放电影URL时,它只会加载2-3秒,而我的系列仪会消耗大约400MB,而我不确定为什么。

这是我的视频播放方法。我做错了吗?

private void playvideo() {

        String MOVIEURL = getIntent().getStringExtra("playthis");
Uri uri = Uri.parse(MOVIEURL);
player = new SimpleExoPlayer.Builder(this).setSeekForwardIncrementMs(10000).setSeekBackIncrementMs(10000).build();

        DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(
                this, Util.getUserAgent(this , "app"));
concatenatingMediaSource = new ConcatenatingMediaSource();

//  app:rewind_increment="1e000"
//    app:fastforward_increment="10000"

        MediaSource mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
                .createMediaSource(MediaItem.fromUri(Uri.parse(String.valueOf(uri))));

        concatenatingMediaSource.addMediaSource(mediaSource);
        playerView.setPlayer(player);
        playerView.setKeepScreenOn(true);
        player.prepare(concatenatingMediaSource);
        player.seekTo(position , C.TIME_UNSET);
        playError();
        

    }

    private void playError() {
        player.addListener(new Player.Listener() {
            @Override
            public void onPlayerError(PlaybackException error) {
                Toast.makeText(video_player.this, "Error", Toast.LENGTH_SHORT).show();
            }
        });


I'm making an app which plays videos from a URL. I'm using Exoplayer, but I noticed that when I play an online video in Exoplayer, it consumes too much data. For example, when I play a movie URL, it just loads for 2-3 seconds and my Exoplayer consumes around 400mb, and I'm not sure why.

This my video playing method in Exoplayer. Is there something I did wrong?

private void playvideo() {

        String MOVIEURL = getIntent().getStringExtra("playthis");
Uri uri = Uri.parse(MOVIEURL);
player = new SimpleExoPlayer.Builder(this).setSeekForwardIncrementMs(10000).setSeekBackIncrementMs(10000).build();

        DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(
                this, Util.getUserAgent(this , "app"));
concatenatingMediaSource = new ConcatenatingMediaSource();

//  app:rewind_increment="1e000"
//    app:fastforward_increment="10000"

        MediaSource mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
                .createMediaSource(MediaItem.fromUri(Uri.parse(String.valueOf(uri))));

        concatenatingMediaSource.addMediaSource(mediaSource);
        playerView.setPlayer(player);
        playerView.setKeepScreenOn(true);
        player.prepare(concatenatingMediaSource);
        player.seekTo(position , C.TIME_UNSET);
        playError();
        

    }

    private void playError() {
        player.addListener(new Player.Listener() {
            @Override
            public void onPlayerError(PlaybackException error) {
                Toast.makeText(video_player.this, "Error", Toast.LENGTH_SHORT).show();
            }
        });


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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文