AVProVideoPlayer.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 = UTY.gameProjectPath + "\\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. if (!flag)
  33. {
  34. NDebug.MessageBox("エラー", "ビデオファイルを開けませんでした。\nファイルの存在=" + File.Exists(this.m_player.m_VideoPath).ToString() + "\n" + this.m_player.m_VideoPath);
  35. }
  36. if (flag && this.m_player.VideoOpened && this.m_bAutoStart)
  37. {
  38. this.Play();
  39. }
  40. }
  41. public void Play()
  42. {
  43. if (this.m_player.VideoOpened)
  44. {
  45. this.m_player.Play();
  46. }
  47. }
  48. public void Stop()
  49. {
  50. if (this.m_player.VideoOpened)
  51. {
  52. this.m_player.Stop();
  53. }
  54. }
  55. public void Speed(float f_fSpeed)
  56. {
  57. if (this.m_player.VideoOpened)
  58. {
  59. this.m_player.m_PlaybackRate = f_fSpeed;
  60. }
  61. }
  62. private MediaPlayer m_player;
  63. public bool m_bAutoStart;
  64. }