目录

AudioVoice

has.stopVoice

has.stopVoice(Object object)

Stops audio playback.

Since: 1.0.16

Parameters

The input parameter is an object containing the following fields.

Parameter Type Mandatory Description
success function No Callback triggered when the API call is successful.
fail function No Callback triggered when the API call fails.
complete function No Callback triggered when the API call is complete, regardless of success or failure.

Error code information

Error Code Error Message
101 AVPlayer is not initialized.
102

1. AVPlayer can not be stop.

2. src is invalid or inaccessible

70003503

1. stopVoice error.

2. stopAudio error.

For details, see Media Error Codes.

Example:

has.stopVoice({
  success: () => {
    console.info('stopVoice success');
  },
  fail: (err) => {
    console.error('stopVoice fail', err);
  },
  complete: (res) => {
    console.info('stopVoice complete', res);
  }
});

has.playVoice

has.playVoice(Object object)

Starts audio playback. This API allows only one audio file to play at a time. If a previous audio file is still playing, it is interrupted and terminated.

Since: 1.0.16

Parameters

The input parameter is an object containing the following fields.

Parameter Type Default Value Mandatory Description
filePath string - Yes Path of the audio file to play.
duration number 60 No Playback duration, in seconds. The playback automatically stops after the specified duration.
success function - No Callback triggered when the API call is successful.
fail function - No Callback triggered when the API call fails.
complete function - No Callback triggered when the API call is complete, regardless of success or failure.
Error Code Error Message
101 AVPlayer is not initialized.
102

1. src is invalid or inaccessible;AVPlayer can not be stop.

2. filePath is invalid or inaccessible.

70003401 AVPlayer can not reset.
70003501

playVoice error.

For details, see Media Error Codes.

Example:

has.playVoice({
  filePath: 'internal://tmp/template.mp3',
  success: () => {
    console.info('playVoice success');
  },
  fail: (err) => {
    console.error('playVoice fail', err);
  },
  complete: (res) => {
    console.info('playVoice complete', res);
  }
});

has.pauseVoice

has.pauseVoice(Object object)

Pauses the audio that is currently playing. If has.playVoice is called again to play the same file, the playback resumes from the paused position. To start playback from the beginning, you must first call has.stopVoice.

Since: 1.0.16

Parameters

The input parameter is an object containing the following fields.

Parameter Type Mandatory Description
success function No Callback triggered when the API call is successful.
fail function No Callback triggered when the API call fails.
complete function No Callback triggered when the API call is complete, regardless of success or failure.

Error code information

Error Code Error Message
70003502

1. pauseVoice error.

2. pauseAudio error.

For details, see Media Error Codes.

Example:

has.pauseVoice({
  success: () => {
    console.info('pauseVoice success');
  },
  fail: (err) => {
    console.error('pauseVoice fail', err);
  },
  complete: (res) => {
    console.info('pauseVoice complete', res);
  }
});