在ListView中夸大com.google.android.youtube.player.YouTubePlayerView类时出错

时间:2019-02-20 03:19:30

标签: xamarin.android mvvmcross youtubeplayer

我正在尝试使用Xamarin工具(适用于Android和iOS)熟悉 YoutubePlayerView Mvvmcross 模型

我想创建一个视频列表,当用户单击视频时,可以在ListView中播放 enter image description here

但是我在使用Android时遇到错误

二进制XML文件第1行:夸大类com.google.android.youtube.player.YouTubePlayerView

到目前为止,我的代码:

这是列表: VideoListView.axml:

<android.support.v4.widget.SwipeRefreshLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        local:MvxBind="Refresh RefreshCommand; Refreshing IsRefreshing">

        <dc.CustomMvxListView
            android:id="@+id/videoList"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </android.support.v4.widget.SwipeRefreshLayout>

VideoListItemView.axml:

<dc.AlphaLinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    local:MvxBind="Click ItemClickCommand">

    <!--Video Thumbnail-->
    <FrameLayout
        android:layout_width="@dimen/ProductImageWidth"
        android:layout_height="@dimen/ProductImageHeight"
        android:layout_margin="@dimen/ExtraNewsImagePadding">
        <com.google.android.youtube.player.YouTubePlayerView
        android:id="@+id/playerView"
        android:layout_width="@dimen/ProductImageWidth"
        android:layout_height="@dimen/ProductImageHeight"
        android:layout_margin="@dimen/ExtraNewsImagePadding"/>
    </FrameLayout>

    <!--Video information-->
    <LinearLayout
    ....
    </LinearLayout>

</dc.AlphaLinearLayout>

VideoListView.cs

   public class VideoListView : DetailViewWithShare
    {
        protected override int LayoutId => Resource.Layout.VideoListView;
        private CustomMvxListView _videoListview;

        protected override void InitView(View view)
        {
            _videoListview = view.FindViewById<CustomMvxListView>(Resource.Id.videoList);
            _videoListview.ItemTemplateId = Resource.Layout.VideoListItemView;
        }

        protected override void CreateBinding()
        {
            var bindingSet = this.CreateBindingSet<VideoListView, VideoListViewModel>();

            bindingSet.Bind(_videoListview.Adapter)
                .For(v => v.ItemsSource)
                .To(vm => vm.VideoItemViewModels);

            bindingSet.Bind(_videoListview)
                .For(v => v.ScrollToBottom)
                .To(vm => vm.ScrollToBottomCommand);

            bindingSet.Apply();
        }
}

VideoListItemView.cs

namespace Droid.Views.Video
{
    public class VideoListItemView : YouTubeFailureRecoveryActivity
    {
        private string _youtubeId;
        public string YoutubeId
        {
            get
            {
                return _youtubeId;
            }
            set
            {
                _youtubeId = value;
                _player.CueVideo(value);
            }
        }

        private IYouTubePlayer _player;
        protected override IYouTubePlayerProvider YouTubePlayerProvider => FindViewById<YouTubePlayerView>(Resource.Id.playerView);

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.VideoListItemView);

            var youtubeView = FindViewById<YouTubePlayerView>(Resource.Id.playerView);
            youtubeView.Initialize(DEVELOPER_KEY, this);

        }

        public override void OnInitializationSuccess(IYouTubePlayerProvider provider, IYouTubePlayer player, bool wasRestored)
        {
            if (!wasRestored)
            {
                _player = player;
            }
        }
    }

    public abstract class YouTubeFailureRecoveryActivity : YouTubeBaseActivity, IYouTubePlayerOnInitializedListener
    {
        public const int RecoveryDialogRequest = 1;
        public string DEVELOPER_KEY = "AIzaSyDQjcaioPiOuMCPcugUmUxTijoy3sTLXkM";

        public void OnInitializationFailure(IYouTubePlayerProvider provider, YouTubeInitializationResult errorReason)
        {
            if (errorReason.IsUserRecoverableError)
            {
                errorReason.GetErrorDialog(this, RecoveryDialogRequest).Show();
            }
            else
            {
                var errorMessage = string.Format("Error initializing YouTube player", errorReason.ToString());
                Toast.MakeText(this, errorMessage, ToastLength.Long).Show();
            }
        }

        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            if (requestCode == RecoveryDialogRequest)
            {
                // Retry initialization if user performed a recovery action
                YouTubePlayerProvider.Initialize(DEVELOPER_KEY, this);
            }
        }

        public abstract void OnInitializationSuccess(IYouTubePlayerProvider provider, IYouTubePlayer player, bool wasRestored);

        protected abstract IYouTubePlayerProvider YouTubePlayerProvider { get; }
    }
}

**由于其ViewModel用于iOS和Android,因此无法在ViewModel中实现YouTubeBaseActivity。

我需要做的是首先成功为Android扩展YoutubePlayer,然后再计算其余部分。**

做了很多研究,但是我还没有解决这个错误: 二进制XML文件的第1行:膨胀类com.google.android.youtube.player.YouTubePlayerView的错误

帮助!!!!

0 个答案:

没有答案