public async Task <PlayingOrchestrateResult> PreperePlayWithCache(VideoId videoId)
        {
            if (!InternetConnection.IsInternet())
            {
                return(new PlayingOrchestrateResult(PlayingOrchestrateFailedReason.RequireNetworkConnection));
            }

            var preparePlayVideo = await _nicoVideoSessionProvider.PreparePlayVideoAsync(videoId);

            var commentSessionProvider = preparePlayVideo;
            var nicoVideoDetails       = preparePlayVideo?.GetVideoDetails();

            return(new PlayingOrchestrateResult(
                       new CachedVideoSessionProvider(_videoCacheManager.GetVideoCache(videoId), _niconicoSession),
                       commentSessionProvider,
                       nicoVideoDetails
                       ));
        }
Пример #2
0
        /// <summary>
        /// 再生処理
        /// </summary>
        /// <returns></returns>
        public async Task <PlayingOrchestrateResult> CreatePlayingOrchestrateResultAsync(string videoId)
        {
            var cacheVideoResult = await _videoCacheManager.TryCreateCachedVideoSessionProvider(videoId);

            if (cacheVideoResult.IsSuccess)
            {
                INiconicoCommentSessionProvider commentSessionProvider = null;
                INicoVideoDetails nicoVideoDetails = null;
                if (!Models.Helpers.InternetConnection.IsInternet())
                {
                    var cachedComment = _commentRepository.GetCached(videoId);
                    if (cachedComment != null)
                    {
                        commentSessionProvider = new CachedCommentsProvider(videoId, cachedComment.Comments);
                    }

                    var videoInfo = Database.NicoVideoDb.Get(videoId);
                    if (videoInfo != null)
                    {
                        nicoVideoDetails = new CachedVideoDetails()
                        {
                            VideoTitle      = videoInfo.Title,
                            ViewCount       = videoInfo.ViewCount,
                            CommentCount    = videoInfo.CommentCount,
                            MylistCount     = videoInfo.MylistCount,
                            VideoLength     = videoInfo.Length,
                            SubmitDate      = videoInfo.PostedAt,
                            Tags            = videoInfo.Tags.Select(x => new NicoVideoTag(x.Id)).ToArray(),
                            ProviderId      = videoInfo.Owner?.OwnerId,
                            ProviderName    = videoInfo.Owner?.ScreenName,
                            OwnerIconUrl    = videoInfo.Owner.IconUrl,
                            DescriptionHtml = videoInfo.DescriptionWithHtml,
                            ThumbnailUrl    = videoInfo.ThumbnailUrl
                        };
                    }
                }
                else
                {
                    var preparePlayVideo = await _nicoVideoSessionProvider.PreparePlayVideoAsync(videoId);

                    commentSessionProvider = preparePlayVideo;
                    nicoVideoDetails       = preparePlayVideo?.GetVideoDetails();
                }

                // キャッシュからコメントを取得する方法が必要
                return(new PlayingOrchestrateResult(
                           cacheVideoResult.VideoSessionProvider,
                           commentSessionProvider,
                           nicoVideoDetails
                           ));
            }
            else
            {
                /*
                 * bool canPlay = true;
                 * var downloadLineOwnership = await _videoCacheManager.TryRentDownloadLineAsync();
                 * if (downloadLineOwnership == null)
                 * {
                 *  canPlay = false;
                 *  if (await ShowSuspendCacheDownloadingDialog())
                 *  {
                 *      await _videoCacheManager.SuspendCacheDownload();
                 *      canPlay = true;
                 *  }
                 * }
                 *
                 * if (!canPlay)
                 * {
                 *  return new PlayingOrchestrateResult();
                 * }
                 */

                var preparePlayVideo = await _nicoVideoSessionProvider.PreparePlayVideoAsync(videoId);

                if (!preparePlayVideo.IsSuccess)
                {
                    var progress = await _videoCacheManager.GetDownloadProgressVideosAsync();

                    if (!_niconicoSession.IsPremiumAccount && progress.Any())
                    {
                        var result = await ShowSuspendCacheDownloadingDialog();

                        if (result)
                        {
                            preparePlayVideo = await _nicoVideoSessionProvider.PreparePlayVideoAsync(videoId);
                        }
                    }
                }

                if (preparePlayVideo == null || !preparePlayVideo.IsSuccess)
                {
                    throw new NotSupportedException("不明なエラーにより再生できません");
                }

                return(new PlayingOrchestrateResult(
                           preparePlayVideo,
                           preparePlayVideo,
                           preparePlayVideo.GetVideoDetails()
                           ));
            }
        }