Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* @flow */
  2. import Sound from 'react-native-sound';
  3. import AbstractAudio from '../AbstractAudio';
  4. const logger = require('jitsi-meet-logger').getLogger(__filename);
  5. /**
  6. * The React Native/mobile {@link Component} which is similar to Web's
  7. * {@code HTMLAudioElement} and wraps around react-native-webrtc's
  8. * {@link RTCView}.
  9. */
  10. export default class Audio extends AbstractAudio {
  11. /**
  12. * Reference to 'react-native-sound} {@link Sound} instance.
  13. */
  14. _sound: ?Sound;
  15. /**
  16. * A callback passed to the 'react-native-sound''s {@link Sound} instance,
  17. * called when loading sound is finished.
  18. *
  19. * @param {Object} error - The error object passed by
  20. * the 'react-native-sound' library.
  21. * @returns {void}
  22. * @private
  23. */
  24. _soundLoadedCallback(error) {
  25. if (error) {
  26. logger.error('Failed to load sound', error);
  27. } else {
  28. this.setAudioElementImpl(this._sound);
  29. }
  30. }
  31. /**
  32. * Will load the sound, after the component did mount.
  33. *
  34. * @returns {void}
  35. */
  36. componentDidMount() {
  37. this._sound
  38. = this.props.src
  39. ? new Sound(
  40. this.props.src, null,
  41. this._soundLoadedCallback.bind(this))
  42. : null;
  43. }
  44. /**
  45. * Will dispose sound resources (if any) when component is about to unmount.
  46. *
  47. * @returns {void}
  48. */
  49. componentWillUnmount() {
  50. if (this._sound) {
  51. this._sound.release();
  52. this._sound = null;
  53. this.setAudioElementImpl(null);
  54. }
  55. }
  56. /**
  57. * Attempts to begin the playback of the media.
  58. *
  59. * @inheritdoc
  60. * @override
  61. */
  62. play() {
  63. if (this._sound) {
  64. this._sound.setNumberOfLoops(this.props.loop ? -1 : 0);
  65. super.play();
  66. }
  67. }
  68. /**
  69. * Implements React's {@link Component#render()}.
  70. *
  71. * @inheritdoc
  72. * @returns {null}
  73. */
  74. render() {
  75. // TODO react-native-webrtc's RTCView doesn't do anything with the audio
  76. // MediaStream specified to it so it's easier at the time of this
  77. // writing to not render anything.
  78. return null;
  79. }
  80. /**
  81. * Stops the sound if it's currently playing.
  82. *
  83. * @returns {void}
  84. */
  85. stop() {
  86. if (this._sound) {
  87. this._sound.stop();
  88. }
  89. }
  90. }