MediaPlayer.cs 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using UnityEngine;
  6. namespace RenderHeads.Media.AVProVideo
  7. {
  8. [AddComponentMenu("AVPro Video/Media Player", -100)]
  9. [HelpURL("http://renderheads.com/product/avpro-video/")]
  10. public class MediaPlayer : MonoBehaviour
  11. {
  12. public Resampler FrameResampler
  13. {
  14. get
  15. {
  16. return this.m_Resampler;
  17. }
  18. }
  19. public bool DisplayDebugGUI
  20. {
  21. get
  22. {
  23. return this.m_DebugGui;
  24. }
  25. set
  26. {
  27. this.m_DebugGui = value;
  28. }
  29. }
  30. public bool DisplayDebugGUIControls
  31. {
  32. get
  33. {
  34. return this.m_DebugGuiControls;
  35. }
  36. set
  37. {
  38. this.m_DebugGuiControls = value;
  39. }
  40. }
  41. public bool Persistent
  42. {
  43. get
  44. {
  45. return this.m_Persistent;
  46. }
  47. set
  48. {
  49. this.m_Persistent = value;
  50. }
  51. }
  52. public IMediaInfo Info
  53. {
  54. get
  55. {
  56. return this.m_Info;
  57. }
  58. }
  59. public IMediaControl Control
  60. {
  61. get
  62. {
  63. return this.m_Control;
  64. }
  65. }
  66. public IMediaPlayer Player
  67. {
  68. get
  69. {
  70. return this.m_Player;
  71. }
  72. }
  73. public virtual IMediaProducer TextureProducer
  74. {
  75. get
  76. {
  77. return this.m_Texture;
  78. }
  79. }
  80. public virtual IMediaSubtitles Subtitles
  81. {
  82. get
  83. {
  84. return this.m_Subtitles;
  85. }
  86. }
  87. public MediaPlayerEvent Events
  88. {
  89. get
  90. {
  91. if (this.m_events == null)
  92. {
  93. this.m_events = new MediaPlayerEvent();
  94. }
  95. return this.m_events;
  96. }
  97. }
  98. public bool VideoOpened
  99. {
  100. get
  101. {
  102. return this.m_VideoOpened;
  103. }
  104. }
  105. public Transform AudioHeadTransform
  106. {
  107. get
  108. {
  109. return this.m_AudioHeadTransform;
  110. }
  111. set
  112. {
  113. this.m_AudioHeadTransform = value;
  114. }
  115. }
  116. public bool AudioFocusEnabled
  117. {
  118. get
  119. {
  120. return this.m_AudioFocusEnabled;
  121. }
  122. set
  123. {
  124. this.m_AudioFocusEnabled = value;
  125. }
  126. }
  127. public float AudioFocusOffLevelDB
  128. {
  129. get
  130. {
  131. return this.m_AudioFocusOffLevelDB;
  132. }
  133. set
  134. {
  135. this.m_AudioFocusOffLevelDB = value;
  136. }
  137. }
  138. public float AudioFocusWidthDegrees
  139. {
  140. get
  141. {
  142. return this.m_AudioFocusWidthDegrees;
  143. }
  144. set
  145. {
  146. this.m_AudioFocusWidthDegrees = value;
  147. }
  148. }
  149. public Transform AudioFocusTransform
  150. {
  151. get
  152. {
  153. return this.m_AudioFocusTransform;
  154. }
  155. set
  156. {
  157. this.m_AudioFocusTransform = value;
  158. }
  159. }
  160. public MediaPlayer.OptionsWindows PlatformOptionsWindows
  161. {
  162. get
  163. {
  164. return this._optionsWindows;
  165. }
  166. }
  167. public MediaPlayer.OptionsMacOSX PlatformOptionsMacOSX
  168. {
  169. get
  170. {
  171. return this._optionsMacOSX;
  172. }
  173. }
  174. public MediaPlayer.OptionsIOS PlatformOptionsIOS
  175. {
  176. get
  177. {
  178. return this._optionsIOS;
  179. }
  180. }
  181. public MediaPlayer.OptionsTVOS PlatformOptionsTVOS
  182. {
  183. get
  184. {
  185. return this._optionsTVOS;
  186. }
  187. }
  188. public MediaPlayer.OptionsAndroid PlatformOptionsAndroid
  189. {
  190. get
  191. {
  192. return this._optionsAndroid;
  193. }
  194. }
  195. public MediaPlayer.OptionsWindowsPhone PlatformOptionsWindowsPhone
  196. {
  197. get
  198. {
  199. return this._optionsWindowsPhone;
  200. }
  201. }
  202. public MediaPlayer.OptionsWindowsUWP PlatformOptionsWindowsUWP
  203. {
  204. get
  205. {
  206. return this._optionsWindowsUWP;
  207. }
  208. }
  209. public MediaPlayer.OptionsWebGL PlatformOptionsWebGL
  210. {
  211. get
  212. {
  213. return this._optionsWebGL;
  214. }
  215. }
  216. public MediaPlayer.OptionsPS4 PlatformOptionsPS4
  217. {
  218. get
  219. {
  220. return this._optionsPS4;
  221. }
  222. }
  223. private void Awake()
  224. {
  225. if (this.m_Persistent)
  226. {
  227. UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
  228. }
  229. }
  230. protected void Initialise()
  231. {
  232. BaseMediaPlayer baseMediaPlayer = this.CreatePlatformMediaPlayer();
  233. if (baseMediaPlayer != null)
  234. {
  235. this.m_Control = baseMediaPlayer;
  236. this.m_Texture = baseMediaPlayer;
  237. this.m_Info = baseMediaPlayer;
  238. this.m_Player = baseMediaPlayer;
  239. this.m_Subtitles = baseMediaPlayer;
  240. this.m_Dispose = baseMediaPlayer;
  241. if (!MediaPlayer.s_GlobalStartup)
  242. {
  243. Helper.LogInfo(string.Format("Initialising AVPro Video (script v{0} plugin v{1}) on {2}/{3} (MT {4}) on {5}", new object[]
  244. {
  245. "1.7.5",
  246. baseMediaPlayer.GetVersion(),
  247. SystemInfo.graphicsDeviceName,
  248. SystemInfo.graphicsDeviceVersion,
  249. SystemInfo.graphicsMultiThreaded,
  250. Application.platform
  251. }), null);
  252. MediaPlayer.s_GlobalStartup = true;
  253. }
  254. }
  255. }
  256. private void Start()
  257. {
  258. if (this.m_Control == null)
  259. {
  260. this.Initialise();
  261. }
  262. if (this.m_Control != null)
  263. {
  264. if (this.m_AutoOpen)
  265. {
  266. this.OpenVideoFromFile();
  267. if (this.m_LoadSubtitles && this.m_Subtitles != null && !string.IsNullOrEmpty(this.m_SubtitlePath))
  268. {
  269. this.EnableSubtitles(this.m_SubtitleLocation, this.m_SubtitlePath);
  270. }
  271. }
  272. this.StartRenderCoroutine();
  273. }
  274. }
  275. public bool OpenVideoFromFile(MediaPlayer.FileLocation location, string path, bool autoPlay = true)
  276. {
  277. this.m_VideoLocation = location;
  278. this.m_VideoPath = path;
  279. this.m_AutoStart = autoPlay;
  280. if (this.m_Control == null)
  281. {
  282. this.Initialise();
  283. }
  284. return this.OpenVideoFromFile();
  285. }
  286. public bool OpenVideoFromBuffer(byte[] buffer, bool autoPlay = true)
  287. {
  288. this.m_VideoLocation = MediaPlayer.FileLocation.AbsolutePathOrURL;
  289. this.m_VideoPath = "buffer";
  290. this.m_AutoStart = autoPlay;
  291. if (this.m_Control == null)
  292. {
  293. this.Initialise();
  294. }
  295. return this.OpenVideoFromBufferInternal(buffer);
  296. }
  297. public bool SubtitlesEnabled
  298. {
  299. get
  300. {
  301. return this.m_LoadSubtitles;
  302. }
  303. }
  304. public string SubtitlePath
  305. {
  306. get
  307. {
  308. return this.m_SubtitlePath;
  309. }
  310. }
  311. public MediaPlayer.FileLocation SubtitleLocation
  312. {
  313. get
  314. {
  315. return this.m_SubtitleLocation;
  316. }
  317. }
  318. public bool EnableSubtitles(MediaPlayer.FileLocation fileLocation, string filePath)
  319. {
  320. bool result = false;
  321. if (this.m_Subtitles != null)
  322. {
  323. if (!string.IsNullOrEmpty(filePath))
  324. {
  325. string platformFilePath = this.GetPlatformFilePath(MediaPlayer.GetPlatform(), ref filePath, ref fileLocation);
  326. bool flag = true;
  327. if (platformFilePath.Contains("://"))
  328. {
  329. flag = false;
  330. }
  331. if (flag && !File.Exists(platformFilePath))
  332. {
  333. Debug.LogError("[AVProVideo] Subtitle file not found: " + platformFilePath, this);
  334. }
  335. else
  336. {
  337. Helper.LogInfo("Opening subtitles " + platformFilePath, this);
  338. this.m_previousSubtitleIndex = -1;
  339. try
  340. {
  341. if (platformFilePath.Contains("://"))
  342. {
  343. if (this.m_loadSubtitlesRoutine != null)
  344. {
  345. base.StopCoroutine(this.m_loadSubtitlesRoutine);
  346. this.m_loadSubtitlesRoutine = null;
  347. }
  348. this.m_loadSubtitlesRoutine = base.StartCoroutine(this.LoadSubtitlesCoroutine(platformFilePath, fileLocation, filePath));
  349. }
  350. else
  351. {
  352. string data = File.ReadAllText(platformFilePath);
  353. if (this.m_Subtitles.LoadSubtitlesSRT(data))
  354. {
  355. this.m_SubtitleLocation = fileLocation;
  356. this.m_SubtitlePath = filePath;
  357. this.m_LoadSubtitles = false;
  358. result = true;
  359. }
  360. else
  361. {
  362. Debug.LogError("[AVProVideo] Failed to load subtitles" + platformFilePath, this);
  363. }
  364. }
  365. }
  366. catch (Exception exception)
  367. {
  368. Debug.LogError("[AVProVideo] Failed to load subtitles " + platformFilePath, this);
  369. Debug.LogException(exception, this);
  370. }
  371. }
  372. }
  373. else
  374. {
  375. Debug.LogError("[AVProVideo] No subtitle file path specified", this);
  376. }
  377. }
  378. else
  379. {
  380. this.m_queueSubtitleLocation = fileLocation;
  381. this.m_queueSubtitlePath = filePath;
  382. }
  383. return result;
  384. }
  385. private IEnumerator LoadSubtitlesCoroutine(string url, MediaPlayer.FileLocation fileLocation, string filePath)
  386. {
  387. WWW www = new WWW(url);
  388. yield return www;
  389. string subtitleData = string.Empty;
  390. if (string.IsNullOrEmpty(www.error))
  391. {
  392. subtitleData = www.text;
  393. }
  394. else
  395. {
  396. Debug.LogError("[AVProVideo] Error loading subtitles '" + www.error + "' from " + url);
  397. }
  398. if (this.m_Subtitles.LoadSubtitlesSRT(subtitleData))
  399. {
  400. this.m_SubtitleLocation = fileLocation;
  401. this.m_SubtitlePath = filePath;
  402. this.m_LoadSubtitles = false;
  403. }
  404. else
  405. {
  406. Debug.LogError("[AVProVideo] Failed to load subtitles" + url, this);
  407. }
  408. this.m_loadSubtitlesRoutine = null;
  409. yield break;
  410. }
  411. public void DisableSubtitles()
  412. {
  413. if (this.m_loadSubtitlesRoutine != null)
  414. {
  415. base.StopCoroutine(this.m_loadSubtitlesRoutine);
  416. this.m_loadSubtitlesRoutine = null;
  417. }
  418. if (this.m_Subtitles != null)
  419. {
  420. this.m_previousSubtitleIndex = -1;
  421. this.m_LoadSubtitles = false;
  422. this.m_Subtitles.LoadSubtitlesSRT(string.Empty);
  423. }
  424. else
  425. {
  426. this.m_queueSubtitlePath = string.Empty;
  427. }
  428. }
  429. private bool OpenVideoFromBufferInternal(byte[] buffer)
  430. {
  431. bool result = false;
  432. if (this.m_Control != null)
  433. {
  434. this.CloseVideo();
  435. this.m_VideoOpened = true;
  436. this.m_AutoStartTriggered = !this.m_AutoStart;
  437. this.m_EventFired_MetaDataReady = false;
  438. this.m_EventFired_ReadyToPlay = false;
  439. this.m_EventFired_Started = false;
  440. this.m_EventFired_FirstFrameReady = false;
  441. this.m_EventFired_FinishedPlaying = false;
  442. this.m_previousSubtitleIndex = -1;
  443. Helper.LogInfo("Opening buffer of length " + buffer.Length, this);
  444. if (!this.m_Control.OpenVideoFromBuffer(buffer))
  445. {
  446. Debug.LogError("[AVProVideo] Failed to open buffer", this);
  447. if (this.GetCurrentPlatformOptions() != this.PlatformOptionsWindows || this.PlatformOptionsWindows.videoApi != Windows.VideoApi.DirectShow)
  448. {
  449. Debug.LogError("[AVProVideo] Loading from buffer is currently only supported in Windows when using the DirectShow API");
  450. }
  451. }
  452. else
  453. {
  454. this.SetPlaybackOptions();
  455. result = true;
  456. this.StartRenderCoroutine();
  457. }
  458. }
  459. return result;
  460. }
  461. private bool OpenVideoFromFile()
  462. {
  463. bool result = false;
  464. if (this.m_Control != null)
  465. {
  466. this.CloseVideo();
  467. this.m_VideoOpened = true;
  468. this.m_AutoStartTriggered = !this.m_AutoStart;
  469. this.m_EventFired_MetaDataReady = false;
  470. this.m_EventFired_ReadyToPlay = false;
  471. this.m_EventFired_Started = false;
  472. this.m_EventFired_FirstFrameReady = false;
  473. this.m_EventFired_FinishedPlaying = false;
  474. this.m_FinishedFrameOpenCheck = true;
  475. this.m_previousSubtitleIndex = -1;
  476. long platformFileOffset = this.GetPlatformFileOffset();
  477. string platformFilePath = this.GetPlatformFilePath(MediaPlayer.GetPlatform(), ref this.m_VideoPath, ref this.m_VideoLocation);
  478. if (!string.IsNullOrEmpty(this.m_VideoPath))
  479. {
  480. string httpHeaderJson = null;
  481. bool flag = true;
  482. if (platformFilePath.Contains("://"))
  483. {
  484. flag = false;
  485. httpHeaderJson = this.GetPlatformHttpHeaderJson();
  486. }
  487. if (flag && !File.Exists(platformFilePath))
  488. {
  489. Debug.LogError("[AVProVideo] File not found: " + platformFilePath, this);
  490. }
  491. else
  492. {
  493. Helper.LogInfo(string.Concat(new object[]
  494. {
  495. "Opening ",
  496. platformFilePath,
  497. " (offset ",
  498. platformFileOffset,
  499. ")"
  500. }), this);
  501. if (this._optionsWindows.enableAudio360)
  502. {
  503. this.m_Control.SetAudioChannelMode(this._optionsWindows.audio360ChannelMode);
  504. }
  505. if (!this.m_Control.OpenVideoFromFile(platformFilePath, platformFileOffset, httpHeaderJson))
  506. {
  507. Debug.LogError("[AVProVideo] Failed to open " + platformFilePath, this);
  508. }
  509. else
  510. {
  511. this.SetPlaybackOptions();
  512. result = true;
  513. this.StartRenderCoroutine();
  514. }
  515. }
  516. }
  517. else
  518. {
  519. Debug.LogError("[AVProVideo] No file path specified", this);
  520. }
  521. }
  522. return result;
  523. }
  524. private void SetPlaybackOptions()
  525. {
  526. if (this.m_Control != null)
  527. {
  528. this.m_Control.SetLooping(this.m_Loop);
  529. this.m_Control.SetVolume(this.m_Volume);
  530. this.m_Control.SetBalance(this.m_Balance);
  531. this.m_Control.SetPlaybackRate(this.m_PlaybackRate);
  532. this.m_Control.MuteAudio(this.m_Muted);
  533. this.m_Control.SetTextureProperties(this.m_FilterMode, this.m_WrapMode, this.m_AnisoLevel);
  534. }
  535. }
  536. public void CloseVideo()
  537. {
  538. if (this.m_Control != null)
  539. {
  540. if (this.m_events != null && this.m_VideoOpened)
  541. {
  542. this.m_events.Invoke(this, MediaPlayerEvent.EventType.Closing, ErrorCode.None);
  543. }
  544. this.m_AutoStartTriggered = false;
  545. this.m_VideoOpened = false;
  546. this.m_EventFired_ReadyToPlay = false;
  547. this.m_EventFired_Started = false;
  548. this.m_EventFired_MetaDataReady = false;
  549. this.m_EventFired_FirstFrameReady = false;
  550. this.m_EventFired_FinishedPlaying = false;
  551. if (this.m_loadSubtitlesRoutine != null)
  552. {
  553. base.StopCoroutine(this.m_loadSubtitlesRoutine);
  554. this.m_loadSubtitlesRoutine = null;
  555. }
  556. this.m_previousSubtitleIndex = -1;
  557. this.m_isPlaybackStalled = false;
  558. this.m_Control.CloseVideo();
  559. }
  560. if (this.m_Resampler != null)
  561. {
  562. this.m_Resampler.Reset();
  563. }
  564. this.StopRenderCoroutine();
  565. }
  566. public void Play()
  567. {
  568. if (this.m_Control != null && this.m_Control.CanPlay())
  569. {
  570. this.m_Control.Play();
  571. this.m_EventFired_ReadyToPlay = true;
  572. }
  573. else
  574. {
  575. this.m_AutoStart = true;
  576. }
  577. }
  578. public void Pause()
  579. {
  580. if (this.m_Control != null && this.m_Control.IsPlaying())
  581. {
  582. this.m_Control.Pause();
  583. }
  584. }
  585. public void Stop()
  586. {
  587. if (this.m_Control != null)
  588. {
  589. this.m_Control.Stop();
  590. }
  591. }
  592. public void Rewind(bool pause)
  593. {
  594. if (this.m_Control != null)
  595. {
  596. if (pause)
  597. {
  598. this.Pause();
  599. }
  600. this.m_Control.Rewind();
  601. }
  602. }
  603. private void Update()
  604. {
  605. if (this.m_Control != null)
  606. {
  607. if (this.m_VideoOpened && this.m_AutoStart && !this.m_AutoStartTriggered && this.m_Control.CanPlay())
  608. {
  609. this.m_AutoStartTriggered = true;
  610. this.Play();
  611. }
  612. if (this._renderingCoroutine == null && this.m_Control.CanPlay())
  613. {
  614. this.StartRenderCoroutine();
  615. }
  616. if (this.m_Subtitles != null && !string.IsNullOrEmpty(this.m_queueSubtitlePath))
  617. {
  618. this.EnableSubtitles(this.m_queueSubtitleLocation, this.m_queueSubtitlePath);
  619. this.m_queueSubtitlePath = string.Empty;
  620. }
  621. this.UpdateAudioHeadTransform();
  622. this.UpdateAudioFocus();
  623. this.m_Player.Update();
  624. this.UpdateErrors();
  625. this.UpdateEvents();
  626. }
  627. }
  628. private void LateUpdate()
  629. {
  630. if (this.m_Resample && this.m_Resampler == null)
  631. {
  632. this.m_Resampler = new Resampler(this, base.gameObject.name, this.m_ResampleBufferSize, this.m_ResampleMode);
  633. }
  634. if (this.m_Resampler != null)
  635. {
  636. this.m_Resampler.Update();
  637. this.m_Resampler.UpdateTimestamp();
  638. }
  639. }
  640. private void OnEnable()
  641. {
  642. if (this.m_Control != null && this.m_WasPlayingOnPause)
  643. {
  644. this.m_AutoStart = true;
  645. this.m_AutoStartTriggered = false;
  646. this.m_WasPlayingOnPause = false;
  647. }
  648. if (this.m_Player != null)
  649. {
  650. this.m_Player.OnEnable();
  651. }
  652. this.StartRenderCoroutine();
  653. }
  654. private void OnDisable()
  655. {
  656. if (this.m_Control != null && this.m_Control.IsPlaying())
  657. {
  658. this.m_WasPlayingOnPause = true;
  659. this.Pause();
  660. }
  661. this.StopRenderCoroutine();
  662. }
  663. private void OnDestroy()
  664. {
  665. this.CloseVideo();
  666. if (this.m_Dispose != null)
  667. {
  668. this.m_Dispose.Dispose();
  669. this.m_Dispose = null;
  670. }
  671. this.m_Control = null;
  672. this.m_Texture = null;
  673. this.m_Info = null;
  674. this.m_Player = null;
  675. if (this.m_Resampler != null)
  676. {
  677. this.m_Resampler.Release();
  678. this.m_Resampler = null;
  679. }
  680. }
  681. private void OnApplicationQuit()
  682. {
  683. if (MediaPlayer.s_GlobalStartup)
  684. {
  685. Helper.LogInfo("Shutdown", null);
  686. MediaPlayer[] array = Resources.FindObjectsOfTypeAll<MediaPlayer>();
  687. if (array != null && array.Length > 0)
  688. {
  689. for (int i = 0; i < array.Length; i++)
  690. {
  691. array[i].CloseVideo();
  692. }
  693. }
  694. WindowsMediaPlayer.DeinitPlatform();
  695. MediaPlayer.s_GlobalStartup = false;
  696. }
  697. }
  698. private void StartRenderCoroutine()
  699. {
  700. if (this._renderingCoroutine == null)
  701. {
  702. this._renderingCoroutine = base.StartCoroutine(this.FinalRenderCapture());
  703. }
  704. }
  705. private void StopRenderCoroutine()
  706. {
  707. if (this._renderingCoroutine != null)
  708. {
  709. base.StopCoroutine(this._renderingCoroutine);
  710. this._renderingCoroutine = null;
  711. }
  712. }
  713. private IEnumerator FinalRenderCapture()
  714. {
  715. YieldInstruction wait = new WaitForEndOfFrame();
  716. while (Application.isPlaying)
  717. {
  718. yield return wait;
  719. if (base.enabled && this.m_Player != null)
  720. {
  721. this.m_Player.Render();
  722. }
  723. }
  724. yield break;
  725. }
  726. public static Platform GetPlatform()
  727. {
  728. return Platform.Windows;
  729. }
  730. public MediaPlayer.PlatformOptions GetCurrentPlatformOptions()
  731. {
  732. return this._optionsWindows;
  733. }
  734. public static string GetPath(MediaPlayer.FileLocation location)
  735. {
  736. string text = string.Empty;
  737. switch (location)
  738. {
  739. case MediaPlayer.FileLocation.RelativeToProjectFolder:
  740. {
  741. string path = "..";
  742. text = Path.GetFullPath(Path.Combine(Application.dataPath, path));
  743. text = text.Replace('\\', '/');
  744. break;
  745. }
  746. case MediaPlayer.FileLocation.RelativeToStreamingAssetsFolder:
  747. text = Application.streamingAssetsPath;
  748. break;
  749. case MediaPlayer.FileLocation.RelativeToDataFolder:
  750. text = Application.dataPath;
  751. break;
  752. case MediaPlayer.FileLocation.RelativeToPeristentDataFolder:
  753. text = Application.persistentDataPath;
  754. break;
  755. }
  756. return text;
  757. }
  758. public static string GetFilePath(string path, MediaPlayer.FileLocation location)
  759. {
  760. string result = string.Empty;
  761. if (!string.IsNullOrEmpty(path))
  762. {
  763. switch (location)
  764. {
  765. case MediaPlayer.FileLocation.AbsolutePathOrURL:
  766. result = path;
  767. break;
  768. case MediaPlayer.FileLocation.RelativeToProjectFolder:
  769. case MediaPlayer.FileLocation.RelativeToStreamingAssetsFolder:
  770. case MediaPlayer.FileLocation.RelativeToDataFolder:
  771. case MediaPlayer.FileLocation.RelativeToPeristentDataFolder:
  772. result = Path.Combine(MediaPlayer.GetPath(location), path);
  773. break;
  774. }
  775. }
  776. return result;
  777. }
  778. private long GetPlatformFileOffset()
  779. {
  780. return 0L;
  781. }
  782. private string GetPlatformHttpHeaderJson()
  783. {
  784. string text = null;
  785. if (!string.IsNullOrEmpty(text))
  786. {
  787. text = text.Trim();
  788. }
  789. return text;
  790. }
  791. private string GetPlatformFilePath(Platform platform, ref string filePath, ref MediaPlayer.FileLocation fileLocation)
  792. {
  793. string empty = string.Empty;
  794. if (platform != Platform.Unknown)
  795. {
  796. MediaPlayer.PlatformOptions currentPlatformOptions = this.GetCurrentPlatformOptions();
  797. if (currentPlatformOptions != null && currentPlatformOptions.overridePath)
  798. {
  799. filePath = currentPlatformOptions.path;
  800. fileLocation = currentPlatformOptions.pathLocation;
  801. }
  802. }
  803. return MediaPlayer.GetFilePath(filePath, fileLocation);
  804. }
  805. public virtual BaseMediaPlayer CreatePlatformMediaPlayer()
  806. {
  807. BaseMediaPlayer baseMediaPlayer = null;
  808. if (WindowsMediaPlayer.InitialisePlatform())
  809. {
  810. baseMediaPlayer = new WindowsMediaPlayer(this._optionsWindows.videoApi, this._optionsWindows.useHardwareDecoding, this._optionsWindows.useTextureMips, this._optionsWindows.hintAlphaChannel, this._optionsWindows.useLowLatency, this._optionsWindows.forceAudioOutputDeviceName, this._optionsWindows.useUnityAudio, this._optionsWindows.forceAudioResample, this._optionsWindows.preferredFilters);
  811. }
  812. if (baseMediaPlayer == null)
  813. {
  814. Debug.LogError(string.Format("[AVProVideo] Not supported on this platform {0} {1} {2} {3}. Using null media player!", new object[]
  815. {
  816. Application.platform,
  817. SystemInfo.deviceModel,
  818. SystemInfo.processorType,
  819. SystemInfo.operatingSystem
  820. }));
  821. baseMediaPlayer = new NullMediaPlayer();
  822. }
  823. return baseMediaPlayer;
  824. }
  825. private bool ForceWaitForNewFrame(int lastFrameCount, float timeoutMs)
  826. {
  827. bool result = false;
  828. DateTime now = DateTime.Now;
  829. int num = 0;
  830. while (this.Control != null && (DateTime.Now - now).TotalMilliseconds < (double)timeoutMs)
  831. {
  832. this.m_Player.Update();
  833. if (lastFrameCount != this.TextureProducer.GetTextureFrameCount())
  834. {
  835. result = true;
  836. break;
  837. }
  838. num++;
  839. }
  840. this.m_Player.Render();
  841. return result;
  842. }
  843. private void UpdateAudioFocus()
  844. {
  845. this.m_Control.SetAudioFocusEnabled(this.m_AudioFocusEnabled);
  846. this.m_Control.SetAudioFocusProperties(this.m_AudioFocusOffLevelDB, this.m_AudioFocusWidthDegrees);
  847. this.m_Control.SetAudioFocusRotation((!(this.m_AudioFocusTransform == null)) ? this.m_AudioFocusTransform.rotation : Quaternion.identity);
  848. }
  849. private void UpdateAudioHeadTransform()
  850. {
  851. if (this.m_AudioHeadTransform != null)
  852. {
  853. this.m_Control.SetAudioHeadRotation(this.m_AudioHeadTransform.rotation);
  854. }
  855. else
  856. {
  857. this.m_Control.ResetAudioHeadRotation();
  858. }
  859. }
  860. private void UpdateErrors()
  861. {
  862. ErrorCode lastError = this.m_Control.GetLastError();
  863. if (lastError != ErrorCode.None)
  864. {
  865. Debug.LogError("[AVProVideo] Error: " + Helper.GetErrorMessage(lastError));
  866. if (this.m_events != null)
  867. {
  868. this.m_events.Invoke(this, MediaPlayerEvent.EventType.Error, lastError);
  869. }
  870. }
  871. }
  872. private void UpdateEvents()
  873. {
  874. if (this.m_events != null && this.m_Control != null)
  875. {
  876. this.m_FinishedFrameOpenCheck = false;
  877. if (this.FireEventIfPossible(MediaPlayerEvent.EventType.FinishedPlaying, this.m_EventFired_FinishedPlaying))
  878. {
  879. this.m_EventFired_FinishedPlaying = !this.m_FinishedFrameOpenCheck;
  880. }
  881. if (this.m_EventFired_Started && this.m_Control != null && !this.m_Control.IsPlaying() && !this.m_Control.IsSeeking())
  882. {
  883. this.m_EventFired_Started = false;
  884. }
  885. if (this.m_EventFired_FinishedPlaying && this.m_Control != null && this.m_Control.IsPlaying() && !this.m_Control.IsFinished())
  886. {
  887. bool flag = false;
  888. float num = 1000f / this.m_Info.GetVideoFrameRate();
  889. if (this.m_Info.GetDurationMs() - this.m_Control.GetCurrentTimeMs() > num)
  890. {
  891. flag = true;
  892. }
  893. if (flag)
  894. {
  895. this.m_EventFired_FinishedPlaying = false;
  896. }
  897. }
  898. this.m_EventFired_MetaDataReady = this.FireEventIfPossible(MediaPlayerEvent.EventType.MetaDataReady, this.m_EventFired_MetaDataReady);
  899. this.m_EventFired_ReadyToPlay = this.FireEventIfPossible(MediaPlayerEvent.EventType.ReadyToPlay, this.m_EventFired_ReadyToPlay);
  900. this.m_EventFired_Started = this.FireEventIfPossible(MediaPlayerEvent.EventType.Started, this.m_EventFired_Started);
  901. this.m_EventFired_FirstFrameReady = this.FireEventIfPossible(MediaPlayerEvent.EventType.FirstFrameReady, this.m_EventFired_FirstFrameReady);
  902. if (this.FireEventIfPossible(MediaPlayerEvent.EventType.SubtitleChange, false))
  903. {
  904. this.m_previousSubtitleIndex = this.m_Subtitles.GetSubtitleIndex();
  905. }
  906. bool flag2 = this.m_Info.IsPlaybackStalled();
  907. if (flag2 != this.m_isPlaybackStalled)
  908. {
  909. this.m_isPlaybackStalled = flag2;
  910. MediaPlayerEvent.EventType eventType = (!this.m_isPlaybackStalled) ? MediaPlayerEvent.EventType.Unstalled : MediaPlayerEvent.EventType.Stalled;
  911. this.FireEventIfPossible(eventType, false);
  912. }
  913. }
  914. }
  915. private bool FireEventIfPossible(MediaPlayerEvent.EventType eventType, bool hasFired)
  916. {
  917. if (this.CanFireEvent(eventType, hasFired))
  918. {
  919. hasFired = true;
  920. this.m_events.Invoke(this, eventType, ErrorCode.None);
  921. }
  922. return hasFired;
  923. }
  924. private bool CanFireEvent(MediaPlayerEvent.EventType et, bool hasFired)
  925. {
  926. bool result = false;
  927. if (this.m_events != null && this.m_Control != null && !hasFired)
  928. {
  929. switch (et)
  930. {
  931. case MediaPlayerEvent.EventType.MetaDataReady:
  932. result = this.m_Control.HasMetaData();
  933. break;
  934. case MediaPlayerEvent.EventType.ReadyToPlay:
  935. result = (!this.m_Control.IsPlaying() && this.m_Control.CanPlay() && !this.m_AutoStart);
  936. break;
  937. case MediaPlayerEvent.EventType.Started:
  938. result = this.m_Control.IsPlaying();
  939. break;
  940. case MediaPlayerEvent.EventType.FirstFrameReady:
  941. result = (this.m_Texture != null && this.m_Control.CanPlay() && this.m_Texture.GetTextureFrameCount() > 0);
  942. break;
  943. case MediaPlayerEvent.EventType.FinishedPlaying:
  944. result = ((!this.m_Control.IsLooping() && this.m_Control.CanPlay() && this.m_Control.IsFinished()) || (this.m_Control.GetCurrentTimeMs() > this.m_Info.GetDurationMs() && !this.m_Control.IsLooping()));
  945. break;
  946. case MediaPlayerEvent.EventType.SubtitleChange:
  947. result = (this.m_previousSubtitleIndex != this.m_Subtitles.GetSubtitleIndex());
  948. break;
  949. case MediaPlayerEvent.EventType.Stalled:
  950. result = this.m_Info.IsPlaybackStalled();
  951. break;
  952. case MediaPlayerEvent.EventType.Unstalled:
  953. result = !this.m_Info.IsPlaybackStalled();
  954. break;
  955. }
  956. }
  957. return result;
  958. }
  959. private void OnApplicationFocus(bool focusStatus)
  960. {
  961. }
  962. private void OnApplicationPause(bool pauseStatus)
  963. {
  964. }
  965. [ContextMenu("Save Frame To PNG")]
  966. public void SaveFrameToPng()
  967. {
  968. Texture2D texture2D = this.ExtractFrame(null, -1f, true, 1000);
  969. if (texture2D != null)
  970. {
  971. byte[] array = texture2D.EncodeToPNG();
  972. if (array != null)
  973. {
  974. string str = Mathf.FloorToInt(this.Control.GetCurrentTimeMs()).ToString("D8");
  975. File.WriteAllBytes("frame-" + str + ".png", array);
  976. }
  977. UnityEngine.Object.Destroy(texture2D);
  978. }
  979. }
  980. private static Camera GetDummyCamera()
  981. {
  982. if (MediaPlayer.m_DummyCamera == null)
  983. {
  984. GameObject gameObject = GameObject.Find("AVPro Video Dummy Camera");
  985. if (gameObject == null)
  986. {
  987. gameObject = new GameObject("AVPro Video Dummy Camera");
  988. gameObject.hideFlags = (HideFlags.HideInHierarchy | HideFlags.DontSaveInEditor | HideFlags.DontSaveInBuild | HideFlags.DontUnloadUnusedAsset);
  989. gameObject.SetActive(false);
  990. UnityEngine.Object.DontDestroyOnLoad(gameObject);
  991. MediaPlayer.m_DummyCamera = gameObject.AddComponent<Camera>();
  992. MediaPlayer.m_DummyCamera.hideFlags = (HideFlags.HideInInspector | HideFlags.DontSaveInEditor | HideFlags.DontSaveInBuild | HideFlags.DontUnloadUnusedAsset);
  993. MediaPlayer.m_DummyCamera.cullingMask = 0;
  994. MediaPlayer.m_DummyCamera.clearFlags = CameraClearFlags.Nothing;
  995. MediaPlayer.m_DummyCamera.enabled = false;
  996. }
  997. else
  998. {
  999. MediaPlayer.m_DummyCamera = gameObject.GetComponent<Camera>();
  1000. }
  1001. }
  1002. return MediaPlayer.m_DummyCamera;
  1003. }
  1004. private IEnumerator ExtractFrameCoroutine(Texture2D target, MediaPlayer.ProcessExtractedFrame callback, float timeSeconds = -1f, bool accurateSeek = true, int timeoutMs = 1000)
  1005. {
  1006. Texture2D result = target;
  1007. Texture frame = null;
  1008. if (this.m_Control != null)
  1009. {
  1010. if (timeSeconds >= 0f)
  1011. {
  1012. this.Pause();
  1013. float seekTimeMs = timeSeconds * 1000f;
  1014. if (this.TextureProducer.GetTexture(0) != null && this.m_Control.GetCurrentTimeMs() == seekTimeMs)
  1015. {
  1016. frame = this.TextureProducer.GetTexture(0);
  1017. }
  1018. else
  1019. {
  1020. int preSeekFrameCount = this.m_Texture.GetTextureFrameCount();
  1021. if (accurateSeek)
  1022. {
  1023. this.m_Control.Seek(seekTimeMs);
  1024. }
  1025. else
  1026. {
  1027. this.m_Control.SeekFast(seekTimeMs);
  1028. }
  1029. if (!this.m_Control.WaitForNextFrame(MediaPlayer.GetDummyCamera(), preSeekFrameCount))
  1030. {
  1031. int currFc = this.TextureProducer.GetTextureFrameCount();
  1032. int iterations = 0;
  1033. int maxIterations = 50;
  1034. while (currFc + 1 >= this.TextureProducer.GetTextureFrameCount())
  1035. {
  1036. int num;
  1037. iterations = (num = iterations) + 1;
  1038. if (num >= maxIterations)
  1039. {
  1040. break;
  1041. }
  1042. yield return null;
  1043. }
  1044. }
  1045. frame = this.TextureProducer.GetTexture(0);
  1046. }
  1047. }
  1048. else
  1049. {
  1050. frame = this.TextureProducer.GetTexture(0);
  1051. }
  1052. }
  1053. if (frame != null)
  1054. {
  1055. result = Helper.GetReadableTexture(frame, this.TextureProducer.RequiresVerticalFlip(), Helper.GetOrientation(this.Info.GetTextureTransform()), target);
  1056. }
  1057. callback(result);
  1058. yield return null;
  1059. yield break;
  1060. }
  1061. public void ExtractFrameAsync(Texture2D target, MediaPlayer.ProcessExtractedFrame callback, float timeSeconds = -1f, bool accurateSeek = true, int timeoutMs = 1000)
  1062. {
  1063. base.StartCoroutine(this.ExtractFrameCoroutine(target, callback, timeSeconds, accurateSeek, timeoutMs));
  1064. }
  1065. public Texture2D ExtractFrame(Texture2D target, float timeSeconds = -1f, bool accurateSeek = true, int timeoutMs = 1000)
  1066. {
  1067. Texture2D result = target;
  1068. Texture texture = this.ExtractFrame(timeSeconds, accurateSeek, timeoutMs);
  1069. if (texture != null)
  1070. {
  1071. result = Helper.GetReadableTexture(texture, this.TextureProducer.RequiresVerticalFlip(), Helper.GetOrientation(this.Info.GetTextureTransform()), target);
  1072. }
  1073. return result;
  1074. }
  1075. private Texture ExtractFrame(float timeSeconds = -1f, bool accurateSeek = true, int timeoutMs = 1000)
  1076. {
  1077. Texture result = null;
  1078. if (this.m_Control != null)
  1079. {
  1080. if (timeSeconds >= 0f)
  1081. {
  1082. this.Pause();
  1083. float num = timeSeconds * 1000f;
  1084. if (this.TextureProducer.GetTexture(0) != null && this.m_Control.GetCurrentTimeMs() == num)
  1085. {
  1086. result = this.TextureProducer.GetTexture(0);
  1087. }
  1088. else
  1089. {
  1090. int textureFrameCount = this.TextureProducer.GetTextureFrameCount();
  1091. if (accurateSeek)
  1092. {
  1093. this.m_Control.Seek(num);
  1094. }
  1095. else
  1096. {
  1097. this.m_Control.SeekFast(num);
  1098. }
  1099. this.ForceWaitForNewFrame(textureFrameCount, (float)timeoutMs);
  1100. result = this.TextureProducer.GetTexture(0);
  1101. }
  1102. }
  1103. else
  1104. {
  1105. result = this.TextureProducer.GetTexture(0);
  1106. }
  1107. }
  1108. return result;
  1109. }
  1110. public void SetGuiPositionFromVideoIndex(int index)
  1111. {
  1112. this.m_GuiPositionX = Mathf.FloorToInt(15f + (float)(180 * index) * 1.5f);
  1113. }
  1114. public void SetDebugGuiEnabled(bool bEnabled)
  1115. {
  1116. this.m_DebugGui = bEnabled;
  1117. }
  1118. private void OnGUI()
  1119. {
  1120. if (this.m_Info != null && this.m_DebugGui)
  1121. {
  1122. GUI.depth = -1000;
  1123. GUI.matrix = Matrix4x4.TRS(new Vector3((float)this.m_GuiPositionX, 10f, 0f), Quaternion.identity, new Vector3(1.5f, 1.5f, 1f));
  1124. GUILayout.BeginVertical("box", new GUILayoutOption[]
  1125. {
  1126. GUILayout.MaxWidth(180f)
  1127. });
  1128. GUILayout.Label(Path.GetFileName(this.m_VideoPath), new GUILayoutOption[0]);
  1129. GUILayout.Label(string.Concat(new object[]
  1130. {
  1131. "Dimensions: ",
  1132. this.m_Info.GetVideoWidth(),
  1133. "x",
  1134. this.m_Info.GetVideoHeight(),
  1135. "@",
  1136. this.m_Info.GetVideoFrameRate().ToString("F2")
  1137. }), new GUILayoutOption[0]);
  1138. GUILayout.Label(string.Concat(new string[]
  1139. {
  1140. "Time: ",
  1141. (this.m_Control.GetCurrentTimeMs() * 0.001f).ToString("F1"),
  1142. "s / ",
  1143. (this.m_Info.GetDurationMs() * 0.001f).ToString("F1"),
  1144. "s"
  1145. }), new GUILayoutOption[0]);
  1146. GUILayout.Label("Rate: " + this.m_Info.GetVideoDisplayRate().ToString("F2") + "Hz", new GUILayoutOption[0]);
  1147. if (this.m_Resample && this.m_Resampler != null)
  1148. {
  1149. GUILayout.BeginVertical(new GUILayoutOption[0]);
  1150. GUILayout.Label("Resampler Info:", new GUILayoutOption[0]);
  1151. GUILayout.Label("Resampler timestamp: " + this.m_Resampler.TextureTimeStamp, new GUILayoutOption[0]);
  1152. GUILayout.Label("Resampler frames dropped: " + this.m_Resampler.DroppedFrames, new GUILayoutOption[0]);
  1153. GUILayout.Label("Resampler frame displayed timer: " + this.m_Resampler.FrameDisplayedTimer, new GUILayoutOption[0]);
  1154. GUILayout.EndVertical();
  1155. }
  1156. if (this.TextureProducer != null && this.TextureProducer.GetTexture(0) != null)
  1157. {
  1158. GUILayout.BeginHorizontal(new GUILayoutOption[0]);
  1159. Rect rect = GUILayoutUtility.GetRect(32f, 32f);
  1160. GUILayout.Space(8f);
  1161. Rect rect2 = GUILayoutUtility.GetRect(32f, 32f);
  1162. Matrix4x4 matrix = GUI.matrix;
  1163. if (this.TextureProducer.RequiresVerticalFlip())
  1164. {
  1165. GUIUtility.ScaleAroundPivot(new Vector2(1f, -1f), new Vector2(0f, rect.y + rect.height / 2f));
  1166. }
  1167. GUI.DrawTexture(rect, this.TextureProducer.GetTexture(0), ScaleMode.ScaleToFit, false);
  1168. GUI.DrawTexture(rect2, this.TextureProducer.GetTexture(0), ScaleMode.ScaleToFit, true);
  1169. GUI.matrix = matrix;
  1170. GUILayout.FlexibleSpace();
  1171. GUILayout.EndHorizontal();
  1172. }
  1173. if (this.m_DebugGuiControls)
  1174. {
  1175. GUILayout.BeginHorizontal(new GUILayoutOption[0]);
  1176. if (this.m_Control.IsPaused())
  1177. {
  1178. if (GUILayout.Button("Play", new GUILayoutOption[]
  1179. {
  1180. GUILayout.Width(50f)
  1181. }))
  1182. {
  1183. this.m_Control.Play();
  1184. }
  1185. }
  1186. else if (GUILayout.Button("Pause", new GUILayoutOption[]
  1187. {
  1188. GUILayout.Width(50f)
  1189. }))
  1190. {
  1191. this.m_Control.Pause();
  1192. }
  1193. float durationMs = this.m_Info.GetDurationMs();
  1194. float currentTimeMs = this.m_Control.GetCurrentTimeMs();
  1195. float num = GUILayout.HorizontalSlider(currentTimeMs, 0f, durationMs, new GUILayoutOption[0]);
  1196. if (num != currentTimeMs)
  1197. {
  1198. this.m_Control.Seek(num);
  1199. }
  1200. GUILayout.EndHorizontal();
  1201. }
  1202. GUILayout.EndVertical();
  1203. }
  1204. }
  1205. public MediaPlayer.FileLocation m_VideoLocation = MediaPlayer.FileLocation.RelativeToStreamingAssetsFolder;
  1206. public string m_VideoPath;
  1207. public bool m_AutoOpen = true;
  1208. public bool m_AutoStart = true;
  1209. public bool m_Loop;
  1210. [Range(0f, 1f)]
  1211. public float m_Volume = 1f;
  1212. [SerializeField]
  1213. [Range(-1f, 1f)]
  1214. private float m_Balance;
  1215. public bool m_Muted;
  1216. [SerializeField]
  1217. [Range(-4f, 4f)]
  1218. public float m_PlaybackRate = 1f;
  1219. public bool m_Resample;
  1220. public Resampler.ResampleMode m_ResampleMode;
  1221. [Range(3f, 10f)]
  1222. public int m_ResampleBufferSize = 5;
  1223. private Resampler m_Resampler;
  1224. [SerializeField]
  1225. private bool m_DebugGui;
  1226. [SerializeField]
  1227. private bool m_DebugGuiControls = true;
  1228. [SerializeField]
  1229. private bool m_Persistent;
  1230. public StereoPacking m_StereoPacking;
  1231. public AlphaPacking m_AlphaPacking;
  1232. public bool m_DisplayDebugStereoColorTint;
  1233. public FilterMode m_FilterMode = FilterMode.Bilinear;
  1234. public TextureWrapMode m_WrapMode = TextureWrapMode.Clamp;
  1235. [Range(0f, 16f)]
  1236. public int m_AnisoLevel;
  1237. [SerializeField]
  1238. private bool m_LoadSubtitles;
  1239. [SerializeField]
  1240. private MediaPlayer.FileLocation m_SubtitleLocation = MediaPlayer.FileLocation.RelativeToStreamingAssetsFolder;
  1241. private MediaPlayer.FileLocation m_queueSubtitleLocation;
  1242. [SerializeField]
  1243. private string m_SubtitlePath;
  1244. private string m_queueSubtitlePath;
  1245. private Coroutine m_loadSubtitlesRoutine;
  1246. [SerializeField]
  1247. private Transform m_AudioHeadTransform;
  1248. [SerializeField]
  1249. private bool m_AudioFocusEnabled;
  1250. [SerializeField]
  1251. private Transform m_AudioFocusTransform;
  1252. [SerializeField]
  1253. [Range(40f, 120f)]
  1254. private float m_AudioFocusWidthDegrees = 90f;
  1255. [SerializeField]
  1256. [Range(-24f, 0f)]
  1257. private float m_AudioFocusOffLevelDB;
  1258. [SerializeField]
  1259. private MediaPlayerEvent m_events;
  1260. private IMediaControl m_Control;
  1261. private IMediaProducer m_Texture;
  1262. private IMediaInfo m_Info;
  1263. private IMediaPlayer m_Player;
  1264. private IMediaSubtitles m_Subtitles;
  1265. private IDisposable m_Dispose;
  1266. private bool m_VideoOpened;
  1267. private bool m_AutoStartTriggered;
  1268. private bool m_WasPlayingOnPause;
  1269. private Coroutine _renderingCoroutine;
  1270. private const int s_GuiDepth = -1000;
  1271. private const float s_GuiScale = 1.5f;
  1272. private const int s_GuiStartWidth = 10;
  1273. private const int s_GuiWidth = 180;
  1274. private int m_GuiPositionX = 10;
  1275. private static bool s_GlobalStartup;
  1276. private bool m_EventFired_ReadyToPlay;
  1277. private bool m_EventFired_Started;
  1278. private bool m_EventFired_FirstFrameReady;
  1279. private bool m_EventFired_FinishedPlaying;
  1280. private bool m_EventFired_MetaDataReady;
  1281. private int m_previousSubtitleIndex = -1;
  1282. private bool m_isPlaybackStalled;
  1283. private static Camera m_DummyCamera;
  1284. private bool m_FinishedFrameOpenCheck;
  1285. [SerializeField]
  1286. private MediaPlayer.OptionsWindows _optionsWindows = new MediaPlayer.OptionsWindows();
  1287. [SerializeField]
  1288. private MediaPlayer.OptionsMacOSX _optionsMacOSX = new MediaPlayer.OptionsMacOSX();
  1289. [SerializeField]
  1290. private MediaPlayer.OptionsIOS _optionsIOS = new MediaPlayer.OptionsIOS();
  1291. [SerializeField]
  1292. private MediaPlayer.OptionsTVOS _optionsTVOS = new MediaPlayer.OptionsTVOS();
  1293. [SerializeField]
  1294. private MediaPlayer.OptionsAndroid _optionsAndroid = new MediaPlayer.OptionsAndroid();
  1295. [SerializeField]
  1296. private MediaPlayer.OptionsWindowsPhone _optionsWindowsPhone = new MediaPlayer.OptionsWindowsPhone();
  1297. [SerializeField]
  1298. private MediaPlayer.OptionsWindowsUWP _optionsWindowsUWP = new MediaPlayer.OptionsWindowsUWP();
  1299. [SerializeField]
  1300. private MediaPlayer.OptionsWebGL _optionsWebGL = new MediaPlayer.OptionsWebGL();
  1301. [SerializeField]
  1302. private MediaPlayer.OptionsPS4 _optionsPS4 = new MediaPlayer.OptionsPS4();
  1303. [Serializable]
  1304. public class Setup
  1305. {
  1306. public bool displayDebugGUI;
  1307. public bool persistent;
  1308. }
  1309. public enum FileLocation
  1310. {
  1311. AbsolutePathOrURL,
  1312. RelativeToProjectFolder,
  1313. RelativeToStreamingAssetsFolder,
  1314. RelativeToDataFolder,
  1315. RelativeToPeristentDataFolder
  1316. }
  1317. [Serializable]
  1318. public class PlatformOptions
  1319. {
  1320. public virtual bool IsModified()
  1321. {
  1322. return this.overridePath;
  1323. }
  1324. public bool overridePath;
  1325. public MediaPlayer.FileLocation pathLocation = MediaPlayer.FileLocation.RelativeToStreamingAssetsFolder;
  1326. public string path;
  1327. }
  1328. [Serializable]
  1329. public class OptionsWindows : MediaPlayer.PlatformOptions
  1330. {
  1331. public override bool IsModified()
  1332. {
  1333. return base.IsModified() || !this.useHardwareDecoding || this.useTextureMips || this.hintAlphaChannel || this.useLowLatency || this.useUnityAudio || this.videoApi != Windows.VideoApi.MediaFoundation || !this.forceAudioResample || this.enableAudio360 || this.audio360ChannelMode != Audio360ChannelMode.TBE_8_2 || !string.IsNullOrEmpty(this.forceAudioOutputDeviceName) || this.preferredFilters.Count != 0;
  1334. }
  1335. public Windows.VideoApi videoApi;
  1336. public bool useHardwareDecoding = true;
  1337. public bool useUnityAudio;
  1338. public bool forceAudioResample = true;
  1339. public bool useTextureMips;
  1340. public bool hintAlphaChannel;
  1341. public bool useLowLatency;
  1342. public string forceAudioOutputDeviceName = string.Empty;
  1343. public List<string> preferredFilters = new List<string>();
  1344. public bool enableAudio360;
  1345. public Audio360ChannelMode audio360ChannelMode;
  1346. }
  1347. [Serializable]
  1348. public class OptionsMacOSX : MediaPlayer.PlatformOptions
  1349. {
  1350. public override bool IsModified()
  1351. {
  1352. return base.IsModified() || !string.IsNullOrEmpty(this.httpHeaderJson);
  1353. }
  1354. [Multiline]
  1355. public string httpHeaderJson;
  1356. }
  1357. [Serializable]
  1358. public class OptionsIOS : MediaPlayer.PlatformOptions
  1359. {
  1360. public override bool IsModified()
  1361. {
  1362. return base.IsModified() || !string.IsNullOrEmpty(this.httpHeaderJson) || !this.useYpCbCr420Textures;
  1363. }
  1364. public bool useYpCbCr420Textures = true;
  1365. [Multiline]
  1366. public string httpHeaderJson;
  1367. }
  1368. [Serializable]
  1369. public class OptionsTVOS : MediaPlayer.PlatformOptions
  1370. {
  1371. public override bool IsModified()
  1372. {
  1373. return base.IsModified() || !string.IsNullOrEmpty(this.httpHeaderJson) || !this.useYpCbCr420Textures;
  1374. }
  1375. public bool useYpCbCr420Textures = true;
  1376. [Multiline]
  1377. public string httpHeaderJson;
  1378. }
  1379. [Serializable]
  1380. public class OptionsAndroid : MediaPlayer.PlatformOptions
  1381. {
  1382. public override bool IsModified()
  1383. {
  1384. return base.IsModified() || this.fileOffset != 0 || this.useFastOesPath || this.showPosterFrame || this.videoApi != Android.VideoApi.MediaPlayer || !string.IsNullOrEmpty(this.httpHeaderJson) || this.enableAudio360 || this.audio360ChannelMode != Audio360ChannelMode.TBE_8_2;
  1385. }
  1386. public Android.VideoApi videoApi = Android.VideoApi.MediaPlayer;
  1387. public bool useFastOesPath;
  1388. public bool showPosterFrame;
  1389. public bool enableAudio360;
  1390. public Audio360ChannelMode audio360ChannelMode;
  1391. [Multiline]
  1392. public string httpHeaderJson;
  1393. [SerializeField]
  1394. [Tooltip("Byte offset into the file where the media file is located. This is useful when hiding or packing media files within another file.")]
  1395. public int fileOffset;
  1396. }
  1397. [Serializable]
  1398. public class OptionsWindowsPhone : MediaPlayer.PlatformOptions
  1399. {
  1400. public override bool IsModified()
  1401. {
  1402. return base.IsModified() || !this.useHardwareDecoding || this.useTextureMips || this.useLowLatency || this.useUnityAudio || !this.forceAudioResample;
  1403. }
  1404. public bool useHardwareDecoding = true;
  1405. public bool useUnityAudio;
  1406. public bool forceAudioResample = true;
  1407. public bool useTextureMips;
  1408. public bool useLowLatency;
  1409. }
  1410. [Serializable]
  1411. public class OptionsWindowsUWP : MediaPlayer.PlatformOptions
  1412. {
  1413. public override bool IsModified()
  1414. {
  1415. return base.IsModified() || !this.useHardwareDecoding || this.useTextureMips || this.useLowLatency || this.useUnityAudio || !this.forceAudioResample;
  1416. }
  1417. public bool useHardwareDecoding = true;
  1418. public bool useUnityAudio;
  1419. public bool forceAudioResample = true;
  1420. public bool useTextureMips;
  1421. public bool useLowLatency;
  1422. }
  1423. [Serializable]
  1424. public class OptionsWebGL : MediaPlayer.PlatformOptions
  1425. {
  1426. }
  1427. [Serializable]
  1428. public class OptionsPS4 : MediaPlayer.PlatformOptions
  1429. {
  1430. }
  1431. public delegate void ProcessExtractedFrame(Texture2D extractedFrame);
  1432. }
  1433. }