DJI Mobile SDK Documentation

      class Speaker

      class Speaker extends BaseComponent
      Package:dji.sdk.accessory.speaker
      Inherits From:BaseComponent
      Description:

      The class represents the speaker accessory on the aircraft. Used transmit audio files and control the speaker.

      Class Members:
      File List State
      method
      method getFileListState
      FileListState getFileListState()
      Package:dji.sdk.accessory.speaker
      Description:

      Current file list state of the speaker.

      Return:
      FileListStateAn enum value of FileListState.
      Data Transmission State
      method
      method getDataTransmissionState
      SpeakerDataTransmissionState getDataTransmissionState()
      Package:dji.sdk.accessory.speaker
      Description:

      The data transmission state of the speaker.

      Return:
      SpeakerDataTransmissionStateAn enum value of SpeakerDataTransmissionState.
      Set Volume
      method
      method setVolume
      void setVolume(@IntRange(from = MIN_VOLUME, to = MAX_VOLUME) int value,
      @Nullable final CompletionCallback callback)
      Package:dji.sdk.accessory.speaker
      Description:

      Sets the volume to play audio. The valid range is [0, 100]. 100 means loudest.

      Input Parameters:
      @IntRange(from = MIN_VOLUME, to = MAX_VOLUME) int valueVolume value to set.
      @Nullable final CompletionCallback callbackThe execution callback with the returned execution result.
      Set Play Mode
      method
      method setPlayMode
      void setPlayMode(@NonNull SettingsDefinitions.PlayMode mode,
      @Nullable final CompletionCallback callback)
      Package:dji.sdk.accessory.speaker
      Description:

      Sets the play mode of the speaker to control the behavior after finishing playing a file.

      Input Parameters:
      @NonNull SettingsDefinitions.PlayMode modeThe play mode to set.
      @Nullable final CompletionCallback callbackThe execution callback with the returned execution result.
      Start Transmission
      method
      method startTransmission
      void startTransmission(@NonNull AudioFileInfo info, @Nullable final TransmissionListener listener)
      Package:dji.sdk.accessory.speaker
      Description:

      Starts to send a complete audio file to the aircraft, which can be played by the speaker. A transmission session can only be started when the transmission state is in IDLE. If the transmission is started successfully, the state will change to READY_TO_TRANSMIT. Then call paceData to send data to SDK. Call markEOF when all data has been sent to SDK. SDK will maintain a buffer to hold all the data and transmit it to the aircraft. For M2E Speaker, the audio file to transmit should fulfill the following configurations:
      - The speaker only receives raw PCM(Pulse-code modulation) data of an audio file, if the audio file is compressed, PCM extraction is needed before the transmission.
      - The audio channel is mono.
      - The audio sample rate is 44,100 Hz.
      - The PCM (Pulse-code modulation) sample depth is 16 bit per sample.
      - The audio file is stored in the aircraft instead of the speaker.

      Input Parameters:
      @NonNull AudioFileInfo infoThe information of the file to transmit. It is also used to determine the location the file will be stored in the aircraft.
      @Nullable final TransmissionListener listenerInform the progress of the data transfer.
      Pace Data
      method
      method paceData
      boolean paceData(@NonNull @Size(MAX_INPUT_SIZE) byte[] data)
      Package:dji.sdk.accessory.speaker
      Description:

      Sends raw PCM data of the audio file to SDK internal logic. For Mavic 2 Enterprise, the transmission rate is limited to 80kB/s by sdk. Therefore, SDK will cache the paced data to a local file when the rate of pacing data is over 80kB/s. The paced data will be appended to the local file. Call markEOF when all data of the data has been paced to SDK.

      Input Parameters:
      @NonNull @Size(MAX_INPUT_SIZE) byte[] dataRaw PCM data stream in bytes.
      Return:
      booleantrue if data is paced successfully. Otherwise, pacing data is not in the current state or the data size is illegal.
      Mark EOF
      method
      method markEOF
      DJIError markEOF()
      Package:dji.sdk.accessory.speaker
      Description:

      Marks EOF (end-of-file). It is used to inform SDK that all data of the file has been paced. SDK will continue to transmit data to the aircraft. The state will change to IDLE when all data is transmitted. After calling this method, paceData is invalid until a new transmission session starts. If no data is paced before calling this method, the transmission session will end immediately.

      Return:
      DJIErrorThe occurred error if any.
      Cancel Transmission
      method
      method cancelTransmission
      void cancelTransmission()
      Package:dji.sdk.accessory.speaker
      Description:

      This will entirely stop the data transfer process and of course clean the transfer thread pool.

      Play
      method
      method play
      void play(int fileIndex, @Nullable final CompletionCallback callback)
      Package:dji.sdk.accessory.speaker
      Description:

      Starts to play the audio file with the specific index.

      Input Parameters:
      int fileIndexThe file index of the AudioMediaFile to play.
      @Nullable final CompletionCallback callbackThe execution callback with the returned execution result.
      Stop Audio Play
      method
      method stop
      void stop(@Nullable final CompletionCallback callback)
      Package:dji.sdk.accessory.speaker
      Description:

      Stops the speaker from playing audio. The method is only valid when the playing state is PLAYING.

      Input Parameters:
      @Nullable final CompletionCallback callbackThe execution callback with the returned execution result.
      Rename
      method
      method rename
      void rename(int index, String filename, final CommonCallbacks.CompletionCallback callback)
      Package:dji.sdk.accessory.speaker
      Description:

      Renames the audio file with the specific index. If the operation is started successfully, FileListState will become RENAMING.

      Input Parameters:
      int indexThe index of the audio file to rename.
      String filenameThe new file name of the audio file. The file name should not exceed 128 characters.
      final CommonCallbacks.CompletionCallback callbackCompletion callback to receive the result.
      Get File List Snapshot
      method
      method getFileListSnapshot
      @Nullable
      List<AudioMediaFile> getFileListSnapshot()
      Package:dji.sdk.accessory.speaker
      Description:

      Returns a copy of the current audio file list from the storage. Returns null if getFileListState is reset.

      Return:
      List<AudioMediaFile>An array of AudioMediaFile objects.
      Refresh File List
      method
      method refreshFileList
      void refreshFileList(final CommonCallbacks.CompletionCallback callback)
      Package:dji.sdk.accessory.speaker
      Description:

      Refresh the audio file list in the aircraft.
      - If the current state is RESET, SDK will try to fetch the complete file list.
      - If the current state is INCOMPLETE, SDK will only fetch the missing list of files.
      - If the operation is started successfully, the FileListState will become SYNCING.
      - When the file list is refreshed successfully, the FileListState will become UP_TO_DATE.

      Input Parameters:
      final CommonCallbacks.CompletionCallback callbackCompletion callback to receive the result.
      method
      method delete
      void delete(@NonNull List<Integer> fileIndices,
      final CommonCallbacks.CompletionCallbackWithTwoParam<List<Integer>, DJIError> callback)
      Package:dji.sdk.accessory.speaker
      Description:

      Deletes audio files in the aircraft. If the operation is started successfully, getFileListState will become DELETING. If there is error or "failedFiles" is not empty, getFileListState will become RESET.

      Input Parameters:
      @NonNull List<Integer> fileIndicesA list of AudioMediaFile's index.
      final CommonCallbacks.CompletionCallbackWithTwoParam<List<Integer>, DJIError> callbackCompletion callback to receive the result.
      Add File List State Listener
      method
      method addFileListStateListener
      void addFileListStateListener(FileListStateListener listener)
      Package:dji.sdk.accessory.speaker
      Description:

      Start listen to the update of getFileListState.

      Input Parameters:
      FileListStateListener listenerA FileListStateListener interface.
      Remove File List State Listener
      method
      method removeFileListStateListener
      void removeFileListStateListener(FileListStateListener listener)
      Package:dji.sdk.accessory.speaker
      Description:

      Stop listen to the update of getFileListState.

      Input Parameters:
      FileListStateListener listenerListener to be removed.

      State Updates

      General
      method
      method setStateCallback
      void setStateCallback(@Nullable SpeakerState.Callback callback)
      Package:dji.sdk.accessory.speaker
      Description:

      Sets the callback that updates speaker state.

      Input Parameters:
      @Nullable SpeakerState.Callback callbackThe execution callback with the execution result returned.


      enum PlayMode
      enum PlayMode
      Package:dji.common.accessory
      Description:

      The speaker's play mode. It determines the behavior of the speaker when it finishes playing a file.

      Enum Members:
      SINGLE_ONCEThe speaker will play the selected file once. The speaker will stop playing after finishing playing the file.
      REPEAT_SINGLEThe speaker will play the selected file repeatedly.
      UNKNOWNUnknown.
      Class Members:
      enum SpeakerPlayingState
      enum SpeakerPlayingState
      Package:dji.common.accessory
      Description:

      The speaker's Playing State.

      Enum Members:
      PLAYINGThe speaker is playing the voice.
      STOPPEDThe speaker is stopped and playing nothing.
      UNKNOWNUnknown.
      Class Members:
      enum SpeakerDataTransmissionState
      enum SpeakerDataTransmissionState
      Package:dji.common.accessory
      Description:

      Data transmission state of the speaker.

      Enum Members:
      IDLEThe speaker is in idle state and is ready for receiving data from the mobile device. Call startTransmission to start the data transmission.
      READY_TO_TRANSMITThe data transmission from the mobile device to the speaker is started. Call paceData to transmit data.
      TRANSMITINGThe mobile device is transmitting data to the speaker.
      UNKNOWNUnknown state, either the speaker is disconnected or not recognized.
      Class Members:
      State Updates
      class
      Inherited Methods:
      dji.sdk.base.BaseComponent
      method
      method setComponentListener
      void setComponentListener(ComponentListener listener)
      Package:dji.sdk.base
      Description:

      Sets the listener for the DJI component.

      Input Parameters:
      ComponentListener listenerThe callback of ComponentListener.
      method
      method getIndex
      int getIndex()
      Package:dji.sdk.base
      Description:

      Returns the component index. Index is zero based. A component will have an index greater than zero when there are multiple components of the same type on the DJI product, and one of the components already has the index 0. For instance, M210 can have two gimbal mounted cameras, and will therefore have two gimbal components with indices 0 and 1, and two camera components with indices 0 and 1. For Matrice 600, there are printed numbers on the battery boxes. The Battery component instance with index 0 corresponds to battery compartment number 1. For Inspire 2 and M200 series, Battery with index 0 corresponds to the battery on the port (left hand) side of the aircraft. For M210, M210 RTK, M300 RTK and M350 RTK, Camera and Gimbal with index 0 corresponds to the camera and gimbal on the port (left hand) side of the aircraft. Lidar with index 0 corresponds to the lidar(Zenmuse L1) on the port (left hand) side of the aircraft.

      Return:
      intAn int value of index.
      method isConnected
      boolean isConnected()
      Package:dji.sdk.base
      Description:

      true if the component is connected.

      Return:
      booleantrue if the component is connected.
      method getSerialNumber
      void getSerialNumber(@NonNull CompletionCallbackWith<String> callback)
      Package:dji.sdk.base
      Description:

      Gets the serial number of the component. Depending on the component, this serial number might not match the serial number found on the physical component.

      Input Parameters:
      @NonNull CompletionCallbackWith<String> callbackThe execution callback with the value returned.
      method getFirmwareVersion
      void getFirmwareVersion(@NonNull CompletionCallbackWith<String> callback)
      Package:dji.sdk.base
      Description:

      Returns the firmware version of the component. Each component will have a different firmware version, the combination of which will form the package firmware version getFirmwarePackageVersion found in BaseProduct.

      Input Parameters:
      @NonNull CompletionCallbackWith<String> callbackThe execution callback with the value(s) returned.