AVProVideoPlayer.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System;
  2. using System.IO;
  3. using RenderHeads.Media.AVProVideo;
  4. using UnityEngine;
  5. public class AVProVideoPlayer : MonoBehaviour
  6. {
  7. private void Awake()
  8. {
  9. this.m_player = base.GetComponent<MediaPlayer>();
  10. NDebug.Assert(this.m_player != null, "MediaPlayer コンポーネントが付いてないといけません。");
  11. this.m_player.m_VideoLocation = MediaPlayer.FileLocation.AbsolutePathOrURL;
  12. this.m_player.m_VideoPath = this.m_player.m_VideoPath.Replace("\\", "/");
  13. if (this.m_player.m_VideoPath.Contains("movie_temp/"))
  14. {
  15. this.m_player.m_VideoPath = this.m_player.m_VideoPath.Replace("movie_temp/", string.Empty);
  16. }
  17. if (this.m_player.m_VideoPath.Contains("/"))
  18. {
  19. this.m_player.m_VideoPath = UTY.gameProjectPath + "\\GameData\\" + this.m_player.m_VideoPath;
  20. }
  21. else
  22. {
  23. string path = UTY.gameProjectPath + "\\GameData\\";
  24. string[] directories = Directory.GetDirectories(path, "movie*", SearchOption.TopDirectoryOnly);
  25. bool flag = false;
  26. foreach (string path2 in directories)
  27. {
  28. foreach (string text in Directory.GetFiles(path2))
  29. {
  30. string fileName = Path.GetFileName(text);
  31. if (this.m_player.m_VideoPath == fileName)
  32. {
  33. flag = true;
  34. this.m_player.m_VideoPath = text;
  35. break;
  36. }
  37. }
  38. if (flag)
  39. {
  40. break;
  41. }
  42. }
  43. if (!flag)
  44. {
  45. Debug.LogErrorFormat("{0}がGameDataフォルダから見つかりませんでした", new object[]
  46. {
  47. this.m_player.m_VideoPath
  48. });
  49. return;
  50. }
  51. }
  52. string dshowFilter = GameMain.Instance.CMSystem.SConfig.DShowFilter;
  53. MediaPlayer.OptionsWindows platformOptionsWindows = this.m_player.PlatformOptionsWindows;
  54. if (!string.IsNullOrEmpty(dshowFilter))
  55. {
  56. platformOptionsWindows.preferredFilters.Add(dshowFilter);
  57. Debug.Log("[VideoPlayer] preferredFilters.Add(" + dshowFilter + ").");
  58. }
  59. else
  60. {
  61. Debug.Log("[VideoPlayer] SConfig.DShowFilter\u3000には値が設定されていませんでした。");
  62. }
  63. platformOptionsWindows.useHardwareDecoding = true;
  64. Debug.Log("[VideoPlayer] useHardwareDecoding = true.");
  65. platformOptionsWindows.videoApi = Windows.VideoApi.MediaFoundation;
  66. Debug.Log("[VideoPlayer] videoApi = " + platformOptionsWindows.videoApi.ToString());
  67. }
  68. private void Start()
  69. {
  70. bool flag = this.m_player.OpenVideoFromFile(MediaPlayer.FileLocation.AbsolutePathOrURL, this.m_player.m_VideoPath, false);
  71. if (!flag)
  72. {
  73. NDebug.MessageBox("エラー", "ビデオファイルを開けませんでした。\nファイルの存在=" + File.Exists(this.m_player.m_VideoPath).ToString() + "\n" + this.m_player.m_VideoPath);
  74. }
  75. if (flag && this.m_player.VideoOpened && this.m_bAutoStart)
  76. {
  77. this.Play();
  78. }
  79. }
  80. public void Play()
  81. {
  82. if (this.m_player.VideoOpened)
  83. {
  84. this.m_player.Play();
  85. }
  86. }
  87. public void Stop()
  88. {
  89. if (this.m_player.VideoOpened)
  90. {
  91. this.m_player.Stop();
  92. }
  93. }
  94. public void Speed(float f_fSpeed)
  95. {
  96. if (this.m_player.VideoOpened)
  97. {
  98. this.m_player.m_PlaybackRate = f_fSpeed;
  99. }
  100. }
  101. private MediaPlayer m_player;
  102. public bool m_bAutoStart;
  103. }