| 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.');
For details about the APIs used for audio playback, see [js-apis-media.md](../reference/apis/js-apis-media.md).
### Full-Process Scenario
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.
For details about the **src** media source input types supported by **AudioPlayer**, see the [src attributes](../reference/apis/js-apis-media.md#audioplayer_Attributes).
```js
functionSetCallBack(audioPlayer){
audioPlayer.on('dataLoad',()=>{// Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully.
console.info('audio set source success');
// The playback page is ready. You can click the Play button to start the playback.
});
audioPlayer.on('play',()=>{// Set the 'play' event callback.
console.info('audio play success');
// The Play button is changed to the pausable state.
});
audioPlayer.on('pause',()=>{// Set the 'pause' event callback.
console.info('audio pause success');
// The Play button is changed to the playable state.
});
audioPlayer.on('stop',()=>{// Set the 'stop' event callback.
console.info('audio stop success');
// The playback stops, the playback progress bar returns to 0, and the Play button is changed to the playable state.
});
audioPlayer.on('reset',()=>{// Set the 'reset' event callback.
console.info('audio reset success');
// You can reconfigure the src attribute to play another audio file.
});
audioPlayer.on('timeUpdate',(seekDoneTime)=>{// Set the 'timeUpdate' event callback.
if(typeof(seekDoneTime)=='undefined'){
console.info('audio seek fail');
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) => {
if (err) {
console.error('Error returned in the stop() callback.');