YouTubePlayerView失去亮度

时间:2019-08-13 21:34:13

标签: android xamarin android-youtube-api

我在带有 val df= spark.readStream.format("kafka").option("kafka.bootstrap.servers", "broker:port").option("subscribe", "mytopic").option("consumer.config", "/full_path_to/client.properties").load() 和NoTitle的活动中使用com.google.android.youtube.player.YouTubePlayerView。我的问题是Theme Dialog在常规尺寸的视图中会失去亮度,但在全屏模式下却可以正常工作。如何解决亮度问题?

YoutubePlayerView
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@color/transparent"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_centerInParent="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <com.google.android.youtube.player.YouTubePlayerView
            android:id="@+id/youtube_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:elevation="99dp"
        />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:background="#ffffff"
            android:orientation="horizontal">
            <ImageButton
                android:id="@+id/BackVideoBtn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="10dp"
                android:src="@drawable/media_left_nav"
                android:background="@color/transparent" />
            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:padding="10dp">
                <TextView
                    android:id="@+id/VideoLabel"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="20sp"
                    android:text="1/2"
                    android:textColor="#555555" />
            </RelativeLayout>
            <ImageButton
                android:id="@+id/NextVideoBtn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="10dp"
                android:src="@drawable/media_right_nav"
                android:background="@color/transparent" />
        </LinearLayout>
    </LinearLayout>
</RelativeLayout>

图像:

Video not started

Playing video

[已解决] 该问题是由使用Dialog触发的。更改为Theme.Transparent,并且可以正常工作。

1 个答案:

答案 0 :(得分:0)

我在一边使用com.google.android.youtube.player.YouTubePlayerView,但是无论是否全屏显示,我都具有相同的亮度。这是有关YouTuBePlayerView的代码。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.youtube.player.YouTubePlayerView
    android:id="@+id/youtube_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
</LinearLayout>

public class MainActivity : YouTubeBaseActivity, IYouTubePlayerOnInitializedListener
{
    private int RECOVERY_DIALOG_REQUEST = 1;

    public void OnInitializationFailure(IYouTubePlayerProvider provider, YouTubeInitializationResult errorReason)
    {
        if (errorReason.IsUserRecoverableError)
        {
            errorReason.GetErrorDialog(this, RECOVERY_DIALOG_REQUEST).Show();
        }
        else
        {
            String errorMessage = String.Format(
                    GetString(Resource.String.ErrorMessage), errorReason.ToString());
            Toast.MakeText(this, errorMessage, ToastLength.Long).Show();
        }
    }
    public void OnInitializationSuccess(IYouTubePlayerProvider p0, IYouTubePlayer yPlayer, bool p2)
    {

        yPlayer.LoadVideo(DevConstants.VIDEO_ID);
    }

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.activity_main);
        YouTubePlayerView youTubeView = FindViewById<YouTubePlayerView>(Resource.Id.youtube_view);
        youTubeView.Initialize(DevConstants.DEVELOPER_KEY, this);
    }
}

 public static class DevConstants
{
    public static string DEVELOPER_KEY = "YOUR DEVELOPER KEY";
    public static string VIDEO_ID = "_OBlgSz8sSM";
}

enter image description here