public void Play(PlaylistItem item) { // プレイリストアイテムが不正 var playlist = item.Owner; if (playlist == null || item == null || !playlist.PlaylistItems.Contains(item) ) { throw new Exception(); } Player.Playlist = playlist; CurrentPlaylist = playlist; Player.PlayStarted(item); OpenPlaylistItem?.Invoke(CurrentPlaylist, item); IsDisplayPlayer = true; ResetMediaPlayerCommand(); MediaPlayer.AudioCategory = MediaPlayerAudioCategory.Media; }
public void PlayLiveVideo(string liveId, string title = "") { OpenPlaylistItem?.Invoke(CurrentPlaylist, new LiveVideoPlaylistItem() { Type = PlaylistItemType.Live, ContentId = liveId, Title = title }); IsDisplayPlayer = true; }
public async void Play(PlaylistItem item) { // プレイリストアイテムが不正 var playlist = item.Owner; if (item.Type == PlaylistItemType.Video) { if (playlist == null || item == null || playlist.PlaylistItems.FirstOrDefault(x => x.ContentId == item.ContentId) == null ) { throw new Exception(); } } if (!HohoemaApp.IsPremiumUser && !HohoemaApp.CacheManager.CanAddDownloadLine) { // 一般ユーザーまたは未登録ユーザーの場合 // 視聴セッションを1つに制限するため、キャッシュダウンロードを止める必要がある // キャッシュ済みのアイテムを再生中の場合はダウンロード可能なので確認をスキップする bool playingVideoIsCached = false; var currentItem = item; if (currentItem != null && currentItem.Type == PlaylistItemType.Video) { var cachedItems = await HohoemaApp.CacheManager.GetCacheRequest(currentItem.ContentId); if (cachedItems.FirstOrDefault(x => x.ToCacheState() == NicoVideoCacheState.Cached) != null) { playingVideoIsCached = true; } } if (!playingVideoIsCached) { var currentDownloadingItems = await HohoemaApp.CacheManager.GetDownloadProgressVideosAsync(); var downloadingItem = currentDownloadingItems.FirstOrDefault(); var downloadingItemVideoInfo = Database.NicoVideoDb.Get(downloadingItem.RawVideoId); var dialogService = App.Current.Container.Resolve <Services.HohoemaDialogService>(); var totalSize = downloadingItem.DownloadOperation.Progress.TotalBytesToReceive; var receivedSize = downloadingItem.DownloadOperation.Progress.BytesReceived; var megaBytes = (totalSize - receivedSize) / 1000_000.0; var downloadProgressDescription = $"ダウンロード中\n{downloadingItemVideoInfo.Title}\n残り {megaBytes:0.0} MB ( {receivedSize / 1000_000.0:0.0} MB / {totalSize / 1000_000.0:0.0} MB)"; var isCancelCacheAndPlay = await dialogService.ShowMessageDialog("ニコニコのプレミアム会員以外は 視聴とダウンロードは一つしか同時に行えません。\n視聴を開始する場合、キャッシュは中止されます。またキャッシュを再開する場合はダウンロードは最初からやり直しになります。\n\n" + downloadProgressDescription, "キャッシュを中止して視聴を開始しますか?", "キャッシュを中止して視聴する", "何もしない"); if (isCancelCacheAndPlay) { await HohoemaApp.CacheManager.SuspendCacheDownload(); } else { return; } } } else if (!HohoemaApp.IsPremiumUser) { await HohoemaApp.CacheManager.SuspendCacheDownload(); } CurrentPlaylist = playlist; Player.PlayStarted(item); if (PlayerDisplayType == PlayerDisplayType.SecondaryView) { ShowVideoWithSecondaryView(item).ConfigureAwait(false); } else { IsDisplayMainViewPlayer = true; OpenPlaylistItem?.Invoke(CurrentPlaylist, item); } }