Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Dan_vL
Product and Topic Expert
Product and Topic Expert
0 Kudos

         

Voice Recording Plugin (New in SP08)

The Cordova Media Capture plugin provides the ability to capture Audio, Image and Video.  The Kapsel Voice Recording plugin provides the ability to record audio in an encrypted format.  It takes the recorded audio file returned from the media capture plugin, encrypts it using an API from the encrypted storage plugin and then deletes the original unencrypted file.

For additional details on the Kapsel Voice Recording plugin see the JavaScript file in a project that includes this plugin at

project_name\plugins\com.sap.mp.cordova.plugins.voicerecording\www\voicerecording.js

or the Documentation at Using the Voice Recording Plugin.

The following steps will demonstrate these plugins.

  • Create the project.
    cordova -d create C:\Kapsel_Projects\VoiceRecordingDemo com.mycompany.voicerecording VoiceRecordingDemo "{\"plugin_search_path\":\"C:/SAP/MobileSDK3/KapselSDK/plugins/\"}"
    cd C:\Kapsel_Projects\VoiceRecordingDemo
    cordova -d platform add android

    cordova -d create ~/Documents/Kapsel_Projects/VoiceRecordingDemo com.mycompany.voicerecording VoiceRecordingDemo "{\"plugin_search_path\":\"/Users/i826567/SAP/MobileSDK3/KapselSDK/plugins/\"}"
    cd ~/Documents/Kapsel_Projects/VoiceRecordingDemo
    cordova -d platform add ios
  • Add the Media Capture plugin.
    cordova -d plugin add org.apache.cordova.media-capture
    Add the attachment viewer plugin and two other plugins (should be automatically added as dependents but are not in SP08) to assist with the opening of the media file in a separate WebView.
    cordova plugins add com.sap.mp.cordova.plugins.attachmentviewer
    cordova plugins add org.apache.cordova.dialogs
    cordova plugins add com.sap.mp.cordova.plugins.i18n
    Modify the C:\Kapsel_Projects\VoiceRecordingDemo\plugins\com.sap.mp.cordova.plugins.attachmentviewer\www\attachmentviewer.js file to handle file types.
    if (element.tagName == 'A' && (element.href.indexOf("http") === 0 || element.href.indexOf("https") === 0) && element.target == "_blank")
    to
    if (element.tagName == 'A' && (element.href.indexOf("http") === 0 || element.href.indexOf("file") === 0 || element.href.indexOf("https") === 0) && element.target == "_blank")
  • Replace www\index.html with the contents of index.html.

  • Copy the files to the platform directory by running
    cordova -d prepare
  • Use the Android IDE or Xcode to deploy and run the project.

    Note, the Android emulator or iOS simulator can be used for this sample.  On Nexus devices, an app that can handle the intent android.provider.MediaStore.RECORD_SOUND will need to be installed.  One example is Sound Recorder by brightattic.



    Notice above that the file is unencrypted and accessible.

  • The following steps will add the Kapsel Voice Recording plugin which is used to encrypt the voice memo and then to delete the unencrypted file.
    cordova -d plugin add com.sap.mp.cordova.plugins.voicerecording
  • Expose the deleteFile method by making the below changes to the file
    C:\Kapsel_Projects\VoiceRecordingDemo\plugins\com.sap.mp.cordova.plugins.voicerecording\www\recording.js
    Move the exports section below the deleteFile method.  Modify the exports section to include the deleteFile method.
    module.exports = {
        audioCapture: audioCapture,
        deleteFile: deleteFile
    };
  • Copy the files to the platform directory by running
    cordova -d prepare
  • Use the Android IDE or Xcode to deploy and run the project.

    This time click on the Using button to toggle to use the Kapsel Voice Recording plugin.
    Record a voice memo.  Notice that on the device storage, there is now an encrypted version of the voice recording.



    After pressing Unencrypt Voice Memo, an unencrypted copy is generated.



    Both files can be deleted by calling Delete Voice Memo.


Back to Getting Started With Kapsel

1 Comment