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); }
/// <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); }