Exoplayer以全屏模式启动它

时间:2018-06-06 15:22:32

标签: java android android-layout user-interface exoplayer

我正试图通过全屏模式启动Exoplayer。

只需将参数传递给intent,例如url和可能的标题。

我尝试查看文档和stackoverflow,但我找不到任何内容。

这是我目前使用的代码,但效果不佳。

try {

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

            Uri videoURI = Uri.parse(url);

            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);
            exoPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL);

        }catch (Exception e){
            Log.e("MainAcvtivity"," exoplayer error "+ e.toString());
        }

有人可以帮我一把吗?

2 个答案:

答案 0 :(得分:2)

除了全屏外,Exoplayer在所有方面都是一个非常好的玩家,因此处理全屏功能的最佳方法是进行仅具有横向方向的活动,或者如果您想同时拥有纵向和横向模式,则更好地改变取向。看看这篇文章 https://medium.com/tall-programmer/fullscreen-functionality-with-android-exoplayer-5fddad45509f 但如果您不想处理这些内容,我建议您将播放器更改为JWPlayer或youtubeplayer。

答案 1 :(得分:0)

如何通过exoplayer实现全屏体验,

在纵向模式下,布局的exoplayer视图覆盖了屏幕区域的一半,而其他视图则为textview,button,并且具有横向的单独布局,exoplayer视图与父视图相匹配并设置了其他视图。

肖像:

<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"
    android:background="@color/primary_light"
    tools:context=".ui.main.ViewRecipeStepFragment"
>

    <com.google.android.exoplayer2.ui.PlayerView
        android:id="@+id/ep_video_view"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginBottom="0dp"
        android:layout_marginLeft="0dp"
        android:layout_marginRight="0dp"
        android:layout_marginTop="0dp"
        app:layout_constraintBottom_toTopOf="@+id/horizontalHalf"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
    />

    <android.support.constraint.Guideline
        android:id="@+id/horizontalHalf"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintBottom_toTopOf="@+id/recipe_step_instruction"
        app:layout_constraintGuide_percent="0.5"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="256dp"/>

    <TextView
        android:id="@+id/recipe_step_instruction"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:layout_marginBottom="8dp"
        android:textAlignment="center"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="18sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/horizontalHalf"
        tools:text="Instructions"
    />
</android.support.constraint.ConstraintLayout>

要获得更好的人像体验,您可以使用以下方式隐藏系统控件(这将隐藏应用栏),(您可以在活动的onCreate()或onResume()中调用它)

    @SuppressLint("InlinedApi")
    private void hideSystemUi() {
        playerView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
    }

最后在横向模式下,将布局更新为类似的内容,

风景:

<?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=".ui.main.ViewRecipeStepFragment"
    android:background="@color/primary_light"
>

    <com.google.android.exoplayer2.ui.PlayerView
        android:id="@+id/ep_video_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="0dp"
        android:layout_marginRight="0dp"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginBottom="0dp"
        android:layout_marginLeft="0dp"
        app:layout_constraintLeft_toLeftOf="parent"
        />
</android.support.constraint.ConstraintLayout>