For details about the APIs used for audio playback, see [js-apis-media.md](../reference/apis/js-apis-media.md).
| API| Description|
### Full-Process Scenario
| -------- | -------- |
| media.createAudioPlayer() | Creates an **AudioPlayer** instance.|
The full audio playback process includes creating an instance, setting the URI, playing audio, seeking to the playback position, setting the volume, pausing playback, obtaining track information, stopping playback, resetting resources, and releasing resources.
| AudioPlayer | Provides audio playback features. For details, see the table below.|
For details about the **src** media source input types supported by **AudioPlayer**, see the [src attribute](../reference/apis/js-apis-media.md#audioplayer_Attributes).
**Table 2** AudioPlayer methods
```js
| Method| Description|
functionSetCallBack(audioPlayer){
| -------- | -------- |
audioPlayer.on('dataLoad',()=>{// Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully.
| release() | Releases audio resources.|
console.info('audio set source success');
| play() | Starts audio playback.|
// The playback page is ready. You can click the Play button to start the playback.
| pause() | Pauses playback.|
| stop() | Stops playback.|
| reset()<sup>7+</sup> | Resets the audio source to be played.|
| seek(timeMs: number) | Changes the playback position.|
| src:string | Defines the URI of an audio file to play.|
| state:AudioState | Defines the playback state.|
| currentTime:number | Defines the current playback position.|
| duration:number | Defines the playback duration. The value **-1** is returned if the data source does not support playback position change, for example, in the real-time streaming media scenario.|
| loop:boolean | Defines whether to loop audio playback.|
| on('play', function callback) | Subscribes to the playback start event.|
| on('pause', function callback) | Subscribes to the playback pause event.|
| on('stop', function callback) | Subscribes to the playback stop event.|
| on('reset', function callback) | Subscribes to the playback reset event.|
| on('finish',function callback) | Subscribes to the playback end event.|
| on('error', function callback) | Subscribes to the playback error event.|
| on('dataload', function callback) | Subscribes to the data loading event.|
| on('volumeChange', function callback) | Subscribes to the volume change event.|
| on('timeUpdate', function callback) | Subscribes to the progress change event.|
1. Create an audio player.
```
import media from '@ohos.multimedia.media';
var player = media.createAudioPlayer();
```
2. Set the subscription events.
```
player.on('play', (err, action) => {
if (err) {
console.error('Error returned in the play() callback.');
return;
}
console.info('Current player duration: '+ player.duration);
console.info('Current player time: ' + player.currentTime);
console.info('Current player status: '+player.state);
console.info('Pause MP3');
player.pause();
});
player.on('pause', (err, action) => {
if (err) {
console.error('Error returned in the pause() callback.');
return;
}
console.info('Current player status: ' + player.state);
console.info('Current player time: ' + player.currentTime);
player.seek(30000); // Seek for 30 seconds.
});
});
player.on('stop', (err, action) => {
audioPlayer.on('play',()=>{// Set the 'play' event callback.
if (err) {
console.info('audio play success');
console.error('Error returned in the stop() callback.');
// The Play button is changed to the pausable state.