AVProVideoPlayer.cs 2.8 KB

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