0

我正在android中尝试自定义youtupeplayerView。

我在 android YouTubePlayerView 中使用 FrameLayout。用于 youtube 控制(播放/暂停,SeekBar 前进/后退)自定义。Youtubeplayerview 视频正在加载,但突然播放器暂停了视频。为什么?视频无法继续播放

下面添加 XML 代码

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:orientation="vertical">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="1">
    <com.google.android.youtube.player.YouTubePlayerView
        android:id="@+id/demo_youtubeplayer"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:gravity="center"
    android:orientation="vertical">
    <TextView
        android:id="@+id/water_mark"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left|center"
        android:layout_marginLeft="30dp"
        android:alpha="0.50"
        android:padding="5dp"
        android:text="@string/water_mark"
        android:textColor="#66ffffff"
        android:textSize="20dp" />
</LinearLayout>

<LinearLayout
    android:id="@+id/video_title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="top"
    android:background="@android:color/transparent"
    android:gravity="center_vertical"
    android:orientation="vertical">
    <TextView
        android:id="@+id/youtubeview_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:ellipsize="marquee"
        android:fadingEdge="horizontal"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:padding="15dp"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@android:color/white" />
</LinearLayout>

<LinearLayout
    android:id="@+id/video_control"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="@android:color/transparent"
    android:gravity="center_vertical"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/youtube_playimg"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:background="@null"
        android:src="@drawable/ic_media_play" />

    <!--<ImageView
        android:id="@+id/pause_video"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:layout_weight="1"
        android:background="@null"
        android:src="@drawable/ic_media_pause" />-->

    <SeekBar
        android:id="@+id/video_seekbar"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:layout_weight="6"
        android:max="100"
        android:progress="0" />

    <TextView
        android:id="@+id/play_timetv"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:layout_weight="2"
        android:text="--:--"
        android:textColor="@android:color/white" />
</LinearLayout>

下面添加截图

播放/暂停和 SeekBar 使用 FrameLayout 覆盖屏幕

4

1 回答 1

0

根据 youtube android sdk 指南,其他视图不应覆盖 youtube 播放器,在您的 xml 中,其他视图位于 youtube 播放器上方

public static final YouTubePlayer.ErrorReason UNAUTHORIZED_OVERLAY 由于视图覆盖播放器,播放已停止。播放视频时,不允许在播放器顶部覆盖视图。

报告此错误时,将在设备日志中打印一条消息,其中包含有关哪个视图覆盖播放器以及重叠位置的信息。

https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubePlayer.ErrorReason

于 2020-01-30T11:38:38.513 回答