File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
22 "name" : " @monogatari/core" ,
3- "version" : " 2.5.1 " ,
3+ "version" : " 2.6.0 " ,
44 "main" : " lib/monogatari.node.js" ,
55 "module" : " lib/monogatari.module.js" ,
66 "css" : " dist/engine/core/monogatari.css" ,
Original file line number Diff line number Diff line change @@ -270,22 +270,19 @@ export class Play extends Action {
270270 this . media = media ;
271271 }
272272
273- let player = this . engine . mediaPlayer ( this . type , this . mediaKey ) ;
274- if ( typeof player === 'undefined' ) {
275- // We'll create the player in the apply method since it's async
276- this . player = null ;
277- } else {
278- this . player = player ;
279- }
273+ const player = this . engine . mediaPlayer ( this . type , this . mediaKey ) ;
274+
275+ // We'll create the player in the apply method since it's async
276+ this . player = typeof player === 'undefined' ? null : player ;
280277 } else {
281278 this . player = this . engine . mediaPlayers ( this . type ) ;
282279 }
283280 }
284281
285- async createAudioPlayer ( ) {
282+ async createAudioPlayer ( ) {
286283 const audioContext = this . engine . audioContext ;
287284 const gainNode = audioContext . createGain ( ) ;
288- gainNode . connect ( audioContext . destination ) ;
285+ gainNode . connect ( audioContext . destination ) ;
289286 gainNode . gain . setValueAtTime ( this . mediaVolume , audioContext . currentTime ) ;
290287
291288 // Load audio file
Original file line number Diff line number Diff line change @@ -21,18 +21,18 @@ class AudioPlayer {
2121 this . source = null ;
2222 }
2323
24- _createSource ( startAt = 0 ) {
25- const source = this . audioContext . createBufferSource ( ) ;
24+ _createSource ( ) {
25+ const source = this . audioContext . createBufferSource ( ) ;
2626
2727 source . buffer = this . buffer ;
28- source . connect ( this . gainNode ) ;
28+ source . connect ( this . gainNode ) ;
2929 source . loop = this . loop ;
3030
3131 source . onended = ( ) => {
3232 this . isPlaying = false ;
3333 this . hasEnded = true ;
3434 if ( typeof this . onended === 'function' ) {
35- this . onended ( ) ;
35+ this . onended ( ) ;
3636 }
3737 } ;
3838
@@ -55,12 +55,11 @@ class AudioPlayer {
5555 try {
5656 let startAt = 0 ;
5757
58- if ( this . isPaused ) {
58+ if ( this . isPaused && ! this . hasEnded ) {
5959 startAt = this . pausedAt ;
6060 }
6161
62- // Always create a new source node
63- this . source = this . _createSource ( startAt ) ;
62+ this . source = this . _createSource ( ) ;
6463 this . startedAt = this . audioContext . currentTime - startAt ;
6564
6665 this . isPlaying = true ;
@@ -69,21 +68,21 @@ class AudioPlayer {
6968
7069 this . source . start ( 0 , startAt ) ;
7170
72- resolve ( ) ;
71+ resolve ( ) ;
7372 } catch ( error ) {
74- reject ( error ) ;
73+ reject ( error ) ;
7574 }
7675 } ) ;
7776 }
7877
79- pause ( ) {
78+ pause ( ) {
8079 if ( ! this . isPlaying || this . hasEnded ) {
8180 return ;
8281 }
8382
8483 if ( this . source ) {
8584 this . source . onended = null ;
86- this . source . stop ( ) ;
85+ this . source . stop ( ) ;
8786 this . source = null ;
8887 }
8988
@@ -92,7 +91,7 @@ class AudioPlayer {
9291 this . isPaused = true ;
9392 }
9493
95- stop ( ) {
94+ stop ( ) {
9695 if ( this . isPlaying && this . source ) {
9796 this . source . onended = null ;
9897 this . source . stop ( ) ;
You can’t perform that action at this time.
0 commit comments