Example #1
0
        private async void EnsureOpenRtmpConnectionInntenal(object state = null)
        {
            if (DateTime.Now > EnsureOpenRtmpStartTime + EnsureOpenRtmpTryDuration)
            {
                await ExitEnsureOpenRtmpConnection();

                FailedOpenLive?.Invoke(this, new FailedOpenLiveEventArgs()
                {
                    Message = "次の配信が見つかりませんでした"
                });

                return;
            }

            Debug.WriteLine("TRY ensure open rtmp connection ");


            bool isDone = false;

            using (var releaser = await _VideoStreamSrouceAssignLock.LockAsync())
            {
                isDone = VideoStreamSource != null;
            }


            if (!isDone)
            {
                Debug.WriteLine("AGEIN ensure open rtmp connection ");

                await HohoemaApp.UIDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
                {
                    await CloseRtmpConnection();

                    await Task.Delay(1000);

                    await OpenRtmpConnection(PlayerStatusResponse);
                });
            }
            else
            {
                Debug.WriteLine("DETECT ensure open rtmp connection");

                await ExitEnsureOpenRtmpConnection();
            }
        }
Example #2
0
        private async Task OpenRtmpConnection(PlayerStatusResponse res)
        {
            await CloseRtmpConnection();

            using (var releaser = await _RtmpClientAssignLock.LockAsync())
            {
                if (_RtmpClient == null)
                {
                    _RtmpClient = new NicovideoRtmpClient();

                    _RtmpClient.Started += _RtmpClient_Started;
                    _RtmpClient.Stopped += _RtmpClient_Stopped;

                    try
                    {
                        await _RtmpClient.ConnectAsync(res);
                    }
                    catch (Exception ex)
                    {
                        _RtmpClient.Started -= _RtmpClient_Started;
                        _RtmpClient.Stopped -= _RtmpClient_Stopped;
                        _RtmpClient.Dispose();
                        _RtmpClient = null;
                        _EnsureStartLiveTimer?.Dispose();
                        _EnsureStartLiveTimer = null;

                        Debug.WriteLine("CAN NOT play Rtmp, Stop ensure open timer. : " + res.Stream.RtmpUrl);

                        FailedOpenLive?.Invoke(this, new FailedOpenLiveEventArgs()
                        {
                            Exception = ex,
                            Message   = "動画引用放送は未対応です"
                        });
                    }
                }
            }
        }
Example #3
0
        public async Task StartLiveWatchingSessionAsync()
        {
            if (LiveInfo != null)
            {
                LiveInfo = null;

                await ExitLiveViewing();

                await Task.Delay(TimeSpan.FromSeconds(1));
            }

            try
            {
                await UpdateLiveStatus();
            }
            catch { }

            TimeshiftPosition = LiveInfo.VideoInfo.Video.StartTime - LiveInfo.VideoInfo.Video.OpenTime;

            if (IsWatchWithTimeshift)
            {
                _StartTimeOffset = (DateTimeOffset.Now.ToOffset(JapanTimeZoneOffset) - LiveInfo.VideoInfo.Video.OpenTime) ?? TimeSpan.Zero;
            }
            else
            {
                _StartTimeOffset = TimeSpan.Zero;
            }


            // タイムシフトでの視聴かつタイムシフトの視聴予約済みかつ視聴権が未取得の場合は
            // 視聴権の使用を確認する
            if (_TimeshiftProgram?.GetReservationStatus() == Mntone.Nico2.Live.ReservationsInDetail.ReservationStatus.FIRST_WATCH)
            {
                var dialog = App.Current.Container.Resolve <Services.DialogService>();


                // 視聴権に関する詳細な情報提示

                // 視聴権の利用期限は 24H+放送時間 まで
                // ただし公開期限がそれより先に来る場合には公開期限が視聴期限となる
                var    outdatedTime = DateTimeOffset.Now.ToOffset(JapanTimeZoneOffset) + (LiveInfo.VideoInfo.Video.EndTime - LiveInfo.VideoInfo.Video.StartTime) + TimeSpan.FromHours(24);
                string desc         = string.Empty;
                if (outdatedTime > _TimeshiftProgram.ExpiredAt)
                {
                    outdatedTime = _TimeshiftProgram.ExpiredAt.LocalDateTime;
                    desc         = $"この放送のタイムシフト視聴を開始しますか?\r公開期限内に限って繰り返し視聴できます。\r\r公開期限:{_TimeshiftProgram.ExpiredAt.ToString("g")}";
                }
                else
                {
                    desc = $"この放送のタイムシフト視聴を開始しますか?\r視聴開始を起点に視聴期限が設定されます。視聴期限内に限って繰り返し視聴できます。\r\r推定視聴期限:{outdatedTime.Value.ToString("g")}";
                }
                var result = await dialog.ShowMessageDialog(
                    desc
                    , _TimeshiftProgram.Title, "視聴する", "キャンセル"
                    );

                if (result)
                {
                    var token = await LoginUserLiveReservationProvider.GetReservationTokenAsync();

                    await Task.Delay(500);

                    await LoginUserLiveReservationProvider.UseReservationAsync(_TimeshiftProgram.Id, token);

                    await Task.Delay(3000);

                    // タイムシフト予約一覧を更新
                    // 視聴権利用を開始したアイテムがFIRST_WATCH以外の視聴可能を示すステータスになっているはず
                    await RefreshTimeshiftProgram();

                    Debug.WriteLine("use reservation after status: " + _TimeshiftProgram.Status);
                }
            }


            try
            {
                _PlayerProps = await NicoLiveProvider.GetLeoPlayerPropsAsync(LiveId);
            }
            catch (Exception ex)
            {
                FailedOpenLive?.Invoke(this, new FailedOpenLiveEventArgs()
                {
                    Exception = ex,
                    Message   = "サービスからの応答がありません"
                });

                LiveStatus = StatusType.Invalid;
            }

            if (_PlayerProps != null)
            {
                Debug.WriteLine(_PlayerProps.Program.BroadcastId);

                LivePlayerType = Live.LivePlayerType.Leo;

                if (Live2WebSocket == null)
                {
                    Live2WebSocket = new Live2WebSocket(_PlayerProps);
                    Live2WebSocket.RecieveCurrentStream += Live2WebSocket_RecieveCurrentStream;
                    Live2WebSocket.RecieveStatistics    += Live2WebSocket_RecieveStatistics;
                    Live2WebSocket.RecieveDisconnect    += Live2WebSocket_RecieveDisconnect;
                    Live2WebSocket.RecieveCurrentRoom   += Live2WebSocket_RecieveCurrentRoom;
                    var quality = PlayerSettings.DefaultLiveQuality;

                    _IsLowLatency = PlayerSettings.LiveWatchWithLowLatency;
                    await Live2WebSocket.StartAsync(quality, _IsLowLatency);
                }

                await StartLiveViewing();
            }
            else
            {
                throw new NotSupportedException("RTMP による放送は対応していません。");
            }
        }
Example #4
0
        public async Task StartLiveWatchingSessionAsync()
        {
            if (PlayerStatusResponse != null)
            {
                PlayerStatusResponse = null;

                await ExitLiveViewing();

                await Task.Delay(TimeSpan.FromSeconds(1));
            }

            await UpdateLiveStatus();

            Mntone.Nico2.Live.Watch.Crescendo.CrescendoLeoProps leoPlayerProps = null;
            try
            {
                leoPlayerProps = await HohoemaApp.NiconicoContext.Live.GetCrescendoLeoPlayerPropsAsync(LiveId);
            }
            catch (Exception ex)
            {
                FailedOpenLive?.Invoke(this, new FailedOpenLiveEventArgs()
                {
                    Exception = ex,
                    Message   = "サービスからの応答がありません"
                });

                LiveStatusType = Live.LiveStatusType.ServiceTemporarilyUnavailable;
            }

            if (leoPlayerProps != null)
            {
                Debug.WriteLine(leoPlayerProps.Program.BroadcastId);

                LivePlayerType = Live.LivePlayerType.Leo;

                if (Live2WebSocket == null)
                {
                    Live2WebSocket = new Live2WebSocket(leoPlayerProps);
                    Live2WebSocket.RecieveCurrentStream += Live2WebSocket_RecieveCurrentStream;
                    Live2WebSocket.RecieveStatistics    += Live2WebSocket_RecieveStatistics;
                    Live2WebSocket.RecieveDisconnect    += Live2WebSocket_RecieveDisconnect;
                    Live2WebSocket.RecieveCurrentRoom   += Live2WebSocket_RecieveCurrentRoom;
                    var quality = HohoemaApp.UserSettings.PlayerSettings.DefaultLiveQuality;
                    if (BroadcasterCommunityType != CommunityType.Community)
                    {
                        quality = "high";
                    }

                    _IsLowLatency = HohoemaApp.UserSettings.PlayerSettings.LiveWatchWithLowLatency;
                    await Live2WebSocket.StartAsync(quality, _IsLowLatency);
                }

                await StartLiveViewing();

                // ログイン無し視聴に対応しているため
                // 旧APIからログイン無しと応答があっても無視して
                // 視聴を継続させる
                if (LiveStatusType == LiveStatusType.NotLogin)
                {
                    LiveStatusType = default(LiveStatusType);
                }
            }
            else
            {
//                await Task.Delay(500);

//                await UpdateLiveStatus();

                if (PlayerStatusResponse != null && LiveStatusType == LiveStatusType.OnAir)
                {
                    Debug.WriteLine(PlayerStatusResponse.Stream.RtmpUrl);
                    Debug.WriteLine(PlayerStatusResponse.Stream.Contents.Count);

                    LivePlayerType = Live.LivePlayerType.Aries;

                    await StartEnsureOpenRtmpConnection();

                    await StartLiveViewing();

                    // 旧プレイヤーの場合のみ、古いコメントクライアントでコメント受信
                    StartCommentClientConnection();
                }
            }
        }