File tree 3 files changed +17
-3
lines changed
3 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,10 @@ export interface AudioPlayerOptions {
46
46
* Should mix audio.
47
47
*/
48
48
audioMixing ?: boolean ;
49
+ /**
50
+ * start at a specific position
51
+ */
52
+ seek ?: number ;
49
53
50
54
/**
51
55
* iOS: The category for playing recorded music or other sounds that are central to the successful use of your app.
@@ -74,6 +78,7 @@ export interface AudioPlayerOptions {
74
78
* Android: custom player datasource.
75
79
*/
76
80
dataSource ?: android . media . MediaDataSource ;
81
+
77
82
}
78
83
79
84
export interface AudioRecorderAndroidOptions {
Original file line number Diff line number Diff line change @@ -219,7 +219,11 @@ export class TNSPlayer extends Observable {
219
219
player . reset ( ) ;
220
220
if ( options . audioFile ) {
221
221
const audioPath = resolveAudioFilePath ( options . audioFile ) ;
222
- player . setDataSource ( audioPath ) ;
222
+ if ( audioPath . startsWith ( 'content://' ) ) {
223
+ player . setDataSource ( Utils . android . getApplicationContext ( ) , android . net . Uri . parse ( audioPath ) ) ;
224
+ } else {
225
+ player . setDataSource ( audioPath ) ;
226
+ }
223
227
224
228
// check if local file or remote - local then `prepare` is okay https://developer.android.com/reference/android/media/MediaPlayer.html#prepare()
225
229
if ( Utils . isFileOrResourcePath ( audioPath ) ) {
@@ -249,6 +253,9 @@ export class TNSPlayer extends Observable {
249
253
new android . media . MediaPlayer . OnPreparedListener ( {
250
254
onPrepared : ( mp ) => {
251
255
try {
256
+ if ( options . seek ) {
257
+ this . seekTo ( options . seek ) ;
258
+ }
252
259
if ( options . autoPlay ) {
253
260
this . play ( ) ;
254
261
}
@@ -344,8 +351,7 @@ export class TNSPlayer extends Observable {
344
351
345
352
public async seekTo ( time : number ) {
346
353
if ( this . _player ) {
347
- time = time * 1000 ;
348
- this . _player . seekTo ( time ) ;
354
+ this . _player . seekTo ( time * 1000 ) ;
349
355
this . notify ( { eventName : AudioPlayerEvents . seek } ) ;
350
356
}
351
357
}
Original file line number Diff line number Diff line change @@ -123,6 +123,9 @@ export class TNSPlayer extends Observable {
123
123
this . _player . numberOfLoops = - 1 ;
124
124
}
125
125
126
+ if ( options . seek ) {
127
+ this . seekTo ( options . seek ) ;
128
+ }
126
129
if ( options . autoPlay !== false ) {
127
130
this . _player . play ( ) ;
128
131
}
You can’t perform that action at this time.
0 commit comments