@@ -234,20 +234,35 @@ <h2>🎉</h2>
234
234
235
235
< script >
236
236
$ ( document ) . ready ( function ( ) {
237
- goto_relative_page ( 0 ) ;
238
- initialize_player ( ) ;
237
+ show_player ( ) ;
238
+ goto_relative_page ( 0 , true ) ;
239
239
} ) ;
240
240
241
- // If book_audio_file is not null, stream the file.
242
- let initialize_player = function ( ) {
241
+ /**
242
+ * If book_audio_file is not null, set up the player.
243
+ *
244
+ * Don't actually load the source -- for some reason,
245
+ * the ajax page load was causing the audio src to
246
+ * only load occasionally! Not sure why. Source loading
247
+ * is handled in load_player_source().
248
+ */
249
+ let show_player = function ( ) {
243
250
const have_file = ( $ ( '#book_audio_file' ) . val ( ) != '' ) ;
244
- if ( ! have_file ) {
245
- return ;
251
+ if ( have_file ) {
252
+ $ ( 'div.audio-player-container' ) . show ( ) ;
246
253
}
254
+ }
247
255
248
- $ ( 'div.audio-player-container' ) . show ( ) ;
249
- t = parseFloat ( $ ( '#book_audio_current_pos' ) . val ( ) ) ;
256
+ /**
257
+ * Actually set the player source, loading the file,
258
+ * and load all bookmarks etc.
259
+ */
260
+ let load_player_source = function ( ) {
250
261
const book_id = $ ( '#book_id' ) . val ( ) ;
262
+ // console.log('setting source to ' + `/useraudio/stream/${book_id}`);
263
+ player . src = `/useraudio/stream/${ book_id } ` ;
264
+
265
+ t = parseFloat ( $ ( '#book_audio_current_pos' ) . val ( ) ) ;
251
266
player . currentTime = t ;
252
267
timeline . value = t ;
253
268
@@ -260,7 +275,6 @@ <h2>🎉</h2>
260
275
bookmarksArray . push ( b ) ;
261
276
}
262
277
263
- player . src = `/useraudio/stream/${ book_id } ` ;
264
278
start_player_post_loop ( ) ;
265
279
} ;
266
280
@@ -320,8 +334,16 @@ <h2>🎉</h2>
320
334
} ;
321
335
322
336
323
- // Go to page relative to that stored in page_num input.
324
- function goto_relative_page ( p ) {
337
+ /**
338
+ * Go to page relative to that stored in page_num input.
339
+ *
340
+ * On first load of page, load_source_file is set to true.
341
+ * It appears that for Firefox the player source can't be set
342
+ * while the page content is being ajax'd in. This makes
343
+ * _NO SENSE AT ALL_ but moving the player source loading
344
+ * to the ajax "success" function worked. ???
345
+ */
346
+ function goto_relative_page ( p , load_source_file = false ) {
325
347
const bookid = $ ( '#book_id' ) . val ( ) ;
326
348
const pagenum = parseInt ( $ ( '#page_num' ) . val ( ) ) ;
327
349
const maxpage = parseInt ( $ ( '#page_count' ) . val ( ) ) ;
@@ -344,6 +366,12 @@ <h2>🎉</h2>
344
366
set_page_fraction ( ) ;
345
367
set_footer_control_visibility ( ) ;
346
368
show_hide_title ( relpage ) ;
369
+
370
+ // Magic hack for player source to load consistently
371
+ // in Firefox.
372
+ if ( load_source_file ) {
373
+ load_player_source ( ) ;
374
+ }
347
375
}
348
376
) ;
349
377
}
0 commit comments