[RN] Add ability to loop sounds
This commit is contained in:
parent
333a0f5f90
commit
7b0a6a2ee5
|
@ -10,7 +10,8 @@ export type AudioElement = {
|
|||
currentTime?: number,
|
||||
pause: () => void,
|
||||
play: () => void,
|
||||
setSinkId?: string => void
|
||||
setSinkId?: string => void,
|
||||
stop: () => void
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -61,8 +62,6 @@ export default class AbstractAudio extends Component<Props> {
|
|||
this.setAudioElementImpl = this.setAudioElementImpl.bind(this);
|
||||
}
|
||||
|
||||
pause: () => void;
|
||||
|
||||
/**
|
||||
* Attempts to pause the playback of the media.
|
||||
*
|
||||
|
@ -73,10 +72,8 @@ export default class AbstractAudio extends Component<Props> {
|
|||
this._audioElementImpl && this._audioElementImpl.pause();
|
||||
}
|
||||
|
||||
play: () => void;
|
||||
|
||||
/**
|
||||
* Attempts to being the playback of the media.
|
||||
* Attempts to begin the playback of the media.
|
||||
*
|
||||
* @public
|
||||
* @returns {void}
|
||||
|
@ -106,8 +103,6 @@ export default class AbstractAudio extends Component<Props> {
|
|||
typeof setRef === 'function' && setRef(element ? this : null);
|
||||
}
|
||||
|
||||
setSinkId: string => void;
|
||||
|
||||
/**
|
||||
* Sets the sink ID (output device ID) on the underlying audio element.
|
||||
* NOTE: Currently, implemented only on Web.
|
||||
|
@ -120,4 +115,14 @@ export default class AbstractAudio extends Component<Props> {
|
|||
&& typeof this._audioElementImpl.setSinkId === 'function'
|
||||
&& this._audioElementImpl.setSinkId(sinkId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to stop the playback of the media.
|
||||
*
|
||||
* @public
|
||||
* @returns {void}
|
||||
*/
|
||||
stop(): void {
|
||||
this._audioElementImpl && this._audioElementImpl.stop();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,11 +12,10 @@ const logger = require('jitsi-meet-logger').getLogger(__filename);
|
|||
* {@link RTCView}.
|
||||
*/
|
||||
export default class Audio extends AbstractAudio {
|
||||
|
||||
/**
|
||||
* Reference to 'react-native-sound} {@link Sound} instance.
|
||||
*/
|
||||
_sound: Sound
|
||||
_sound: ?Sound;
|
||||
|
||||
/**
|
||||
* A callback passed to the 'react-native-sound''s {@link Sound} instance,
|
||||
|
@ -56,9 +55,22 @@ export default class Audio extends AbstractAudio {
|
|||
*/
|
||||
componentWillUnmount() {
|
||||
if (this._sound) {
|
||||
this.setAudioElementImpl(null);
|
||||
this._sound.release();
|
||||
this._sound = null;
|
||||
this.setAudioElementImpl(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to begin the playback of the media.
|
||||
*
|
||||
* @inheritdoc
|
||||
* @override
|
||||
*/
|
||||
play() {
|
||||
if (this._sound) {
|
||||
this._sound.setNumberOfLoops(this.props.loop ? -1 : 0);
|
||||
super.play();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,10 +93,8 @@ export default class Audio extends AbstractAudio {
|
|||
* @returns {void}
|
||||
*/
|
||||
stop() {
|
||||
// Currently not implemented for mobile. If needed, a possible
|
||||
// implementation is:
|
||||
// if (this._sound) {
|
||||
// this._sound.stop();
|
||||
// }
|
||||
if (this._sound) {
|
||||
this._sound.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue