You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Audio.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.setAudioElementImpl(null);
  52. this._sound.release();
  53. this._sound = null;
  54. }
  55. }
  56. /**
  57. * Implements React's {@link Component#render()}.
  58. *
  59. * @inheritdoc
  60. * @returns {null}
  61. */
  62. render() {
  63. // TODO react-native-webrtc's RTCView doesn't do anything with the audio
  64. // MediaStream specified to it so it's easier at the time of this
  65. // writing to not render anything.
  66. return null;
  67. }
  68. /**
  69. * Stops the sound if it's currently playing.
  70. *
  71. * @returns {void}
  72. */
  73. stop() {
  74. // Currently not implemented for mobile. If needed, a possible
  75. // implementation is:
  76. // if (this._sound) {
  77. // this._sound.stop();
  78. // }
  79. }
  80. }