Exemplo n.º 1
0
        /// <summary>
        /// 生放送情報を取得してライブストリームの受信を開始します。<br />
        /// 配信受信処理のハードリセット動作として機能します。
        /// </summary>
        /// <returns></returns>
        private async Task TryStartViewing()
        {
            if (NicoLiveVideo == null)
            {
                return;
            }

            try
            {
                MediaPlayer.PlaybackSession.PlaybackStateChanged += PlaybackSession_PlaybackStateChanged;

                NowUpdating.Value = true;

                var liveStatus = await NicoLiveVideo.SetupLive();

                if (liveStatus == null)
                {
                    LivePlayerType.Value = NicoLiveVideo.LivePlayerType;

                    OnPropertyChanged(nameof(MediaPlayer));
                    _StartAt = NicoLiveVideo.PlayerStatusResponse.Program.StartedAt;
                    _EndAt   = NicoLiveVideo.PlayerStatusResponse.Program.EndedAt;

                    await StartLiveElapsedTimer();

                    LiveTitle   = NicoLiveVideo.LiveTitle;
                    Title       = LiveTitle;
                    CommunityId = NicoLiveVideo.BroadcasterCommunityId;

                    // seet
                    RoomName = NicoLiveVideo.PlayerStatusResponse.Room.Name;
                    SeetId   = NicoLiveVideo.PlayerStatusResponse.Room.SeatId;

                    OnPropertyChanged(nameof(NicoLiveVideo));

                    if (CommunityName == null)
                    {
                        if (CommunityId == null)
                        {
                            CommunityId = NicoLiveVideo.BroadcasterCommunityId;
                        }

                        try
                        {
                            var communityDetail = await HohoemaApp.ContentFinder.GetCommunityInfo(CommunityId);

                            if (communityDetail.IsStatusOK)
                            {
                                CommunityName = communityDetail.Community.Name;
                            }
                        }
                        catch { }
                    }

                    if (NicoLiveVideo.LivePlayerType == Models.Live.LivePlayerType.Leo)
                    {
                        CanChangeQuality.Value = true;

                        NicoLiveVideo.ObserveProperty(x => x.RequestQuality)
                        .Subscribe(q =>
                        {
                            RequestQuality.Value = q;
                        });

                        NicoLiveVideo.ObserveProperty(x => x.CurrentQuality)
                        .Subscribe(x =>
                        {
                            CurrentQuality.Value = x;
                        });

                        NicoLiveVideo.ObserveProperty(x => x.Qualities)
                        .Subscribe(types =>
                        {
                            IsAvailableSuperLowQuality.Value = types?.Any(x => x == "super_low") ?? false;
                            IsAvailableLowQuality.Value      = types?.Any(x => x == "low") ?? false;
                            IsAvailableNormalQuality.Value   = types?.Any(x => x == "normal") ?? false;
                            IsAvailableHighQuality.Value     = types?.Any(x => x == "high") ?? false;

                            ChangeQualityCommand.RaiseCanExecuteChanged();
                        });
                    }
                }
                else
                {
                    Debug.WriteLine("生放送情報の取得失敗しました " + LiveId);
                }

                ResetSuggestion(liveStatus);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
            finally
            {
                NowUpdating.Value = false;
            }

            // コメント送信中にコメントクライアント切断した場合に対応
            NowSubmittingComment.Value = false;
        }
Exemplo n.º 2
0
        public override void OnNavigatedTo(NavigatedToEventArgs e, Dictionary <string, object> viewModelState)
        {
            if (e.Parameter is string)
            {
                var json    = e.Parameter as string;
                var payload = LiveVideoPagePayload.FromParameterString(json);

                LiveId        = payload.LiveId;
                LiveTitle     = payload.LiveTitle;
                CommunityId   = payload.CommunityId;
                CommunityName = payload.CommunityName;
            }

            if (LiveId != null)
            {
                NicoLiveVideo = new NicoLiveVideo(LiveId, HohoemaApp);

                NowConnecting = Observable.CombineLatest(
                    NicoLiveVideo.ObserveProperty(x => x.LiveStatusType).Select(x => x != null)
                    )
                                .Select(x => x.All(y => y))
                                .ToReactiveProperty(PlayerWindowUIDispatcherScheduler)
                                .AddTo(_NavigatingCompositeDisposable);
                OnPropertyChanged(nameof(NowConnecting));

                LiveComments = NicoLiveVideo.LiveComments.ToReadOnlyReactiveCollection(x =>
                {
                    var comment = new Views.Comment();

                    comment.CommentText    = x.Text;
                    comment.CommentId      = !string.IsNullOrEmpty(x.No) ? x.GetCommentNo() : 0;
                    comment.IsAnonimity    = !string.IsNullOrEmpty(x.Anonymity) ? x.GetAnonymity() : false;
                    comment.UserId         = x.User_id;
                    comment.IsOwnerComment = x.User_id == NicoLiveVideo?.BroadcasterId;

                    try
                    {
                        comment.IsLoginUserComment = !comment.IsAnonimity ? uint.Parse(x.User_id) == HohoemaApp.LoginUserId : false;
                    }
                    catch { }



                    //x.GetVposでサーバー上のコメント位置が取れるが、
                    // 受け取った順で表示したいのでローカルの放送時間からコメント位置を割り当てる
                    comment.VideoPosition = (uint)(MediaPlayer.PlaybackSession.Position.TotalMilliseconds * 0.1) + 50;

                    if (x.Vpos != null && x.GetVpos() < (comment.VideoPosition - 200))
                    {
                        Debug.WriteLine("古いコメントのため非表示 : " + comment.CommentText);
                        comment.IsVisible = false;
                    }

                    // EndPositionはコメントレンダラが再計算するが、仮置きしないと表示対象として処理されない
                    comment.EndPosition = comment.VideoPosition + 1000;

                    comment.ApplyCommands(x.GetCommandTypes());

                    return(comment);
                });

                OnPropertyChanged(nameof(LiveComments));

                CommentCount = NicoLiveVideo.ObserveProperty(x => x.CommentCount)
                               .ToReactiveProperty(PlayerWindowUIDispatcherScheduler)
                               .AddTo(_NavigatingCompositeDisposable);
                OnPropertyChanged(nameof(CommentCount));

                WatchCount = NicoLiveVideo.ObserveProperty(x => x.WatchCount)
                             .ToReactiveProperty(PlayerWindowUIDispatcherScheduler)
                             .AddTo(_NavigatingCompositeDisposable);
                OnPropertyChanged(nameof(WatchCount));

                CommunityId = NicoLiveVideo.BroadcasterCommunityId;


                // post comment
                NicoLiveVideo.PostCommentResult += NicoLiveVideo_PostCommentResult;

                // operation command
                PermanentDisplayText = NicoLiveVideo.ObserveProperty(x => x.PermanentDisplayText)
                                       .ToReactiveProperty(PlayerWindowUIDispatcherScheduler)
                                       .AddTo(_NavigatingCompositeDisposable);
                OnPropertyChanged(nameof(PermanentDisplayText));


                // next live
                NicoLiveVideo.NextLive += NicoLiveVideo_NextLive;
            }

            base.OnNavigatedTo(e, viewModelState);
        }