AVProVideoPlayer.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 = Path.GetFullPath(".\\") + "GameData\\" + this.m_player.m_VideoPath;
  13. string dshowFilter = GameMain.Instance.CMSystem.SConfig.DShowFilter;
  14. MediaPlayer.OptionsWindows platformOptionsWindows = this.m_player.PlatformOptionsWindows;
  15. if (!string.IsNullOrEmpty(dshowFilter))
  16. {
  17. platformOptionsWindows.preferredFilters.Add(dshowFilter);
  18. Debug.Log("[VideoPlayer] preferredFilters.Add(" + dshowFilter + ").");
  19. }
  20. else
  21. {
  22. Debug.Log("[VideoPlayer] SConfig.DShowFilter\u3000には値が設定されていませんでした。");
  23. }
  24. platformOptionsWindows.useHardwareDecoding = true;
  25. Debug.Log("[VideoPlayer] useHardwareDecoding = true.");
  26. platformOptionsWindows.videoApi = Windows.VideoApi.MediaFoundation;
  27. Debug.Log("[VideoPlayer] videoApi = " + platformOptionsWindows.videoApi.ToString());
  28. }
  29. private void Start()
  30. {
  31. bool flag = this.m_player.OpenVideoFromFile(MediaPlayer.FileLocation.AbsolutePathOrURL, this.m_player.m_VideoPath, false);
  32. NDebug.Assert(flag, "ビデオファイルを開けませんでした。\n" + this.m_player.m_VideoPath);
  33. if (flag && this.m_player.VideoOpened && this.m_bAutoStart)
  34. {
  35. this.Play();
  36. }
  37. }
  38. public void Play()
  39. {
  40. if (this.m_player.VideoOpened)
  41. {
  42. this.m_player.Play();
  43. }
  44. }
  45. public void Stop()
  46. {
  47. if (this.m_player.VideoOpened)
  48. {
  49. this.m_player.Stop();
  50. }
  51. }
  52. public void Speed(float f_fSpeed)
  53. {
  54. if (this.m_player.VideoOpened)
  55. {
  56. this.m_player.m_PlaybackRate = f_fSpeed;
  57. }
  58. }
  59. private MediaPlayer m_player;
  60. public bool m_bAutoStart;
  61. }