-
Notifications
You must be signed in to change notification settings - Fork 5
Voice notes
MonkeyKit UI supports creating and viewing voice notes. For this, you need more than a UI library. You need classes that can manipulate different media file types. We decided to include such classes so that you can quickly have a functioning chat. Some of these classes are very basic and don't implement the functionalities for every need. However , you can extend this classes to implement your own functionalities without having to completely change how the UI Kit works.
A voice note message can be played by pressing the play button in the MonkeyHolder
. For the user to actually be able to listen to it, you must set an object that implementes VoiceNotePlayer
to MonkeyAdapter
. MonkeyAdapter
will call this class when the user wants to start or pause playback. VoiceNotePlayer
also calls MonkeyAdapter
to update the SeekBar
periodically in the voice note's UI during playback. These are the public methods:
initPlayer
Initializes the media player. It should be called on the onStart()
callback of your activity.
initPlayerWithFrontSpeaker
Initializes the media player with audio stream type STREAM_VOICE_CALL
, so that it uses the front speaker, which is the one used for voice calls.
onPauseButtonClicked
MonkeyAdapter
calls this method when the user presses the pause button. It pauses playback.
onPlayButtonClicked
MonkeyAdapter
calls this method when the user presses the play button. It starts/resumes playback.
onProgressManuallyChanged
Pauses media playback. this is useful to pause playback in other events not only when the user presses the pause button. For example, you might want to pause playback when your activity is stopped.
releasePlayer
Releases the media player. This should be used for cleanup in the activity's onStop()
callback.
isPlayingAudio
Boolean flag that is set to true when a voice note is playing and consequentially, false when a voice note is paused or if there is no currently playing item.
getPlaybackProgress
Returns an int between 0 - 100 indicating the playback progress.
getPlaybackPosition
Returns an int with the playback position in miliseconds.
Aditionally there are two attributes that you should be aware of.
-
currentlyPlayingItem
is an object that holds theMonkeyItem
that is prepared in the media player.MonkeyAdapter
will use this attribute to find the playing item. -
updateProgressEnabled
is boolean flag that if set to true, the seekbar of the MonkeyHolder of the playing item will update itself periodically. This should be true during playback so that the user can see that the audio is being played, but should be set to false when the user is manipulating the seekbar so that it doesn't move while the user is dragging it.
The UI kit includes an implementation called DefaultVoiceNotePlayer
which you can set to MonkeyAdapter
to enable voice note playback. If you need a different implementation, you can extend VoiceNotePlayer
and override these methods.
A voice note can be recording by holding down the record button in AudioInputView
. The class that actually records the user's voice and saves it into an audio file must extend the abstract class VoiceNoteRecorder
. AudioInputView
calls methods from VoiceNoteRecorder
when the user wants to record a new voice note. The methods that you need to implement in your custom VoiceNoteRecorder
are:
-
startRecording
called when the user starts the recording. -
stopRecording
called when the user successfully finishes the recording. -
cancelRecording
callled when the user cancells the recording.
By default AudioInputView
uses its own implementation, DefaultVoiceRecorder
. You can use a different one using the function setVoiceNoteRecorder()
.