如何使用exoplayer在全屏播放视频?

时间:2017-11-26 11:10:52

标签: java android exoplayer

这是我的代码:

  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 个答案:

答案 0 :(得分:4)

尝试更改SimpleExoPlayerView的调整大小模式,如下所示

app:resize_mode="fill"

您也可以从java

设置它
simpleExoPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL);