Esempio n. 1
0
        public void Dispose()
        {
            _Mss?.Dispose();
            _MediaSource?.Dispose();

            ExitLiveViewing().ConfigureAwait(false);

            Live2WebSocket?.Dispose();
            Live2WebSocket = null;
        }
Esempio n. 2
0
        public async Task <LiveStatusType?> SetupLive()
        {
            if (PlayerStatusResponse != null)
            {
                PlayerStatusResponse = null;

                await EndLiveSubscribe();

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

            LiveStatusType = await UpdateLiveStatus();

            await Task.Delay(500);

            Mntone.Nico2.Live.Watch.LeoPlayerProps leoPlayerProps = null;
            try
            {
                leoPlayerProps = await HohoemaApp.NiconicoContext.Live.GetLeoPlayerPropsAsync(LiveId);
            }
            catch { }

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

                LivePlayerType = Live.LivePlayerType.Leo;

                if (Live2WebSocket == null)
                {
                    Live2WebSocket = new Live2WebSocket(leoPlayerProps);
                    Live2WebSocket.RecieveCurrentStream += Live2WebSocket_RecieveCurrentStream;
                    Live2WebSocket.RecieveStatistics    += Live2WebSocket_RecieveStatistics;
                    Live2WebSocket.RecieveDisconnect    += Live2WebSocket_RecieveDisconnect;
                    await Live2WebSocket.StartAsync(HohoemaApp.UserSettings.PlayerSettings.DefaultLiveQuality);
                }

                await StartLiveSubscribe();

                return(LiveStatusType);
            }
            else
            {
                if (PlayerStatusResponse != null && LiveStatusType == null)
                {
                    LivePlayerType = Live.LivePlayerType.Aries;

                    await StartEnsureOpenRtmpConnection();

                    await StartLiveSubscribe();
                }

                return(LiveStatusType);
            }
        }
Esempio n. 3
0
        public void Dispose()
        {
            _Mss?.Dispose();
            _MediaSource?.Dispose();

            // 次枠検出を終了
            StopNextLiveDetection();

            ExitLiveViewing().ConfigureAwait(false);

            Live2WebSocket?.Dispose();
            Live2WebSocket = null;
        }
Esempio n. 4
0
        public async Task ChangeQualityRequest(string quality)
        {
            if (this.LivePlayerType == Live.LivePlayerType.Leo)
            {
                if (CurrentQuality == quality)
                {
                    return;
                }

                HohoemaApp.MediaPlayer.Source = null;

                RequestQuality = quality;
                await Live2WebSocket.SendChangeQualityMessageAsync(quality);
            }
        }
Esempio n. 5
0
        public void Dispose()
        {
            HohoemaApp.MediaPlayer.Source = null;

            _Mss?.Dispose();
            _MediaSource?.Dispose();

            // 次枠検出を終了
            StopNextLiveSubscribe().ConfigureAwait(false);

            EndLiveSubscribe().ConfigureAwait(false);

            Live2WebSocket?.Dispose();
            Live2WebSocket = null;
        }
Esempio n. 6
0
        public async Task ChangeQualityRequest(string quality, bool isLowLatency)
        {
            if (this.LivePlayerType == Live.LivePlayerType.Leo)
            {
                if (CurrentQuality == quality && _IsLowLatency == isLowLatency)
                {
                    return;
                }

                MediaPlayer.Source = null;

                RequestQuality = quality;
                _IsLowLatency  = isLowLatency;
                await Live2WebSocket.SendChangeQualityMessageAsync(quality, isLowLatency);
            }
        }
Esempio n. 7
0
        public async Task ChangeQualityRequest(string quality, bool isLowLatency)
        {
            if (this.LivePlayerType == Live.LivePlayerType.Leo)
            {
                if (CurrentQuality == quality && _IsLowLatency == isLowLatency)
                {
                    return;
                }

                if (IsWatchWithTimeshift)
                {
                    _LiveComments.Clear();
                    TimeshiftPosition = (TimeshiftPosition ?? TimeSpan.Zero) + MediaPlayer.PlaybackSession.Position;
                }

                MediaPlayer.Source = null;

                RequestQuality = quality;
                _IsLowLatency  = isLowLatency;

                await Live2WebSocket.SendChangeQualityMessageAsync(quality, isLowLatency);
            }
        }
Esempio n. 8
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 による放送は対応していません。");
            }
        }
Esempio n. 9
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();
                }
            }
        }