public void OpenData(string filename, int number) { // JSON読み込み var wc = new WebClient(); wc.OpenReadCompleted += (_s, _e) => { if (_e.Error == null) { // JSONファイルをMediaクラスのインスタンスに逆シリアル化 var ser = new DataContractJsonSerializer(typeof(MediaData.Media)); try { MediaData.media.Add((MediaData.Media)ser.ReadObject(_e.Result)); debugTextBox.Text = string.Empty; } catch { debugTextBox.Text = "JSONファイルの記述に誤りがあります.:" + filename; return; } // 動画ソースへ var movieSet = new MediaData.MovieSet(); movieSet.viewList = new Dictionary<string, AdaptMediaPlayer.Controls.MediaPlayer>(); movieSet.playerPosition = number; for (var urlPos = 0; urlPos < MediaData.media[MediaData.media.Count - 1].video.Count; urlPos++) { var player = new Controls.MediaPlayer(); player.sb = new Storyboard { Duration = TimeSpan.FromMinutes(30) // 時間は適当 }; // Mediaとひも付け player.media = MediaData.media[MediaData.media.Count - 1]; player.movie.Source = new Uri(MediaData.baseUri, player.media.video[urlPos].url); player.title.Text = player.media.title; player.movie_index = MediaData.media.Count - 1; player.Margin = new Thickness(8, 8, 0, 0); Canvas.SetLeft(player, 340 * number); Canvas.SetTop(player, 0); // JSONからアニメーションを生成 // rectangle編 foreach (var value in player.media.video[0].rectangle) // 決め打ち { // 四角を作る var rect = new Rectangle { Height = value.height[0], Width = value.width[0], Stroke = new SolidColorBrush(TransColor(value.color)), StrokeThickness = 2, Visibility = Visibility.Collapsed }; Canvas.SetLeft(rect, value.left[0]); Canvas.SetTop(rect, value.top[0]); player.anime.Children.Add(rect); // アニメの定義 var anim = new ObjectAnimationUsingKeyFrames(); // 四角を出す var frame1 = new DiscreteObjectKeyFrame(); frame1.KeyTime = TimeSpan.Zero; frame1.Value = Visibility.Visible; // 四角を消す var frame2 = new DiscreteObjectKeyFrame(); frame2.KeyTime = TimeSpan.Parse(value.time[value.time.Count - 1]) - TimeSpan.Parse(value.time[0]); frame2.Value = Visibility.Collapsed; anim.KeyFrames.Add(frame1); anim.KeyFrames.Add(frame2); anim.BeginTime = TimeSpan.Parse(value.time[0]); // Storyboardの定義 player.sb.Children.Add(anim); Storyboard.SetTarget(anim, rect); Storyboard.SetTargetProperty(anim, new PropertyPath(VisibilityProperty)); // 長方形の変形・移動を設定する if (value.height.Count >= 2) { var animeHeight = new DoubleAnimationUsingKeyFrames(); var animeWidth = new DoubleAnimationUsingKeyFrames(); var animeLeft = new DoubleAnimationUsingKeyFrames(); var animeTop = new DoubleAnimationUsingKeyFrames(); for (var i = 1; i < value.time.Count; i++) { // 四角の変形 : Height var animeHeightKeyFrame = new LinearDoubleKeyFrame { KeyTime = TimeSpan.Parse(value.time[i]), Value = value.height[i] }; animeHeight.KeyFrames.Add(animeHeightKeyFrame); // 四角の変形 : Width var animeWidthKeyFrame = new LinearDoubleKeyFrame { KeyTime = TimeSpan.Parse(value.time[i]), Value = value.width[i] }; animeWidth.KeyFrames.Add(animeWidthKeyFrame); // 四角の移動 : Left var animeLeftKeyFrame = new LinearDoubleKeyFrame { KeyTime = TimeSpan.Parse(value.time[i]), Value = value.left[i] }; animeLeft.KeyFrames.Add(animeLeftKeyFrame); // 四角の移動 : Top var animeTopKeyFrame = new LinearDoubleKeyFrame { KeyTime = TimeSpan.Parse(value.time[i]), Value = value.top[i] }; animeTop.KeyFrames.Add(animeTopKeyFrame); } player.sb.Children.Add(animeHeight); Storyboard.SetTarget(animeHeight, rect); Storyboard.SetTargetProperty(animeHeight, new PropertyPath(Rectangle.HeightProperty)); player.sb.Children.Add(animeWidth); Storyboard.SetTarget(animeWidth, rect); Storyboard.SetTargetProperty(animeWidth, new PropertyPath(Rectangle.WidthProperty)); player.sb.Children.Add(animeLeft); Storyboard.SetTarget(animeLeft, rect); Storyboard.SetTargetProperty(animeLeft, new PropertyPath(Canvas.LeftProperty)); player.sb.Children.Add(animeTop); Storyboard.SetTarget(animeTop, rect); Storyboard.SetTargetProperty(animeTop, new PropertyPath(Canvas.TopProperty)); } } // text編 foreach (var value in player.media.video[0].text) // 決め打ち { // テキストを作る var str = new TextBlock { Text = value.text, FontSize = 18, Foreground = new SolidColorBrush(TransColor(value.color)), Visibility = Visibility.Collapsed }; Canvas.SetLeft(str, value.left[0]); Canvas.SetTop(str, value.top[0]); player.anime.Children.Add(str); // アニメの定義 var anim = new ObjectAnimationUsingKeyFrames(); // テキストを出す var frame1 = new DiscreteObjectKeyFrame(); frame1.KeyTime = TimeSpan.Zero; frame1.Value = Visibility.Visible; // テキストを消す var frame2 = new DiscreteObjectKeyFrame(); frame2.KeyTime = TimeSpan.Parse(value.time[1]) - TimeSpan.Parse(value.time[0]); frame2.Value = Visibility.Collapsed; anim.KeyFrames.Add(frame1); anim.KeyFrames.Add(frame2); anim.BeginTime = TimeSpan.Parse(value.time[0]); // Storyboardの定義 player.sb.Children.Add(anim); Storyboard.SetTarget(anim, str); Storyboard.SetTargetProperty(anim, new PropertyPath(VisibilityProperty)); } // プレイヤーを追加 playerArea.Children.Add(player); // 最初に表示するプレイヤーを決定 movieSet.viewList.Add(player.media.video[urlPos].viewpoint, player); if (urlPos == 0) { movieSet.currentPlayer = player; } else { player.Visibility = Visibility.Collapsed; } } MediaData.movieList.Add(movieSet); // カメラ切替ボタン生成 if (MediaData.media.Count == 1) { foreach (var value in MediaData.media[0].video) // 決め打ち { var buttonChange = new Button { Content = value.viewpoint, FontSize = 18, Width = 80 }; Canvas.SetTop(buttonChange, 35 * MediaData.media[0].video.IndexOf(value)); // 決め打ち buttonChange.Click += new RoutedEventHandler(ChangeCamera); ChangeCameraArea.Children.Add(buttonChange); var buttonEx = new Button { Content = value.viewpoint, FontSize = 18, Width = 80 }; Canvas.SetTop(buttonEx, 35 * (MediaData.media[0].video.IndexOf(value) + 1)); // 決め打ち buttonEx.Click += new RoutedEventHandler(ExCamera); ExCamaraArea.Children.Add(buttonEx); } } // JSON変更ボタン var openJsonButton = new Image { Source = new BitmapImage(new Uri("../image/Open.png", UriKind.Relative)), Height = 24, Width = 24, Margin = new Thickness(8, 8, 0, 0), Tag = movieSet.playerPosition }; Canvas.SetLeft(openJsonButton, 288 + 340 * movieSet.playerPosition); openJsonButton.MouseLeftButtonDown += new MouseButtonEventHandler(OpenJsonFile); openFileButtonArea.Children.Add(openJsonButton); } else { // エラー処理 debugTextBox.Text = _e.Error.ToString(); } }; wc.OpenReadAsync(new Uri(MediaData.baseUri, filename)); }
public void OpenData(string filename, int number) { // JSON読み込み var wc = new WebClient(); wc.OpenReadCompleted += (_s, _e) => { if (_e.Error == null) { // JSONファイルをMediaクラスのインスタンスに逆シリアル化 var ser = new DataContractJsonSerializer(typeof(MediaData.Media)); try { MediaData.media.Add((MediaData.Media)ser.ReadObject(_e.Result)); debugTextBox.Text = string.Empty; } catch { debugTextBox.Text = "JSONファイルの記述に誤りがあります.:" + filename; return; } // 動画ソースへ var movieSet = new MediaData.MovieSet(); movieSet.viewList = new Dictionary <string, AdaptMediaPlayer.Controls.MediaPlayer>(); movieSet.playerPosition = number; for (var urlPos = 0; urlPos < MediaData.media[MediaData.media.Count - 1].video.Count; urlPos++) { var player = new Controls.MediaPlayer(); player.sb = new Storyboard { Duration = TimeSpan.FromMinutes(30) // 時間は適当 }; // Mediaとひも付け player.media = MediaData.media[MediaData.media.Count - 1]; player.movie.Source = new Uri(MediaData.baseUri, player.media.video[urlPos].url); player.title.Text = player.media.title; player.movie_index = MediaData.media.Count - 1; player.Margin = new Thickness(8, 8, 0, 0); Canvas.SetLeft(player, 340 * number); Canvas.SetTop(player, 0); // JSONからアニメーションを生成 // rectangle編 foreach (var value in player.media.video[0].rectangle) // 決め打ち { // 四角を作る var rect = new Rectangle { Height = value.height[0], Width = value.width[0], Stroke = new SolidColorBrush(TransColor(value.color)), StrokeThickness = 2, Visibility = Visibility.Collapsed }; Canvas.SetLeft(rect, value.left[0]); Canvas.SetTop(rect, value.top[0]); player.anime.Children.Add(rect); // アニメの定義 var anim = new ObjectAnimationUsingKeyFrames(); // 四角を出す var frame1 = new DiscreteObjectKeyFrame(); frame1.KeyTime = TimeSpan.Zero; frame1.Value = Visibility.Visible; // 四角を消す var frame2 = new DiscreteObjectKeyFrame(); frame2.KeyTime = TimeSpan.Parse(value.time[value.time.Count - 1]) - TimeSpan.Parse(value.time[0]); frame2.Value = Visibility.Collapsed; anim.KeyFrames.Add(frame1); anim.KeyFrames.Add(frame2); anim.BeginTime = TimeSpan.Parse(value.time[0]); // Storyboardの定義 player.sb.Children.Add(anim); Storyboard.SetTarget(anim, rect); Storyboard.SetTargetProperty(anim, new PropertyPath(VisibilityProperty)); // 長方形の変形・移動を設定する if (value.height.Count >= 2) { var animeHeight = new DoubleAnimationUsingKeyFrames(); var animeWidth = new DoubleAnimationUsingKeyFrames(); var animeLeft = new DoubleAnimationUsingKeyFrames(); var animeTop = new DoubleAnimationUsingKeyFrames(); for (var i = 1; i < value.time.Count; i++) { // 四角の変形 : Height var animeHeightKeyFrame = new LinearDoubleKeyFrame { KeyTime = TimeSpan.Parse(value.time[i]), Value = value.height[i] }; animeHeight.KeyFrames.Add(animeHeightKeyFrame); // 四角の変形 : Width var animeWidthKeyFrame = new LinearDoubleKeyFrame { KeyTime = TimeSpan.Parse(value.time[i]), Value = value.width[i] }; animeWidth.KeyFrames.Add(animeWidthKeyFrame); // 四角の移動 : Left var animeLeftKeyFrame = new LinearDoubleKeyFrame { KeyTime = TimeSpan.Parse(value.time[i]), Value = value.left[i] }; animeLeft.KeyFrames.Add(animeLeftKeyFrame); // 四角の移動 : Top var animeTopKeyFrame = new LinearDoubleKeyFrame { KeyTime = TimeSpan.Parse(value.time[i]), Value = value.top[i] }; animeTop.KeyFrames.Add(animeTopKeyFrame); } player.sb.Children.Add(animeHeight); Storyboard.SetTarget(animeHeight, rect); Storyboard.SetTargetProperty(animeHeight, new PropertyPath(Rectangle.HeightProperty)); player.sb.Children.Add(animeWidth); Storyboard.SetTarget(animeWidth, rect); Storyboard.SetTargetProperty(animeWidth, new PropertyPath(Rectangle.WidthProperty)); player.sb.Children.Add(animeLeft); Storyboard.SetTarget(animeLeft, rect); Storyboard.SetTargetProperty(animeLeft, new PropertyPath(Canvas.LeftProperty)); player.sb.Children.Add(animeTop); Storyboard.SetTarget(animeTop, rect); Storyboard.SetTargetProperty(animeTop, new PropertyPath(Canvas.TopProperty)); } } // text編 foreach (var value in player.media.video[0].text) // 決め打ち { // テキストを作る var str = new TextBlock { Text = value.text, FontSize = 18, Foreground = new SolidColorBrush(TransColor(value.color)), Visibility = Visibility.Collapsed }; Canvas.SetLeft(str, value.left[0]); Canvas.SetTop(str, value.top[0]); player.anime.Children.Add(str); // アニメの定義 var anim = new ObjectAnimationUsingKeyFrames(); // テキストを出す var frame1 = new DiscreteObjectKeyFrame(); frame1.KeyTime = TimeSpan.Zero; frame1.Value = Visibility.Visible; // テキストを消す var frame2 = new DiscreteObjectKeyFrame(); frame2.KeyTime = TimeSpan.Parse(value.time[1]) - TimeSpan.Parse(value.time[0]); frame2.Value = Visibility.Collapsed; anim.KeyFrames.Add(frame1); anim.KeyFrames.Add(frame2); anim.BeginTime = TimeSpan.Parse(value.time[0]); // Storyboardの定義 player.sb.Children.Add(anim); Storyboard.SetTarget(anim, str); Storyboard.SetTargetProperty(anim, new PropertyPath(VisibilityProperty)); } // プレイヤーを追加 playerArea.Children.Add(player); // 最初に表示するプレイヤーを決定 movieSet.viewList.Add(player.media.video[urlPos].viewpoint, player); if (urlPos == 0) { movieSet.currentPlayer = player; } else { player.Visibility = Visibility.Collapsed; } } MediaData.movieList.Add(movieSet); // カメラ切替ボタン生成 if (MediaData.media.Count == 1) { foreach (var value in MediaData.media[0].video) // 決め打ち { var buttonChange = new Button { Content = value.viewpoint, FontSize = 18, Width = 80 }; Canvas.SetTop(buttonChange, 35 * MediaData.media[0].video.IndexOf(value)); // 決め打ち buttonChange.Click += new RoutedEventHandler(ChangeCamera); ChangeCameraArea.Children.Add(buttonChange); var buttonEx = new Button { Content = value.viewpoint, FontSize = 18, Width = 80 }; Canvas.SetTop(buttonEx, 35 * (MediaData.media[0].video.IndexOf(value) + 1)); // 決め打ち buttonEx.Click += new RoutedEventHandler(ExCamera); ExCamaraArea.Children.Add(buttonEx); } } // JSON変更ボタン var openJsonButton = new Image { Source = new BitmapImage(new Uri("../image/Open.png", UriKind.Relative)), Height = 24, Width = 24, Margin = new Thickness(8, 8, 0, 0), Tag = movieSet.playerPosition }; Canvas.SetLeft(openJsonButton, 288 + 340 * movieSet.playerPosition); openJsonButton.MouseLeftButtonDown += new MouseButtonEventHandler(OpenJsonFile); openFileButtonArea.Children.Add(openJsonButton); } else { // エラー処理 debugTextBox.Text = _e.Error.ToString(); } }; wc.OpenReadAsync(new Uri(MediaData.baseUri, filename)); }