MediaPlayer_OpenStream.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using UnityEngine;
  2. #if NETFX_CORE
  3. using Windows.Storage.Streams;
  4. #endif
  5. //-----------------------------------------------------------------------------
  6. // Copyright 2015-2022 RenderHeads Ltd. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. namespace RenderHeads.Media.AVProVideo
  9. {
  10. public partial class MediaPlayer : MonoBehaviour
  11. {
  12. #if NETFX_CORE
  13. public bool OpenVideoFromStream(IRandomAccessStream ras, string path, bool autoPlay = true)
  14. {
  15. _videoLocation = FileLocation.AbsolutePathOrURL;
  16. _videoPath = path;
  17. _autoPlayOnStart = autoPlay;
  18. if (_controlInterface == null)
  19. {
  20. Initialise();
  21. }
  22. return OpenVideoFromStream(ras);
  23. }
  24. private bool OpenVideoFromStream(IRandomAccessStream ras)
  25. {
  26. bool result = false;
  27. // Open the video file
  28. if (_controlInterface != null)
  29. {
  30. CloseVideo();
  31. _isVideoOpened = true;
  32. _autoPlayOnStartTriggered = !_autoPlayOnStart;
  33. // Potentially override the file location
  34. long fileOffset = GetPlatformFileOffset();
  35. if (!Control.OpenVideoFromFile(ras, _videoPath, fileOffset, null, _manuallySetAudioSourceProperties ? _sourceAudioSampleRate : 0,
  36. _manuallySetAudioSourceProperties ? _sourceAudioChannels : 0))
  37. {
  38. Debug.LogError("[AVProVideo] Failed to open " + _videoPath, this);
  39. }
  40. else
  41. {
  42. SetPlaybackOptions();
  43. result = true;
  44. StartRenderCoroutine();
  45. }
  46. }
  47. return result;
  48. }
  49. #endif
  50. }
  51. }