Skip to content

Commit 0f33452

Browse files
committed
Provide fallback for FCBH
* webm (ogg opus) files are not supported on iPhone. * check if damId ends with -opus16 (which indicates using webm files), and fallback to using mp3 which is damId with -opus16 removed.
1 parent 1760835 commit 0f33452

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Diff for: src/lib/data/audio.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,17 @@ export function updatePlaybackSpeed(playbackSpeed) {
332332
currentAudioPlayer.audio.playbackRate = parseFloat(playbackSpeed);
333333
}
334334
}
335-
335+
function getDamId(audioSource: any) {
336+
let damId = audioSource.damId;
337+
if (damId.endsWith('-opus16')) {
338+
// Check to see if the browser can handle webm files.
339+
const audio = new Audio();
340+
if (!audio.canPlayType('audio/webm')) {
341+
damId = damId.replace(/-opus16$/, '');
342+
}
343+
}
344+
return damId;
345+
}
336346
export async function getAudioSourceInfo(item: {
337347
collection: string;
338348
book: string;
@@ -355,7 +365,8 @@ export async function getAudioSourceInfo(item: {
355365
// if (source.accessMethods.includes('download')) {
356366
// // TODO: Figure out how to use Cache API to download audio to PWA
357367
// }
358-
const request = `${dbp4}/api/bibles/filesets/${audioSource.damId}/${item.book}/${item.chapter}?v=4&key=${audioSource.key}`;
368+
const damId = getDamId(audioSource);
369+
const request = `${dbp4}/api/bibles/filesets/${damId}/${item.book}/${item.chapter}?v=4&key=${audioSource.key}`;
359370
const response = await fetch(request, {
360371
method: 'GET',
361372
headers: {

0 commit comments

Comments
 (0)