Java Exoplayer在全屏模式下有意启动

Java Exoplayer在全屏模式下有意启动,java,android,android-layout,user-interface,exoplayer,Java,Android,Android Layout,User Interface,Exoplayer,我正试图在全屏模式下通过intent启动Exoplayer 只需将参数传递给意图,例如url和可能的标题 我试着查看文档和stackoverflow,但什么也找不到 这是我目前正在使用的代码,但效果很差 try { BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelector trackSelector = new DefaultTrackSelector(n

我正试图在全屏模式下通过intent启动Exoplayer

只需将参数传递给意图,例如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());
        }

有人能帮我一把吗?

Exoplayer在除全屏之外的所有方面都是一个非常好的玩家,所以处理全屏功能的最好方法是让活动只以横向为方向,或者如果你想同时使用纵向和横向模式,最好改变方向。检查这篇文章
但是如果你不想处理这些事情,我建议你把播放器换成JWPlayer或youtubeplayer。

这就是如何使用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>

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

景观:

<?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>


同时,感谢您的回答。我必须播放的视频不是youtube视频,因此我需要一个通用播放器,在那里我可以编辑ui,并且必须以全屏模式运行它。我想创建的图形类型是:你推荐什么,继续使用exoplayer?是的,exoplayer是最好的播放器之一,但如果你只想处理全屏,那么我推荐brightcove exoplayer,它源于exoplayer,而且他们拥有所有播放器中最好的文档,可以满足您的用例。试着使用它。这就是我当时通过修改exoplayer图形所能做到的:即使圆的东西仍然不能让我满意,你认为呢?我想在seekbar预览版中使用它的问题是:我读了你提到的文章,但我遗漏了一些东西:例如,我应该在FullscreenVideoActivity.java和MainActivity.java中添加什么?你知道我在哪里可以找到所有完整的示例代码吗?好的,我想告诉你,一旦完成,它看起来会很酷。然后,您希望通过intent启动exoplayer,因此intent应该是您的全屏活动,所有intent的启动以及在此之前所做的一切都应该进入主活动,并将全屏活动与主活动分开,即所有exo代码都应该进入全屏。是,另外,我想使用previwseekbar。但也有一些疑问。
<?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>