MediaPlayerSourceObserver.cs 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System;
  2. namespace Agora.Rtc
  3. {
  4. public delegate void OnPlayerSourceStateChangedHandler(MEDIA_PLAYER_STATE state, MEDIA_PLAYER_ERROR ec);
  5. public delegate void OnPositionChangedHandler(Int64 position_ms);
  6. public delegate void OnPlayerEventHandler(MEDIA_PLAYER_EVENT eventCode, Int64 elapsedTime, string message);
  7. public delegate void OnMetaDataHandler(byte[] data, int length);
  8. public delegate void OnPlayBufferUpdatedHandler(Int64 playCachedBuffer);
  9. public delegate void OnCompletedHandler();
  10. public delegate void OnAgoraCDNTokenWillExpireHandler();
  11. public delegate void OnPlayerSrcInfoChangedHandler(SrcInfo from, SrcInfo to);
  12. public delegate void OnPlayerInfoUpdatedHandler(PlayerUpdatedInfo info);
  13. public delegate void MediaPlayerOnAudioVolumeIndicationHandler(int volume);
  14. public class MediaPlayerSourceObserver : IMediaPlayerSourceObserver
  15. {
  16. public event OnPlayerSourceStateChangedHandler EventOnPlayerSourceStateChanged;
  17. public event OnPositionChangedHandler EventOnPositionChanged;
  18. public event OnPlayerEventHandler EventOnPlayerEvent;
  19. public event OnMetaDataHandler EventOnMetaData;
  20. public event OnPlayBufferUpdatedHandler EventOnPlayBufferUpdated;
  21. public event OnCompletedHandler EventOnCompleted;
  22. public event OnAgoraCDNTokenWillExpireHandler EventOnAgoraCDNTokenWillExpire;
  23. public event OnPlayerSrcInfoChangedHandler EventOnPlayerSrcInfoChanged;
  24. public event OnPlayerInfoUpdatedHandler EventOnPlayerInfoUpdated;
  25. public event MediaPlayerOnAudioVolumeIndicationHandler EventOnAudioVolumeIndication;
  26. public override void OnPlayerSourceStateChanged(MEDIA_PLAYER_STATE state, MEDIA_PLAYER_ERROR ec)
  27. {
  28. if (EventOnPlayerSourceStateChanged == null) return;
  29. EventOnPlayerSourceStateChanged.Invoke(state, ec);
  30. }
  31. public override void OnPositionChanged(Int64 position_ms)
  32. {
  33. if (EventOnPositionChanged == null) return;
  34. EventOnPositionChanged.Invoke(position_ms);
  35. }
  36. public override void OnPlayerEvent(MEDIA_PLAYER_EVENT eventCode, Int64 elapsedTime, string message)
  37. {
  38. if (EventOnPlayerEvent == null) return;
  39. EventOnPlayerEvent.Invoke(eventCode, elapsedTime, message);
  40. }
  41. public override void OnMetaData(byte[] data, int length)
  42. {
  43. if (EventOnMetaData == null) return;
  44. EventOnMetaData.Invoke(data, length);
  45. }
  46. public override void OnPlayBufferUpdated(Int64 playCachedBuffer)
  47. {
  48. if (EventOnPlayBufferUpdated == null) return;
  49. EventOnPlayBufferUpdated.Invoke(playCachedBuffer);
  50. }
  51. public override void OnCompleted()
  52. {
  53. if (EventOnCompleted == null) return;
  54. EventOnCompleted.Invoke();
  55. }
  56. public override void OnAgoraCDNTokenWillExpire()
  57. {
  58. if (EventOnAgoraCDNTokenWillExpire == null) return;
  59. EventOnAgoraCDNTokenWillExpire.Invoke();
  60. }
  61. public override void OnPlayerSrcInfoChanged(SrcInfo from, SrcInfo to)
  62. {
  63. if (EventOnPlayerSrcInfoChanged == null) return;
  64. EventOnPlayerSrcInfoChanged.Invoke(from, to);
  65. }
  66. public override void OnPlayerInfoUpdated(PlayerUpdatedInfo info)
  67. {
  68. if (EventOnPlayerInfoUpdated == null) return;
  69. EventOnPlayerInfoUpdated.Invoke(info);
  70. }
  71. public override void OnAudioVolumeIndication(int volume)
  72. {
  73. if (EventOnAudioVolumeIndication == null) return;
  74. EventOnAudioVolumeIndication.Invoke(volume);
  75. }
  76. }
  77. }