Example #1
0
        public async Task PlayAsync(NicoVideoQuality quality = NicoVideoQuality.Unknown, TimeSpan startPosition = default)
        {
            if (_niconicoVideoSessionProvider == null) { throw new ArgumentException("please call VideoPlayer.UpdatePlayingVideo() before VideoPlayer.PlayAsync()."); }

            if ((_currentSession as IVideoStreamingSession)?.Quality == quality)
            {
                return;
            }

            _currentSession?.Dispose();

            _currentSession = await _niconicoVideoSessionProvider.CreateVideoSessionAsync(quality);
            if (_currentSession is IVideoStreamingSession videoStreamingSession)
            {
                CurrentQuality = AvailableQualities.First(x => x.Quality == videoStreamingSession.Quality);
            }
            if (_currentSession is LocalVideoStreamingSession)
            {
                IsPlayWithCache.Value = true;
            }

            NowPlayingWithDmcVideo = _currentSession is Models.DmcVideoStreamingSession;
            
            await _currentSession.StartPlayback(_mediaPlayer, startPosition);
        }
 public NicoVideoCacheProgress(NicoVideoCacheRequest req, DownloadOperation op, IVideoStreamingDownloadSession session)
 {
     RawVideoId           = req.RawVideoId;
     Quality              = session.Quality;
     IsRequireForceUpdate = req.IsRequireForceUpdate;
     RequestAt            = req.RequestAt;
     DownloadOperation    = op;
     Session              = session;
 }
        /// <summary>
        /// 動画ストリームの取得します
        /// </summary>
        /// <exception cref="NotSupportedException" />
        public async Task <IStreamingSession> CreateVideoSessionAsync(NicoVideoQuality quality = NicoVideoQuality.Unknown)
        {
            IStreamingSession streamingSession = null;

            if (_watchApiResponse != null)
            {
                var ownership = await _ownershipManager.TryRentVideoSessionOwnershipAsync(_watchApiResponse.videoDetail.id, !IsForCacheDownload);

                if (ownership != null)
                {
                    streamingSession = new SmileVideoStreamingSession(
                        _watchApiResponse.VideoUrl,
                        _niconicoSession,
                        ownership
                        );
                }
            }
            else if (_dmcWatchData != null)
            {
                if (_dmcWatchData.DmcWatchResponse.Video.DmcInfo != null)
                {
                    var qualityEntity = AvailableQualities.Where(x => x.IsAvailable).FirstOrDefault(x => x.Quality == quality);
                    if (qualityEntity == null)
                    {
                        qualityEntity = AvailableQualities.Where(x => x.IsAvailable).First();
                    }

                    var ownership = await _ownershipManager.TryRentVideoSessionOwnershipAsync(_dmcWatchData.DmcWatchResponse.Video.Id, !IsForCacheDownload);

                    if (ownership != null)
                    {
                        streamingSession = new DmcVideoStreamingSession(qualityEntity.QualityId, _dmcWatchData, _niconicoSession, ownership);
                    }
                }
                else if (_dmcWatchData.DmcWatchResponse.Video.SmileInfo != null)
                {
                    var ownership = await _ownershipManager.TryRentVideoSessionOwnershipAsync(_dmcWatchData.DmcWatchResponse.Video.Id, !IsForCacheDownload);

                    if (ownership != null)
                    {
                        streamingSession = new SmileVideoStreamingSession(
                            new Uri(_dmcWatchData.DmcWatchResponse.Video.SmileInfo.Url), _niconicoSession, ownership);
                    }
                }
                else
                {
                    throw new NotSupportedException("動画ページ情報から動画ファイルURLを検出できませんでした");
                }
            }
            else
            {
                throw new NotSupportedException("動画の再生準備に失敗(動画ページの解析でエラーが発生)");
            }

            return(streamingSession);
        }
Example #4
0
        public void ClearCurrentSession()
        {
            _currentSession?.Dispose();
            _currentSession = null;
            _niconicoVideoSessionProvider = null;

            _currentQuality = null;
            RaisePropertyChanged(nameof(AvailableQualities));

            PlayingVideoId = null;
            NowPlayingWithDmcVideo = false;
            IsPlayWithCache.Value = false;
        }
Example #5
0
        public NicoVideoCacheProgress(DownloadOperation op, IVideoStreamingDownloadSession session, string videoId, NicoVideoQuality quality, DateTime requestAt)
        {
            DownloadOperation = op;
            Session           = session;
            VideoId           = videoId;
            Quality           = quality;
            RequestAt         = requestAt;

            _nicoVideo = Database.NicoVideoDb.Get(VideoId);
            SendUpdatableToastWithProgress();

            Progress = 0.0;
            _invertedProgressTotal = 1.0 / op.Progress.TotalBytesToReceive;
        }