如何使用ExoPlayer全屏播放视频?

5
这是我的代码:

  setContentView(R.layout.activity_video);
        SimpleExoPlayerView exoPlayerView;
        //SimpleExoPlayer exoPlayer;
        Intent intent = getIntent();

        String url_video_passato = intent.getStringExtra("URL_VIDEO");
        System.out.println("PASSATO?"+url_video_passato);
       // String videoURL = "http://vod06.msf.ticdn.it/farmunica/2017/11/124899_15fc565cd8f965/15fc565cd8f965-11_0.mp4";


            exoPlayerView = (SimpleExoPlayerView) findViewById(R.id.exo_player_view);
            try {


                BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
                TrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(bandwidthMeter));
                exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector);

                Uri videoURI = Uri.parse(url_video_passato);

                DefaultHttpDataSourceFactory dataSourceFactory = new DefaultHttpDataSourceFactory("exoplayer_video");
                ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
                MediaSource mediaSource = new ExtractorMediaSource(videoURI, dataSourceFactory, extractorsFactory, null, null);

                exoPlayerView.setPlayer(exoPlayer);
                exoPlayer.prepare(mediaSource);
                exoPlayer.setPlayWhenReady(true);
            }catch (Exception e){
                Log.e("MainAcvtivity"," exoplayer error "+ e.toString());
            }

视频活动布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="marco.uomini.donne.Video">
        <com.google.android.exoplayer2.ui.SimpleExoPlayerView
        android:id="@+id/exo_player_view"
        android:layout_alignParentStart="true"
        android:layout_alignParentEnd="true"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
       >

    </com.google.android.exoplayer2.ui.SimpleExoPlayerView>

</android.support.constraint.ConstraintLayout>

使用ExoPlayer时,视频无法全屏播放,我不知道为什么。
目前的结果如下:

enter image description here

有人可以帮助我吗?
1个回答

9
尝试按以下方式更改SimpleExoPlayerView的调整大小模式
app:resize_mode="fill"

您也可以从Java中设置它。
simpleExoPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL);

@Sisso 很高兴能帮助你。 - Munir
它可以工作,但它会垂直拉伸视频,是否可能将视频中心裁剪并适应屏幕?参考我的问题https://blog.lemberg.co.uk/surface-view-video-cropping - Sagar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接